Speed up Magento Product Import

Hi Guys, Hope you are doing well. It has been a long time, things have been really busy for us from past few months. But now it is getting bit smoother, so we thought we should talk about Magento again ????

And today’s topic is Magento product import and it’s performance because this has helped us recently so we thought we must share this with the community.

The process that takes most time after product save is indexer, sometime it takes 1-2 minutes to save a single product so if you have 400 products then it can take up to 3-4 hours to import the product data. And if you have huge catalogue then you can do the maths ????

Here is the code which allows you to save your product(s) in milliseconds instead of taking minutes to save a single product.

 /* set all indexers to manual*/ $indexers = Mage::getSingleton('index/indexer')->getProcessesCollection();
foreach ($indexers as $indexer) { $indexer->setMode(Mage_Index_Model_Process::MODE_MANUAL)->save();
} $sku="SKU1234"; $product = Mage::getModel("catalog/product")->loadByAttribute("sku",$sku); if ($product){ try{ $product->setData("name",$name) ->setData("short_desc",$shortDesc) ->save(); } catch (Exception $e){ Mage::log($e->getMessage()); }
} /* set all indexers to automatic*/
$indexers = Mage::getSingleton('index/indexer')->getProcessesCollection();
foreach ($indexers as $indexer) { $indexer->setMode(Mage_Index_Model_Process::MODE_REAL_TIME)->save();

If required then you can run all or particular index(es) after all the products are saved, depending upon the data you have saved.

List of possible indexes in Magento are as follows -:

  1. Product Attributes
  2. Product Prices
  3. Catalog URL Rewrites
  4. Product Flat Data
  5. Category Flat Data
  6. Category Products
  7. Catalog Search index
  8. Tag Aggregation Data
  9. Stock Status

so to run particular index(es), you can use the following code -:

$process = Mage::getModel('index/process')->load($id);

Where $id is a list index from the above list.

and to run all indexes at the same time, you can use the following code -:

$process = Mage::getModel('index/process')->reindexAll();

Hope this article helped you in some way. Please leave us your comment and let us know what do you think? Thanks.

Similar Posts