In the Quickstart you'll find detailed information about M2IF - Simple Console Tool installation and usage. To give you a better impression, what is possible with M2IF, we've a running example that is based on a Magento 2 Sample Data installation. Follow these steps to delete, replace and add/update products + categories in a Magento 2 installation with the Sample Data provided by Magento.
Download and Install Magento 2 with Sample Data
You'll find the Magento 2 sources with Sample Data on the Magento website. Optionally it should be possible to add the Sample Data on the CLI, but actually, especially when you run the Community Edition, there seems to be some issues which breaks the installation process. The best way will be to download the complete package directly from the Magento website.
Assuming, that you'll have a running system, follow the instrutions from the Magento instructions to install your Magento 2 instance with Sample Data.
When you've a running Magento 2 instance with Sample Data, you additionally need to download the sample CSV import files from the repository techdivision/import-cli-simple. Clone this repository with
git clone https://github.com/techdivision/import-cli-simple.git
to the root directory of your Magento 2 installation. Finally you need the Magento 2 Sample Data (especially the images), that can also be cloned from Github. Assuming you're in the root folder of your Magento 2 installation, you can clone the repository with
$ git clone https://github.com/magento/magento2-sample-data.git projects/sample-data/magento2-sample-data import-cli-simle/projects/sample-data/magento2-sample-data
from the command line.
The import files as well as the Sample Data files for your Magento 2 version should now be available under the
M2IF is able to handle bunches. In general this is a functionality that will only make sense in a multithreaded or multiprocessed environment where the bunches can be imported in parallel. In this case, it should only give the developer an idea, on how a multiprocessed functionality can be implemented.
A bunch is a CSV file which is only a part of a complete import. It doesn't matter, what a kind of data a bunch contains, as the importer handles the data in the necessary order. This means, that the first step is to import all simple products found in a bunch. After that, information like the created entity IDs related with the imported SKUs, which is necessary to import all other product data (Bunches, Configurables, Images, Related etc.) will be shared, so it'll be possible to import these data step-by-step, but each step also in parallel.
To split a import into multiple bunches, the bunched files MUST follow these pattern:
- The prefix has to equal, e. g.
- The prefix has to be followed by an underscore
- A random number of alphanumeric charaters has to follow
- These characters has also to be followed by an underscore
- Finally, each bunch MUST have a sequential number, followed by
For example, the following files will be imported as a bunch:
When starting the import process by invoking the apropriate command, these files will be imported like one file. It is NOT necessary to invoke the importer four times.
Running the Import
The command doesn't implement any directory clean-up or archiving functionality, what means that the files have to be copied to the source directory specified in the configuration file. The command to re-import the sample data including the images (assuming you've Magento 2.1.x, would look like this:
sudo rm -rf import-cli-simple/projects/sample-data/tmp \ && sudo mkdir import-cli-simple/projects/sample-data/tmp \ && sudo cp import-cli-simple/projects/sample-data/ce/2.1.x/data/replace/*.csv import-cli-simple/projects/sample-data/tmp \ && sudo bin/import-cli-simple.phar import:products --source-dir=import-cli-simple/projects/sample-data/tmp
To make sure, that all old import files will be removed, we'll delete and re-create the directory that contains the import files
The import process only starts, when an OK flagfile is available in the same directory where the CSV files are located. The naming convention for the OK flagfile MUST follow one of these naming conventions
which results in one of
The flagfile MUST contain the name of the CSV files that have to be imported within the next iterations. If the flagfile would be named
import-cli-simple/projects/sample-data/tmp/magento-import_20170203-1234.ok for example and contains the following lines
magento-import_20170203-1234_01.csv magento-import_20170203-1234_02.csv magento-import_20170203-1234_03.csv magento-import_20170203-1234_04.csv
the importer has to be invoked four times (because the example above is NO bunch), whereas on each invovation, the next file will be imported and removed from the flagfile.
Have a look in subdirectories of
import-cli-simple/projects/sample-data/* for a working example.