Clean special price when special price equal to price

class Mage_Shell_CleanSpcialPrice extends Mage_Shell_Abstract
{


    /**
     * Run script
     *
     */
    public function run()
    {
    	
    	$collection = Mage::getModel('catalog/product')->getCollection()
    	//->addAttributeToFilter('type_id', 'configurable')
    	->addAttributeToSelect(array('name', 'price', 'special_price'), 'left')
    	->addAttributeToFilter('status',1);
    	foreach ($collection as $_product) {
    		var_dump('sp_price:' . $_product->getData('special_price'));
    		var_dump('org_price:' . $_product->getData('price'));
    		if ($_product->getData('special_price') ==  $_product->getData('price')) {
    			$_product->setSpecialPrice('')
					        ->setSpecialToDate('')
					        ->setSpecialFromDate('')
					        ->save();
    			var_dump('clean ' . $_product->getSku() . ' special price');
    		} else {
    			var_dump('no need to clean.'.$_product->getSku().' special price');
    		}
    		
    	}
    	
    	//do priec index
    	var_dump('do price index');
    	$process = Mage::getModel('index/process')->load(2);
    	$process->reindexAll();
    	$process = Mage::getModel('index/process')->load(4);
    	$process->reindexAll();
    	var_dump('finished!');
    }
}

$shell = new Mage_Shell_CleanSpcialPrice();
$shell->run();

 

你可能感兴趣的:(when)