using the new import module
TRANSCRIPT
![Page 1: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/1.jpg)
Imagine Conference, Feb. 2011 | Author: Vinai Kopp <[email protected]>
Using the new Import ModuleHow to use Magentos new ImportExport module in your custom modules
![Page 2: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/2.jpg)
It's me!Vinai Kopp
Magento Development since March 08
Magento Developer Training
Magento Consulting
![Page 3: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/3.jpg)
Introducing the Players
Overview of the the classes used during the import process
![Page 4: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/4.jpg)
The Controller
Mage_ImportExport_Adminhtml_ImportController
Purpose: Entry Point
Instantiates the Import Model and start Process
![Page 5: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/5.jpg)
The Import Model
Mage_ImportExport_Model_Import
Purpose: Facade to the underlying import classes
![Page 6: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/6.jpg)
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
![Page 7: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/7.jpg)
The Source Adapter
Mage_ImportExport_Model_Import_Adapter_Csv
Purpose: Parse and access input data into arrays as expected by the
entity type model
![Page 8: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/8.jpg)
Import Data Resource Model
Mage_ImportExport_Model_Mysql4_Import_Data
Purpose: Interface to the import data table
![Page 9: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/9.jpg)
Product Type Import Models
Mage_ImportExport_Model_Import_Entity_Product_Type_*
Purpose: Build and execute product type specific SQL
![Page 10: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/10.jpg)
The Import Process
POINT OF ENTRY
MagentoCronJobCLI
AdminhtmlInterface
IMPORT MODEL:validateSource()
SOURCE ADAPTER
ENTITY TYPE ADAPTER
Document
DATA ARRAY
Temporary Table
![Page 11: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/11.jpg)
The Import Process
POINT OF ENTRY
MagentoCronJobCLI
AdminhtmlInterface
ENTITY TYPE ADAPTER
Temporary Table
IMPORT MODEL:importSource()
SQL
PRODUCT TYPEIMPORT MODEL
CATALOGTABLE
![Page 12: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/12.jpg)
How can I use that?
Import, Update or Delete Products and/or Customers
![Page 13: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/13.jpg)
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
![Page 14: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/14.jpg)
Why a custom CSV file format?
sku
_store
_attribute_set
_type
_category
_product_websites
color
cost
created_at
custom_design
custom_design_from
custom_design_to
custom_layout_update
description
enable_googlecheckout
gallery
gift_message_available
has_options
image
image_label
is_imported
manufacturer
media_gallery
meta_description
meta_keyword
meta_title
minimal_price
name
news_from_dat
news_to_date
options_container
page_layout
price
required_options
short_description
small_image
small_image_label
special_from_date
special_price
special_to_date
status
tax_class_id
thumbnail
thumbnail_label
updated_at
url_key
url_path
visibility
weight
qty
min_qty
use_config_min_qty
is_qty_decimal
backorders
use_config_backorders
min_sale_qty
use_config_min_sale_qty
max_sale_qty
use_config_max_sale_qty
is_in_stock
notify_stock_qty
use_config_notify_stock_qty
manage_stock
use_config_manage_stock
use_config_qty_increments
qty_increments
use_config_enable_qty_increments
enable_qty_increments
_links_related_sku
_links_related_position
_links_crosssell_sku
_links_crosssell_position
_links_upsell_sku
_links_upsell_position
_associated_sku
_associated_default_qty
_associated_position
_tier_price_website
_tier_price_customer_group
_tier_price_qty
_tier_price_price
_super_products_sku
_super_attribute_code
_super_attribute_option
_super_attribute_price_corr
![Page 15: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/15.jpg)
Cronjob Catalog Updates
Step One: Build Source Adapter for custom CSV file
Step Two: Create Cron Observer
![Page 16: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/16.jpg)
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
![Page 17: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/17.jpg)
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
![Page 18: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/18.jpg)
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
![Page 19: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/19.jpg)
The Source Array Format
sku
_store
_attribute_set
_type
_category
_product_websites
color
cost
created_at
custom_design
custom_design_from
custom_design_to
custom_layout_update
description
enable_googlecheckout
gallery
gift_message_available
has_options
image
image_label
is_imported
manufacturer
media_gallery
meta_description
meta_keyword
meta_title
minimal_price
name
news_from_dat
news_to_date
options_container
page_layout
price
required_options
short_description
small_image
small_image_label
special_from_date
special_price
special_to_date
status
tax_class_id
thumbnail
thumbnail_label
updated_at
url_key
url_path
visibility
weight
qty
min_qty
use_config_min_qty
is_qty_decimal
backorders
use_config_backorders
min_sale_qty
use_config_min_sale_qty
max_sale_qty
use_config_max_sale_qty
is_in_stock
notify_stock_qty
use_config_notify_stock_qty
manage_stock
use_config_manage_stock
use_config_qty_increments
qty_increments
use_config_enable_qty_increments
enable_qty_increments
_links_related_sku
_links_related_position
_links_crosssell_sku
_links_crosssell_position
_links_upsell_sku
_links_upsell_position
_associated_sku
_associated_default_qty
_associated_position
_tier_price_website
_tier_price_customer_group
_tier_price_qty
_tier_price_price
_super_products_sku
_super_attribute_code
_super_attribute_option
_super_attribute_price_corr
![Page 20: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/20.jpg)
Product Import Source Array
Configurable Products
... 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_products_sku_super_attribute_code_super_attribute_option_super_attribute_price_corr
![Page 21: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/21.jpg)
Product Import Source Array
... 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_products_sku
One row for every associated simple product in addition to record for the simple product itself
Configurable Products
![Page 22: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/22.jpg)
Product Import Source Array
... 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_code
One row for every associated simple product attribute
Configurable Products
![Page 23: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/23.jpg)
Product Import Source Array
... 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
One row for every attribute with a price update
_super_products_price_corr
Configurable Products
![Page 24: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/24.jpg)
Product Import Source Array
... 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_products_sku and _super_attribute_option do not (have to) correspond
Configurable Products
![Page 25: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/25.jpg)
Product Import Source Array
Custom Options_custom_option_store_custom_option_type_custom_option_title_custom_option_is_required_custom_option_price_custom_option_sku_custom_option_max_characters_custom_option_sort_order_custom_option_row_title_custom_option_row_price_custom_option_row_sku_custom_option_row_sort
![Page 26: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/26.jpg)
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
![Page 27: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/27.jpg)
Trigger Import
Cron Observer which wrapps the Import Model calls to
validateSource(), importSource() and invalidateIndex()
![Page 28: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/28.jpg)
Trigger Import
Cron Observer which wrapps the Import Model calls to
validateSource(), importSource() and invalidateIndex()
![Page 29: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/29.jpg)
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
![Page 30: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/30.jpg)
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 :]
![Page 31: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/31.jpg)
Links
Sample Code: http://bit.ly/haCGWI
PDF of the Slides: http://bit.ly/i0eiI7
uRapidFlow: http://www.unirgy.com/products/urapidflow/
![Page 32: Using the new Import Module](https://reader034.vdocuments.site/reader034/viewer/2022052515/58a1ab2c1a28aba5438ba020/html5/thumbnails/32.jpg)
/me is happy to hear from you
[email protected] :: @VinaiKopp
Thank you @riconeitzel for all the time and for making this look good!
Thanks to Magento!