Finally, you have your new Magento 2 store set up and it is time to fill it up with products. Let’s take a look at how to do it with ease.
Just for the sake of mentioning it, of course you can manually create products in Magento admin area. If you have only a couple of them, feel free to do it, but otherwise, read on!
Magento 2 CSV import
In case you have a lot of products to import you can use standard Magento 2 CSV import that will do the heavy lifting for you. M2 lets you download a sample CSV file so you know all the columns and aspects of the data structure.
There are just two obvious hiccups:
- You may be limited by your provider with the size of the CSV file, therefore bigger CSV files must be split into smaller files
- You may be limited by your provider with the time to perform the import
Cron job product import to the rescue!
Having a cron job doing the import for you in the background while you are sipping coffee is really rewarding. If you are writing integration with ERP or any data source you can again take multiple approaches on the matter at hand.
Since Magento 2 is a much more OOP based framework than Magento 1, one possibility is to use factories, interfaces, and repositories to create the product, set all of its attributes and save it into the database. From OOP point of view, this is the way to go, but performance-wise it is just not fast enough.
Our idea was to mimic the CSV import so it would be easy and understandable to fill the product properties and save it into the database. We have used Firegento’s free module Fast Simple Import together with custom logic.
Now it is just a matter of creating a PHP array for a product with all of its attributes including product images similar to CSV import. This way we are able to import thousands of products in a matter of minutes.
Our custom logic mentioned above is just a helper to work with a module used for ERP integration. This module handles fetching of products and creating the PHP arrays. With this, it would be really interesting to create an ultimate ERP product fetching module where the only thing changing is the data transformer layer. But that’s a blog post for another rainy day.
What are your ideas for fast and simple product import?