Showing results for 
Search instead for 
Did you mean: 

Import many products programatically

Import many products programatically



I need to import many products from another database. I get all product data through REST API in json format and I need to insert them to Magento. Problem is when i try to use the built in methods:


$product = Mage::getModel('catalog/product');
}catch(Exception $e){


Then on each product it takes about 1.5 sec to save(). Well that's kinda problem if importing over 1000 products.



When I tryied to find methods that's taking that much of time, I found that cache is taking majority of time. Though I disabled all available caches on admin panel.


So I'd like to know if theres a way to turn off ALL caching during some code execution, later when all products imported, turn back on and reindex the data. And that programmatically, not from admin panel.


Or is there better way to import products, like direct insert to DB, though would like my code be usable on later magento updates too, for example if theres gonna be a database change.


Tnx in advance.



Re: Import many products programatically

1.5 seconds is a long time but there are a lot of things going on when you save a product. Observers fire, indexing of the product is done, databases are committed. One thing you can do though is turn the indexers to Manual and then after you have imported turn them back to Auto and reindex.


There are things out there that go direct to database but these come with issues, noteable around actions that need to happen when models are saved etc. If you have extensions that function based on certain observers firing for example then you are going to run in to problems as these will not fire.

Problem solved? Click Accept as Solution! | Magento Small Business Partner

Re: Import many products programatically

Before importing, you can set all the indices in the admin to be "Manual Update". This should make your import that much faster since indexing won't happen on each product save. You can also set the mode through code for each index and setting it to Mage_Index_Model_Process::MODE_MANUAL.


Edit: Don't forget to reindex after import and re-enabling the indices.