Can this be added to an observer like in my code in: How to set products in stock after import ?
I currently have a module I created that will check the sites prices.
It is currently just a page inside the admin that will show all the products that have special prices in a table.
The code itself is simple.
Check if the special price is equal to the product price or if it is equal to 0.
If it is change it to a blank.
<?php
$_productCollection = Mage::getModel('catalog/product')->getCollection(); /* get the collection */
$_productCollection->addAttributeToSelect('*'); /* select all attributes */
$_productCollection->addAttributeToFilter('special_price', ['notnull' => true]); /* check if special_price is not null or empty */
$_productCollection->addAttributeToSort('special_price', 'asc'); /* sort the special price */
$_productCollection->getSelect(); /* get selection from database */
Mage::getModel('review/review')->appendSummary($_productCollection); /* i have no idea what this does */
$_helper = $this->helper('catalog/output');
foreach ($_productCollection as $_product):
$price = $_product->getPrice(); /* value of price */
$specialprice = $_product->getSpecialPrice(); /* value of special price */
$tprice = trim($price);
$tspecialprice = trim($specialprice);
/* check if special price equal to price and set empty */
if($tprice==$tspecialprice) {
$_product->setSpecialPrice("");
$_product->getResource()->saveAttribute($_product, 'special_price');
}
/* check if special price equal to zero and set empty */
if($tspecialprice==0) {
$_product->setSpecialPrice("");
$_product->getResource()->saveAttribute($_product, 'special_price');
}
endforeach;
?>
Can this be optimized?