Created
September 13, 2013 11:44
-
-
Save ceckoslab/6549634 to your computer and use it in GitHub Desktop.
Deleting all grouped DUMMY prices ... thanks to MagePsycho and his article: Updating product prices in Magento in an easier & faster way - http://www.blog.magepsycho.com/updating-product-prices-in-magento-in-easier-faster-way/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @author MagePsycho <info@magepsycho.com> | |
* @website http://www.magepsycho.com | |
* @category Export / Import | |
*/ | |
$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 _getIdFromSku($sku){ | |
$connection = _getConnection('core_read'); | |
$sql = "SELECT entity_id FROM " . _getTableName('catalog_product_entity') . " WHERE sku = ?"; | |
return $connection->fetchOne($sql, array($sku)); | |
} | |
function _checkIfSkuExists($sku){ | |
$connection = _getConnection('core_read'); | |
$sql = "SELECT COUNT(*) AS count_no FROM " . _getTableName('catalog_product_entity') . " WHERE sku = ?"; | |
$count = $connection->fetchOne($sql, array($sku)); | |
if($count > 0){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
function _deletePrices($data){ | |
$connection = _getConnection('core_write'); | |
$sku = $data[0]; | |
$productId = _getIdFromSku($sku); | |
$attributeId = _getAttributeId(); | |
$sql = "DELETE FROM " . _getTableName('catalog_product_entity_decimal') . " | |
WHERE attribute_id = ? | |
AND entity_id = ?"; | |
$connection->query($sql, array($attributeId, $productId)); | |
} | |
/***************** UTILITY FUNCTIONS ********************/ | |
$collectionGrouped = Mage::getResourceModel('catalog/product_collection') | |
->addAttributeToFilter('type_id', array('eq' => 'grouped')); | |
$data = array(); | |
foreach($collectionGrouped as $product) { | |
$data[] = array( 0 => $product->getSku()); | |
} | |
$message = ''; | |
$count = 1; | |
foreach($data as $_data){ | |
if(_checkIfSkuExists($_data[0])){ | |
try{ | |
_deletePrices($_data); | |
$message .= $count . '> Success:: While Deleting Price of Sku (' . $_data[0] . '). <br />'; | |
}catch(Exception $e){ | |
$message .= $count .'> Error:: While Deleting Price of Sku (' . $_data[0] . ') => '.$e->getMessage().'<br />'; | |
} | |
}else{ | |
$message .= $count .'> Error:: Product with Sku (' . $_data[0] . ') does\'t exist.<br />'; | |
} | |
$count++; | |
} | |
echo $message; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment