schnell importieren mit dem neuen importexport modul

33
Meet-Magento, Mai 2011 | Autor: Vinai Kopp <[email protected]> Schnell Importieren mit dem neuen ImportExport Modul Nutzen und anpassen des ImportExport Moduls in eigenen Erweiterungen

Upload: nguyendien

Post on 13-Feb-2017

228 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Schnell Importieren mit dem neuen ImportExport Modul

Meet-Magento, Mai 2011 | Autor: Vinai Kopp <[email protected]>

Schnell Importieren mit dem neuen ImportExport ModulNutzen und anpassen des ImportExport Moduls in eigenen Erweiterungen

Page 2: Schnell Importieren mit dem neuen ImportExport Modul

Vinai

Magento Entwickler seit März 08

Offizieller Vertrags-Trainer für Magento Inc.

Magento Berater

Page 3: Schnell Importieren mit dem neuen ImportExport Modul

Vorstellung der Mitspieler

Zuerst eine Übersicht über die am Import beteiligten Klassen

Page 4: Schnell Importieren mit dem neuen ImportExport Modul

Der Controller

Mage_ImportExport_Adminhtml_ImportController

Zweck: Einstiegspunkt

Der Controller instanziiert das Import Model und führt durch den

Import Prozess

Page 5: Schnell Importieren mit dem neuen ImportExport Modul

Das Import Model

Mage_ImportExport_Model_Import

Zweck: Fassade für die dahinter liegenden Klassen

Page 6: Schnell Importieren mit dem neuen ImportExport Modul

Die Entity Type Models

Mage_ImportExport_Model_Import_Entity_Product

Mage_ImportExport_Model_Import_Entity_Customer

Zweck: Aufbauen und Ausführen der SQL-Befehle für die Import,

Update und Delete Prozesse

Page 7: Schnell Importieren mit dem neuen ImportExport Modul

Der Source Adapter

Mage_ImportExport_Model_Import_Adapter_Csv

Zweck: Parsen der Eingabedaten in das Array welches von den Entity

Type Models erwartet wird.

Page 8: Schnell Importieren mit dem neuen ImportExport Modul

Import Data Resource Model

Mage_ImportExport_Model_Mysql4_Import_Data

Zweck: Interface zu der Import Daten Table

Page 9: Schnell Importieren mit dem neuen ImportExport Modul

Product Type Import Models

Mage_ImportExport_Model_Import_Entity_Product_Type_*

Zweck: Aufbauen und ausführen der Produkt-Typ spezifischen SQL-

Befehle

Page 10: Schnell Importieren mit dem neuen ImportExport Modul

Der Import Prozess

POINT OF ENTRY

MagentoCronJobCLI

AdminhtmlInterface

IMPORT MODEL:validateSource()

SOURCE ADAPTER

ENTITY TYPE ADAPTER

Document

DATA ARRAY

Temporary Table

Page 11: Schnell Importieren mit dem neuen ImportExport Modul

Der Import Prozess

POINT OF ENTRY

MagentoCronJobCLI

AdminhtmlInterface

ENTITY TYPE ADAPTER

Temporary Table

IMPORT MODEL:importSource()

SQL

PRODUCT TYPEIMPORT MODEL

CATALOGTABLE

Page 12: Schnell Importieren mit dem neuen ImportExport Modul

Was kann ich damit anfangen?

Import, Update oder Löschen von Produkten und/oder Kunden

Page 13: Schnell Importieren mit dem neuen ImportExport Modul

Wie kann ich damit etwas anfangen?

Beispiel: Cronjob catalog updates via eigenen CSV Dateien

Felder der eigenen CSV Eingabedaten:

sku, name, description, short_description, store_id, websites, weight, price, qty, color

Page 14: Schnell Importieren mit dem neuen ImportExport Modul

Warum ein eigenes CSV 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: Schnell Importieren mit dem neuen ImportExport Modul

Cronjob Catalog Updates

Schritt Eins: Bauen des Source Adapters für das eigene CSV Format

Schritt Zwei: Erstellen des Cron Observers

Page 16: Schnell Importieren mit dem neuen ImportExport Modul

Verwenden des eigenen Adapters

Die Source Adapter Klasse wird durch die Dateiendung spezifiziert

Mage_ImportExport_Model_Import_Adapter_ . $type;

sourcefile.csv.custom wird gelesen vom Source Adapter

Mage/ImportExport/Model/Import/Adapter/Custom.php

Page 17: Schnell Importieren mit dem neuen ImportExport Modul

Das Source Adapter Interface

Vererbt Mage_ImportExport_Model_Import_Adapter_Abstract

Implementiert das SeekableIterator Interface

Aufgaben:

Erstellen der rewind(), next() und seek() Methoden.

Benutzen von _init() um die Daten vorzubereiten.

Page 18: Schnell Importieren mit dem neuen ImportExport Modul

Das Source Adapter Interface

protected function _init()

Einlesen der Eingabe-Daten

Aufbauen einer Datenstruktur wie von der core CSV Adapter Klasse

Das Source Array Format? Siehe Export Datei...

Page 19: Schnell Importieren mit dem neuen ImportExport Modul

Das 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: Schnell Importieren mit dem neuen ImportExport Modul

Product Import Source Array

Configurable Products

_super_products_sku _super_attribute_code _super_attribute_option _super_attribute_price_corr

import-Apple-Cyan manufacturer Apple 100.000

import-Apple-Green color Pink 10.000

import-Apple-Pink color Cyan 5.000

import-Samsung-Cyan

import-Samsung-Green

import-Samsung-Pink

Page 21: Schnell Importieren mit dem neuen ImportExport Modul

Product Import Source Array

Configurable Products

_super_products_sku _super_attribute_code _super_attribute_option _super_attribute_price_corr

import-Apple-Cyan manufacturer Apple 100.000

import-Apple-Green color Pink 10.000

import-Apple-Pink color Cyan 5.000

import-Samsung-Cyan

import-Samsung-Green

import-Samsung-Pink

Für jedes zugeordnete Simple Product eine Zeile(zusätzlich zu der Zeile für das eigentliche Simple Product Entität)

Page 22: Schnell Importieren mit dem neuen ImportExport Modul

Product Import Source Array

Configurable Products

_super_products_sku _super_attribute_code _super_attribute_option _super_attribute_price_corr

import-Apple-Cyan manufacturer Apple 100.000

import-Apple-Green color Pink 10.000

import-Apple-Pink color Cyan 5.000

import-Samsung-Cyan

import-Samsung-Green

import-Samsung-Pink

Preiskorrekturen: _code, _option und _price_corr

Page 23: Schnell Importieren mit dem neuen ImportExport Modul

Product Import Source Array

Configurable Products

_super_products_sku _super_attribute_code _super_attribute_option _super_attribute_price_corr

import-Apple-Cyan manufacturer Apple 100.000

import-Apple-Green color Pink 10.000

import-Apple-Pink color Cyan 5.000

import-Samsung-Cyan

import-Samsung-Green

import-Samsung-Pink

Preiskorrekturen: _code, _option und _price_corr

Page 24: Schnell Importieren mit dem neuen ImportExport Modul

Product Import Source Array

Configurable Products

_super_products_sku _super_attribute_code _super_attribute_option _super_attribute_price_corr

import-Apple-Cyan manufacturer Apple 100.000

import-Apple-Green color Pink 10.000

import-Apple-Pink color Cyan 5.000

import-Samsung-Cyan

import-Samsung-Green

import-Samsung-Pink

_super_products_sku und _super_attribute_option müssen nicht übereinstimmen

Page 25: Schnell Importieren mit dem neuen ImportExport Modul

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: Schnell Importieren mit dem neuen ImportExport Modul

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 27: Schnell Importieren mit dem neuen ImportExport Modul

Die Implementation desSource Adapters

Implementieren des SeekableIterator Interface

seek(), current(), next(), rewind(), key(), valid()

Alle ausser next(), rewind() und seek() sind implementiert in

Mage_ImportExport_Model_Import_Adapter_Abstract

Die core CSV Adapter Klasse ist eine gute Referenz

Page 28: Schnell Importieren mit dem neuen ImportExport Modul

Anstossen des Imports

Ein Cron Observer ruft validateSource(), importSource() und

invalidateIndex() auf

Page 29: Schnell Importieren mit dem neuen ImportExport Modul

Anstossen des Imports

Ein Cron Observer ruft validateSource(), importSource() und

invalidateIndex() auf

Page 30: Schnell Importieren mit dem neuen ImportExport Modul

Möglichkeiten

Alle Import-Vorgänge von vielen Entitäten aus verschiedenen Medien

XML Dateien

REST Anfragen mit Produkt-Daten im payload

Unix domain sockets

Adapter für weitere Entitäten (Order, Category, EAV-Attribute, ...)

Page 31: Schnell Importieren mit dem neuen ImportExport Modul

Fazit

Mage_ImportExport füllt eine wichtige Lücke

Fordert (noch?) solide PHP / Magento Kenntnisse

Es fehlen noch wichtige Entity Adapter

Produkt-Gallery

Anlegen von Attribut-Optionen

Anlegen von Kategorien

Page 33: Schnell Importieren mit dem neuen ImportExport Modul

/me is happy to hear from you!

eMail: [email protected] :: Twitter: @VinaiKopp

Danke an @RicoNeitzel für das aufhübschen der Folien!

Thanks Magento!