Search code examples
phpgoogle-apigoogle-api-php-clientgoogle-shopping-apigoogle-content-api

Remove Sale Price from Google Content API for Shopping using PHP


I'm able to update (change with another price) the product sale price in my Google Merchant Feed via Google Content API for Shopping usign PHP language.

Example. A product with 40% discount (Original Price = 100.00 EUR, Sale Price = 60.00 EUR):

$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);

I'm not able to remove this discount, I want my product Final Price 100.00 EUR again. I tried with:

$product->setSalePrice(NULL);

but I got a fatal error:

Argument 1 passed to Google_Service_ShoppingContent_Product::setSalePrice() must be an instance of Google_Service_ShoppingContent_Price

I also tried setting the value to 0

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

but Google disapprove my offer.

How can I do this?

Thanks in advance


Solution

  • Just set the sale price effective date in the past, like this:

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

    Haven't tried it, but hopefully should work.