Is Importing a csv file through a shell script a good idea? Why yes and why not? What are the principal issues?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.Sign up to join this community
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.
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 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.
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
I'm assuming you're talking about Magento shell scripts. You can achieve exactly the same functions with Magento shell scripts as you would with a proper extension if you just want to import CSV data. You use the same Magento methods.
I only see a few advantages of using Magento shell script including but not limited to:
You can schedule it with the system cron, allowing you to avoid interrupting Magento cron jobs if the CSV import take a long time.
No need to configure an extension.
The only time I use a shell script is when I'm migrating data (products, orders, etc.), or when there's a cron job that I know is intensive and takes up a lot of time, like bulk product creation/update, stock update, order syncing, etc.
With these kind of integrations, I usually create an extension that has all of the business logic and create shell scripts as entry points to the extension's processes. That way I can package my program properly and have it accessible by the system to be run independent of the Magento cron jobs.