Skip to content

Instantly share code, notes, and snippets.

@peterjaap
Last active November 25, 2015 06:40
Show Gist options
  • Save peterjaap/39ed258b134b2be9ee6d to your computer and use it in GitHub Desktop.
Save peterjaap/39ed258b134b2be9ee6d to your computer and use it in GitHub Desktop.
This small script looks for products with a higher special price than normal price and removes the special price if the $emptySpecialPrice flag is set to true. Be sure to reindex the prices after running this.
<?php
chdir(dirname(__FILE__));
require_once '../app/Mage.php';
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
umask(0);
$resource = Mage::getModel('core/resource');
$db = $resource->getConnection('core_write');
$specialPriceAttributeId = $db->fetchOne($db->select()->from('eav_attribute')->where('attribute_code = ?', 'special_price')->where('entity_type_id = ?', 4));
$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect(array('name','price'))->addFieldToFilter('special_price', array('neq'=>''));
$emptySpecialPrice = false;
echo "Name\tSKU\tPrice\tSpecialPrice\n";
foreach($products as $product) {
if($product->getPrice() <= $product->getSpecialPrice()) {
echo $product->getName() . "\t" . $product->getSku() . "\t" . $product->getPrice() . "\t" . $product->getSpecialPrice() . "\n";
if($emptySpecialPrice) {
$db->delete('catalog_product_entity_decimal', 'attribute_id = ' . $specialPriceAttributeId . ' AND entity_id = ' . $product->getId());
echo 'Special price for ' . $product->getSku() . ' has been deleted.' . PHP_EOL;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment