使用PHP从Google Content API for Shopping中删除销售价格

问题描述

我可以通过Google Content API for Shopping使用PHP语言在Google Merchant Feed中更新(更改其他价格)产品的销售价格。

示例。折扣40%的产品(原价= 100.00欧元,促销价= 60.00欧元):

$product = new Google_Service_ShoppingContent_Product();
$product->setOfferId($myProductId);
$product->setContentLanguage($idData[1]);
$product->setTargetCountry($idData[2]);
$product->setChannel($idData[0]);

$price = new Google_Service_ShoppingContent_Price();
$price->setValue(100.00);
$price->setCurrency('EUR');

$product->setPrice($price);

$salePrice = new Google_Service_ShoppingContent_Price();
$salePrice->setValue(60.00);
$salePrice->setCurrency('EUR');

$product->setSalePrice($salePrice);

我无法删除此折扣,我希望我的产品最终价格再次100.00欧元。我尝试过:

$product->setSalePrice(NULL);

但是我遇到了致命错误:

参数1传递给 Google_Service_ShoppingContent_Product :: setSalePrice()必须为 Google_Service_ShoppingContent_Price的实例

我还尝试将值设置为0

$salePrice = new Google_Service_ShoppingContent_Price();
$salePrice->setValue(0.00);
$salePrice->setCurrency('EUR');

但是Google拒绝了我的提议。

我该怎么做?

预先感谢

解决方法

只需设置过去的销售价格生效日期即可,

$saleStartDate = date(DateTime::ISO8601,strtotime('-5 days'));
$saleEndDate = date(DateTime::ISO8601,strtotime('-1 day'));
$product->setSalePriceEffectiveDate($saleStartDate . '/' . $saleEndDate);

还没有尝试过,但是希望可以工作。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...