Skip to content

Instantly share code, notes, and snippets.

@ceckoslab
Last active December 25, 2015 16:09
Show Gist options
  • Save ceckoslab/7004061 to your computer and use it in GitHub Desktop.
Save ceckoslab/7004061 to your computer and use it in GitHub Desktop.
Simple Magento script, that deletes all non admin store associated prices ... basically we will keep only the default prices values and will delete all website associated price values.
<?php
/**
* @author MagePsycho <info@magepsycho.com>
* @author ceckoslab <ceckoslab@gmail.com>
* @website http://www.magepsycho.com
* @website http://ceckoslab.com
*/
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
Mage::app('admin');
Mage::register('isSecureArea', 1);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
set_time_limit(0);
ini_set('memory_limit','1024M');
/***************** UTILITY FUNCTIONS ********************/
function _getConnection($type = 'core_read') {
return Mage::getSingleton('core/resource')->getConnection($type);
}
function _getTableName($tableName) {
return Mage::getSingleton('core/resource')->getTableName($tableName);
}
function _getAttributeId($attribute_code = 'price') {
$connection = _getConnection('core_read');
$sql = "SELECT attribute_id
FROM " . _getTableName('eav_attribute') . "
WHERE
entity_type_id = ?
AND attribute_code = ?";
$entity_type_id = _getEntityTypeId();
return $connection->fetchOne($sql, array($entity_type_id, $attribute_code));
}
function _getEntityTypeId($entity_type_code = 'catalog_product') {
$connection = _getConnection('core_read');
$sql = "SELECT entity_type_id FROM " . _getTableName('eav_entity_type') . " WHERE entity_type_code = ?";
return $connection->fetchOne($sql, array($entity_type_code));
}
function _deleteNonAdminPrices() {
$connection = _getConnection('core_write');
$attributeId = _getAttributeId();
$entityTypeId = _getEntityTypeId();
$sql = "DELETE FROM " . _getTableName('catalog_product_entity_decimal') . "
WHERE attribute_id = ?
AND entity_type_id = ?
AND store_id != ?";
$connection->query($sql, array($attributeId, $entityTypeId, Mage_Core_Model_App::ADMIN_STORE_ID));
}
/***************** UTILITY FUNCTIONS ********************/
$message = '';
try {
_deleteNonAdminPrices();
$message = 'Success:: All Non Admin Prices Deleted';
} catch(Exception $e) {
$message = 'Error:: While Deleting Non Admin Prices: ' . $e->getMessage();
}
echo $message;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment