1

我正在使用 Google 的 Content Shopping API,这段代码一切顺利。

但是当我尝试通过以下方法从 Merchant Center 中删除产品时,该产品已成功从列表中删除,但仍返回“未找到项目”错误。

这是代码:

public function deleteProduct($offerId) {
    $productId = $this->buildProductId($offerId);
    // The response for a successful delete is empty
    $this->service->products->delete($this->merchantId, $productId);
}

这是它返回的错误。

Google_Service_Exception
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "item not found"
}
],
"code": 404,
"message": "item not found"
}
}
4

1 回答 1

0

好吧,我想在我的项目中处理两个场景。

1) 如果产品在 Google Merchant Center 上存在,则请求删除它,否则不存在。

2) 如果该产品已在 Google Merchant Center 上发布,则不要尝试再次上传。

内容购物 API 没有这样的东西来检查产品是否已经存在。他们直接抛出异常。

方案 1 的答案:

实际上我使用的是在 GridView 中使用 Pjax 的 Yii2 框架。当我单击一个按钮时,它首先调用 Pjax,然后重定向到 URL。因此它试图再次删除相同的产品。因此例外。

方案 2 的答案:

您可以再次将同一产品上传到 Google Merchant Center。如果产品已经存在,那么它将更新该 productId(itemId 或 offerId)的所有值。我不认为它对我有好处。因此,我将上传产品的状态保存在我的数据库中。如果同样的产品来了,我只是设置了“上传”的标志,而不是真正上传产品。

于 2017-03-31T12:59:32.353 回答