I am using Google's Content Shopping API, Everything is going good with this code.
But when I am trying to delete the product from Merchant Center by following method, the product deleted from list successfully but still returning "item not found" error.
This is the code :
public function deleteProduct($offerId) {
$productId = $this->buildProductId($offerId);
// The response for a successful delete is empty
$this->service->products->delete($this->merchantId, $productId);
}
And this is the error it returning.
Google_Service_Exception
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "item not found"
}
],
"code": 404,
"message": "item not found"
}
}
Well, I want to handle two scenarios in my project.
1) If the product is live on Google Merchant Center then request to delete it, otherwise not.
2) If the product is already live on the Google Merchant Center then do not try to upload it again.
Content Shopping API having no such thing to check the product is already present or not. They directly throw the Exception.
Answer for scenario 1 :
Actually I am using Yii2 framework which uses Pjax in GridView. When I am clicking a button, it first call Pjax and then redirect to the URL. Hence it is trying to delete same product again. And hence the Exception.
Answer for scenario 2 :
You can upload the same product again to the Google Merchant Center. If the product is already there then it will update all values for that productId(itemId or offerId). I don't think its good for me. Hence I am keeping the status of uploaded products in my database. And if same product came, I just setting the flag of 'uploaded' and not really uploading the product.