Created
December 2, 2015 01:02
-
-
Save molotovbliss/5ec3dab283f0d78bf97d to your computer and use it in GitHub Desktop.
Use Iterator to mass update products for performance optimization
This file contains hidden or 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
// Get Collection | |
$collection = Mage::getModel('catalog/product')->getCollection() | |
->addAttributeToSelect('sku') | |
->addAttributeToSelect('publihser') | |
->addFieldToFilter(array(array('attribute'=>'publisher','eq'=>$publisher))); | |
function productUpdateCallback($args){ | |
$product = Mage::getModel('catalog/product'); | |
$product->setData($args['row']); | |
$productId = $product->getId(); | |
$sku = 'yourSku'; | |
// Updates a single attribute, much faster than calling a full product save | |
Mage::getSingleton('catalog/product_action') | |
->updateAttributes(array($productId), array('sku' => $sku), 0); | |
} | |
// Walk through collection, for large collections this is much faster than using foreach | |
Mage::getSingleton('core/resource_iterator')->walk($collection->getSelect(), array('productUpdateCallback')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment