Update Magento Special Price [closed]
This question was caused by a typo or a pro开发者_运维知识库blem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this questionI'm trying to revert "special price" after the "special price to date" passed to null. So basically when I update my product's special price programmatically using this code :
$todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
$collection = Mage::getModel('catalog/product')->getCollection()
->addStoreFilter()
->addAttributeToFilter('special_price', array('gt' => 0))
->addAttributeToFilter('special_to_date', array('date' => true, 'to' => $todayDate));
echo "Total products found : ".count($collection);
foreach ($collection as $product)
{
$product->setSpecialPrice(null)
->setSpecialFromDate(null)
->setSpecialToDate(null)
->save();
}
echo "<br/> Done!";
But after I update my special price to null the magento product wizard does not let me set a new special price for my product. When I save the form it does not give me any error nor affect any changes in special price and it's still null! What's wrong?!
To solve this, pick what suits for you more. you can either set the "ToDate" in the past like:
->setSpecialToDate(date("m-d-Y", strtotime('-25 year')));
just beware that if you want to set it back, you will have to set the "ToDate" in the future like:
->setSpecialToDate(date("m-d-Y", strtotime('25 year')));
or instead of 'null', just insert an empty string ''. like so:
$product->setSpecialPrice('')
->setSpecialToDate('')
->setSpecialFromDate('')
->save()
hope this helps someone out
精彩评论