Magento's Imagine eCommerce Conference 2011 - Import Export in a Flash with the New Magento Module!
1. Using the new Import Module
How to use Magentos new ImportExport module in your custom modules
Imagine Conference, Feb. 2011 | Author: Vinai Kopp <vinai@netzarbeiter.com>
6. The Entity Type Model
Mage_ImportExport_Model_Import_Entity_Product
Mage_ImportExport_Model_Import_Entity_Customer
Purpose: Build and execute SQL for imports, updates and deletes
8. Import Data Resource Model
Mage_ImportExport_Model_Mysql4_Import_Data
Purpose: Interface to the import data table
9. Product Type Import Models
Mage_ImportExport_Model_Import_Entity_Product_Type_*
Purpose: Build and execute product type specific SQL
10. The Import Process
Temporary Table
POINT OF ENTRY
Adminhtml IMPORT MODEL: ENTITY TYPE ADAPTER
Interface validateSource()
Magento
CLI
CronJob
DATA ARRAY
SOURCE ADAPTER
Document
11. The Import Process
POINT OF ENTRY
Adminhtml
Interface
Magento
CLI
CronJob
Temporary Table
IMPORT MODEL: ENTITY TYPE ADAPTER
importSource()
CATALOG
SQL TABLE
PRODUCT TYPE
IMPORT MODEL
12. How can I use that?
Import, Update or Delete Products and/or Customers
13. How can I use that?
Example: Cronjob catalog updates via custom CSV files
Custom CSV Fields:
sku, name, description, short_description, store_id, websites, weight, price, qty, color
16. Specify a Custom Source Adapter
The Source Adapter Class is specified by the File Extension
Mage_ImportExport_Model_Import_Adapter_ . $type;
sourcefile.csv.custom to use Source Adapter
Mage/ImportExport/Model/Import/Adapter/Custom.php
17. The Source Adapter Interface
Extend Mage_ImportExport_Model_Import_Adapter_Abstract
Implements SeekableIterator Interface
Create rewind(), next() and seek() methods using _init() to setup data
18. The Source Adapter Interface
protected function _init()
Read source and build the same data structure like the core csv
adapter
The source array format can best be referenced by exporting some
products and looking at the first line in the resulting export file
21. Product Import Source Array
Configurable Products
One row for every associated simple product in
addition to record for the simple product itself
_super_products_sku
... 0,1,0.0000,1,1,,1,0,1,1,0.0000,1,0,,,,,,,,,,,,,,sku-Pear-Cyan,manufacturer,Pear,100.0000
... ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,sku-Pear-Indigo,color,Cyan,5.0000
... ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,sku-Pear-Mauve,,,
... ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,sku-Pear-Pink,,,
... ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,sku-Peach-Cyan,,,
22. Product Import Source Array
Configurable Products
One row for every associated simple product attribute
_super_attribute_code
... 0,1,0.0000,1,1,,1,0,1,1,0.0000,1,0,,,,,,,,,,,,,,sku-Pear-Cyan,manufacturer,Pear,100.0000
... ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,sku-Pear-Indigo,color,Cyan,5.0000
... ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,sku-Pear-Mauve,,,
... ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,sku-Pear-Pink,,,
... ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,sku-Peach-Cyan,,,
23. Product Import Source Array
Configurable Products
One row for every attribute with a price update
_super_products_price_corr
... 0,1,0.0000,1,1,,1,0,1,1,0.0000,1,0,,,,,,,,,,,,,,sku-Pear-Cyan,manufacturer,Pear,100.0000
... ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,sku-Pear-Indigo,color,Cyan,5.0000
... ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,sku-Pear-Mauve,,,
... ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,sku-Pear-Pink,,,
... ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,sku-Peach-Cyan,,,
_super_attribute_option
24. Product Import Source Array
Configurable Products
_super_products_sku and _super_attribute_option
do not (have to) correspond
... 0,1,0.0000,1,1,,1,0,1,1,0.0000,1,0,,,,,,,,,,,,,,sku-Pear-Cyan,manufacturer,Pear,100.0000
... ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,sku-Pear-Indigo,color,Cyan,5.0000
... ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,sku-Pear-Mauve,,,
... ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,sku-Pear-Pink,,,
... ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,sku-Peach-Cyan,,,
26. Implementation of the Source
Adapter
Implement SeekableIterator Interface
seek(), current(), next(), rewind(), key(), valid()
All except next(), rewind() and seek() are implemented in the abstract
class Mage_ImportExport_Model_Import_Adapter_Abstract
The core CSV Adapter is a good implementation reference
27. Trigger Import
Cron Observer which wrapps the Import Model calls to
validateSource(), importSource() and invalidateIndex()
28. Trigger Import
Cron Observer which wrapps the Import Model calls to
validateSource(), importSource() and invalidateIndex()
29. Other possibilities
Anything that gets product data into Magento in bulk operations, e.g.
XML Files
REST Request with product data in payload
Unix domain sockets
30. Conclusion
Mage_ImportExport fills an important gap!
Usable with technical knowledge because of the complex array
format
Couple of smallish bugs, but it's going places :]
32. /me is happy to hear from you
vinai@netzarbeiter.com :: @VinaiKopp
Thank you @riconeitzel for all the time and for making this look good!
Thanks to Magento!