Introduction |
This long anticipated feature is arguably one of the most important ones in ecommerce world. Flexibility of this interface defines capability of the application to communicate with the outside world, be it legacy systems, 3rd party applications, price aggregators, external order sources, fulfillment systems, accounting, etc.
Thus we took it very seriously and, as with everything else in Magento went one or more steps further than most systems. Effectively any import or export is a conversion. From one medium to another. From database to local file, from FTP server to database, from parsed HTML page to Excel spreadsheet, from Google Spreadsheet to catalog.
Basically, it boils down to loading data from one resource, applying unlimited alterations/reformatting, and saving it to another resource.
Welcome to the world of conversion.
Concept |
Let’s take an example of exporting a product catalog to excel spreadsheet file. The logical steps are:
This sequence of actions we call a Profile.
Here we have 4 categories of components:
Adapters |
Adapters are anything that can plug in to external resource. This may include:
Adapters can have 2 methods:
load - extract data from resource into internal container.save - save data into resource.Mappers |
Mappers are for processing data without changing it’s format or structure. They’re useful for tasks such as mapping one field to another or apply formulas on values.
Mappers can run one method: map
Parsers |
Parsers are for changing format of data. Examples:
Parsers can have 2 methods:
parse - usually convert from more human readable data to machine friendly formatunparse - the opposite, into human readable formatYou might notice that Parsers are separated from Adapters, when usually they are associated as one thing (export to CSV file).
Validators |
Validators are created to make sure that conditions are met. The conditions can be applied to processed data or environment variables.
Validators can only validate.
Implementation |
Let’s take an example of exporting catalog products into CSV file.