Monday 3 October 2011

Import/Export in Magento


The import/export tool is very useful within Magento. Basically you can use the import/export tool to do mass imports of products. It makes it much easier if you would like to add 50 products all at once, you would just create a csv or xml file with the matching fields for the database, add your information and then use the import tool to import the products. You can retrieve a sample csv or xml file, but doing an export.

Doing an export is very easy, and allows you to export all of your products out of your website. You might want to do this, if you are moving your website or need to reinstall or upgrade your website, and need to get the products out.

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.

Import/Export Concept
The logical steps are:
  • Load records from database
  • Convert internal identificators into human understandable text
  • Map database fields to our custom file headings (sku ⇒ Part Number)
  • Format data array as Excel XML
  • Save resulting text as local or remote file
This sequence of actions we call a Profile.
Here we have 4 categories of components:
  • Adapter (input/output)
  • Mapper (data value processing)
  • Parser (data format conversion)
  • Validator (data validation)
Adapters
Adapters are anything that can plug in to external resource. This may include:
  • Local files
  • FTP, SFTP servers
  • Database table
  • Soap services
  • Standard input/output
  • HTTP interface
  • HTML source
  • Google Spreadsheets
  • Custom resources (specialized db interface, cache repository, etc.)
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:
  • CSV text ⇒ Grid array
  • Excel XML text ⇒ Grid array
  • Grid array ⇒ Product model collection
Parsers can have 2 methods:
  • parse – usually convert from more human readable data to machine friendly format
  • unparse – the opposite, into human readable format
You 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

1 comment: