Skip to content

Instantly share code, notes, and snippets.

@pronto2000
Last active June 12, 2016 14:02
Show Gist options
  • Save pronto2000/0e81e310b01646ee71f4dacfe466f59b to your computer and use it in GitHub Desktop.
Save pronto2000/0e81e310b01646ee71f4dacfe466f59b to your computer and use it in GitHub Desktop.
Magento: Snippet to update all products (put it into the shell folder)
<?php
require_once 'abstract.php';
class Mage_Shell_Products extends Mage_Shell_Abstract
{
private function execution_time($start, $current)
{
return date("H:i:s", $current - $start);
}
public function run()
{
echo "Product updater\n";
$progress = array('-', '\\', '|', '/');
$execution_start = microtime(true);
$products = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('type_id', Mage_Catalog_Model_Product_Type::TYPE_SIMPLE); // Simple products only
$i = 0;
foreach($products as $product) {
// Change weight of all simple products to 0.1 (replace it with your own code)
$product->setWeight(0.1);
$product->save();
echo $progress[$i%4] . ' ' . ($i+1) . ' products updated (' . $this->execution_time($execution_start, microtime(true)) . ")\r";
$i++;
}
echo "\n";
}
}
$shell = new Mage_Shell_Products();
$shell->run();
// Contants:
// Mage_Catalog_Model_Product_Type::TYPE_SIMPLE
// Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE
// Mage_Catalog_Model_Product_Type::TYPE_GROUPED
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment