1

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?

4

1 回答 1

2

由于它似乎是一个格式问题,它正在颠倒日期和月份(其中 4/7 变为 7/4)如果您尝试重置日期会发生什么

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

请参阅在 Magento 中以编程方式设置特价

于 2013-07-08T22:09:27.737 回答