Reputation: 26016
I am using Magento version 1.4.0.1.
I have a product with the following "Special Price From Date" and "Special Price To Date" (present under 'Prices' tab in product edit page):
Special Price From Date = 4/7/13 (i.e. April 07, 2013)
Special Price To Date = 7/3/13 (i.e. July 03, 2013)
Then I run the following code to update the product:
Mage::getModel('catalog/product')
->load($productId)
->setName('Some new name for the product')
->save();
The problem is that the special price from date and to date is changed automatically. Now, the special price from and to date become like this:
Special Price From Date = 7/4/13 (i.e. July 04, 2013)
Special Price To Date = 3/7/13 (i.e. March 07, 2013)
Any help please?
Upvotes: 1
Views: 6869
Reputation: 17656
Since it seem to be a format issue, where it's reversing the day and month (where 4/7 become 7/4) what happen if you try to reset the date
$product = Mage::getModel('catalog/product')
->load($productId);
$product->setName('Some new name for the product')
->setSpecialFromDate($product->getSpecialFromDate()) // assuming that this = YYYY-MM-DD
->setSpecialFromDateIsFormated(true)
->setSpecialToDate($product->getSpecialTODate())
->setSpecialToDateIsFormated(true)
->save();
See Set Special Price Programatically In Magento
Upvotes: 2