Magento 1.9 – How to Import CSV File Through Shell Script

csvmagento-1.9shell

Is Importing a csv file through a shell script a good idea? Why yes and why not? What are the principal issues?

Thanks!

Best Answer

It depends how you approach it, I have on many occasions had no choice but to import CSV via a shell script - files coming from third party sources that cant be practical to split up.

Formats that are from non technical clients and not able to get them to put it into a format that the Magento Data importer works.

Writing a custom importer is relatively easy but you need to ensure you can handle error conditions in a sensible way. You also will need to ensure that all of the data attributes are pre-defined , or that you are able to create them on the during the import process.

Benefits

  • Import can work with any CSV (you would have to define the import script)
  • Fast Import can be achieved if bypassing Magento API and using SQL direct.
  • Can enable you to programatically generate your attributes/values on the fly.

Disadvantages

  • Requires Custom Logic
  • Risk of not importing all required information for proper operation of Magento (eg stock control)
  • No clear strategy for handling data - you need to define it properly.
  • By passing Magento API would require solid understanding of database structure.
  • Might break in future updates.
  • Updates from CSV might not be feasible - you might need to custom track between old and new ie if its a 3rd party and they delete the product how to identify that it should be deleted on next import.

There are some alternatives out there that I would reccomend you consider investigating before deciding that writing your own custom CSV importer is the correct strategy for your requirements. I have outlined two of the popular options below.

Magmi

Magmi is a mass importer for Magento, quite popular although it does have some bugs so it may not work for every senario. I've recently used it on a project and we had to disable some import functionality (to do with categories) because it broke price importing.

See More: http://sourceforge.net/projects/magmi/files/

API Import

It might not be using a CSV to do an import, but I think it might be worth considering. It was mentioned at a recent conference which I went to the author being a presenter. I think you will need to do a bit of pre import leg work to get it to the right setup but you can be fairly sure it will import correctly.

See More: https://github.com/danslo/ApiImport

Related Topic