Update Magento Special Price

Posted by Farid on Stack Overflow See other posts from Stack Overflow or by Farid
Published on 2011-01-08T09:49:29Z Indexed on 2011/01/08 9:53 UTC
Read the original article Hit count: 233

Filed under:

I'm trying to revert "special price" after the "special price to date" passed to null. So basically when I update my products 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?!

© Stack Overflow or respective owner

Related posts about magento-1.4