I have a magento installation that has a layered navigation to which attributes show and allow you to filter by.

I have an issue with the attributes showing on the filter, they wont show unless I go into each product and re-save them after I have imported the attribute data via CSV.

I have re-indexed the data and flushed all cache but still cant get them to show.

I need to find a way to force all products to re-save programatically.

Does anyone know of a script I can run via SSH to do this at all? I have tried a few I have found online, but they dont seem to execute correctly.

Any help would be greatly appreciated.

Thanks in advance,

  • have you tried reindex from console/terminal? $~ php shell/indexer.php -reindexall is command for that on unix systems with ability to run php scripts from terminal
    – pankijs
    Mar 28, 2015 at 1:00

3 Answers 3


Untested but something like this:

require 'app/Mage.php';


$collection = Mage::getModel('catalog/product')->getCollection();

foreach ($collection as $product) {
    echo 'saving product '.$product->getData('sku').PHP_EOL;
    echo 'saved'.PHP_EOL;
  • how many products do you have? Feb 16, 2015 at 11:22
  • 750 products. I have just managed to sort this though. I have updated products via the Admin panel. Batch updated attributes, changed all to Taxable Goods and updated. Now working, thanks for your help though, Andrew. Feb 16, 2015 at 11:51

This is what resource iterators are made for:

$productCollection = Mage::getModel('catalog/product')->getCollection();
Mage::getSingleton('core/resource_iterator')->walk($productCollection->getSelect(), array(array($this, 'productCallback')));

// callback method
public function productCallback($args)
    $product = Mage::getModel('catalog/product'); 
    $product->getResource()->saveAttribute($product, 'your_changed_attribute1');
    $product->getResource()->saveAttribute($product, 'your_changed_attribute2');

Note: Since you might only have an issue with some of your attributes, there's no need to do call the 'full' ->save() functions on your products and this is a quite heavy operation. Just select the attributes which you need to save as shown above.

Credits & links for you to look at:

Best Way To Iterate Through Product Collection

Is it possible to iterate over Magento collections with pagination natively?

  • I like this&ndash;it gives you the ORM for building your query and then a very high-speed way to process and update the data
    – STW
    Oct 22, 2015 at 4:42

You can use this :

require 'app/Mage.php';


$products = Mage::getModel('catalog/product')
for ($i = 0; $i < $products->getLastPageNumber(); $i++) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.