Upload
orocrm
View
202
Download
2
Tags:
Embed Size (px)
Citation preview
Presentation title here
Integrate your data into OroCRM
CSV Import and Export
Sergey Zhuravelhttps://github.com/sergeyz
https://twitter.com/sergey_zv
Presentation title here
Outline1. Import and export - process overview
a. Jobs overviewb. Import schemac. Export schema
2. Basic B2B Customer import and exporta. Fields configurationb. Data converterc. Import/export Strategy d. Strategy eventse. Import and validation processorsf. Button configuraion reference
g. Export processorh. Export template processor
3. Import and export customizationa. Data Converter with tags supportb. Tags Normalizerc. Strategy with tags support
Presentation title here
Jobs overview
Job
Step Step Step Step
Presentation title here
Import Process SchemaStep
Reader
Processor
Writer
DataConverter Serializer Strategy
Import and Export
Presentation title here
Export Process SchemaStep
Reader
Processor
Writer
DataConverterSerializer
Import and Export
Presentation title here
Basic B2B Customer import and export
• Configurable entity import and export process is managed by EntityConfigBundle. Field configuration is avalialable in “importexport” configuration scope.
• Minimum import/export configuration should 4 defined services (DataConverter, Strategy, Import/ImportValidation and Export Processors).
• In addition, it is possible to define processor to export file template for data import
Import and Export
Presentation title here
Fields configuration
header – csv column header configuration, default values is field label (if other are not
defined)
/*** @ConfigField(* defaultValues={* "importexport"={* "header"="B2BCustomer name"* }* }* )*/protected $name;
Import and Export
Presentation title here
Fields configuration
identity – field is used to search entity by import strategy
/*** @ConfigField(* defaultValues={* "importexport"={* "identity"=true* }* }* )*/protected $name;
Import and Export
Presentation title here
Fields configuration
order – manages column order
/*** @ConfigField(* defaultValues={* "importexport"={* "order"=10* }* }* )*/protected $name;
Import and Export
Presentation title here
Fields configuration
excluded – allows to exclude field from export and import process
/*** @ConfigField(* defaultValues={* "importexport"={* "excluded"=true* }* }* )*/protected $name;
Import and Export
Presentation title here
Fields configuration
full – used to manage related entities export and import.•true - export and import related entity fields •false – export and import related entity identity fields only
/*** @ConfigField(* defaultValues={* "importexport"={* "full"=true* }* }* )*/protected $name;
Import and Export
Presentation title here
Fields configuration
Import and Export
Presentation title here
Data Converter
• Data converter is responsible for headers mapping and converting imported data to nested representation of entity and its relations.
• Use customized or ConfigurableTableDataConverter
orocrm_sales.importexport.data_converter.b2bcustomer: parent: oro_importexport.data_converter.configurable
Import and Export git checkout tags/step-1
Presentation title here
Strategy
• Strategy responsible for processing import logic.
• Use customized or ConfigurableTableDataConverter
orocrm_sales.importexport.strategy.b2bcustomer.add_or_replace: parent: oro_importexport.strategy.configurable_add_or_replace
Import and Export git checkout tags/step-2
Presentation title here
orocrm_sales.importexport.processor.import.b2bcustomer: parent: oro_importexport.processor.import_abstract calls: - [setDataConverter, [@orocrm_sales.importexport.data_converter.b2bcustomer]] - [setStrategy, [@orocrm_sales.importexport.strategy.b2bcustomer.add_or_replace]] tags: - { name: oro_importexport.processor, type: import, entity: %orocrm_sales.b2bcustomer.entity.class%, alias: orocrm_sales_b2bcustomer } - { name: oro_importexport.processor, type: import_validation, entity: %orocrm_sales.b2bcustomer.entity.class%, alias: orocrm_sales_b2bcustomer }
Import and validation processors definition example
Import and Export
Presentation title here
Button configuration reference
{% include 'OroImportExportBundle:ImportExport:buttons.html.twig' with { entity_class: entity_class, exportProcessor: 'orocrm_sales_b2bcustomer', exportTemplateProcessor: 'orocrm_sales_b2bcustomer', importProcessor: 'orocrm_sales_b2bcustomer', dataGridName: gridName, importTitle: 'orocrm.sales.b2bcustomer.import'|trans} %}
return [ 'entity_class' => $this->container->getParameter('orocrm_sales.b2bcustomer.entity.class')];
Import and Export git checkout tags/step-4
Presentation title here
Export processor
Export processor denormalizes objects and converts plain data using
DataConverter
orocrm_sales.importexport.processor.export.b2bcustomer: parent: oro_importexport.processor.export_abstract calls: - [setDataConverter, [@orocrm_sales.importexport.data_converter.b2bcustomer]] tags: - { name: oro_importexport.processor, type: export, entity: %orocrm_sales.b2bcustomer.entity.class%, alias: orocrm_sales_b2bcustomer }
Import and Export git checkout tags/step-5
Presentation title here
Export template processorUse registered fixture to export an example file.
parameters: orocrm_sales.importexport.template_fixture.b2bcustomer.class: OroCRM\Bundle\SalesBundle\ImportExport\TemplateFixture\B2bCustomerFixtureservices: orocrm_sales.importexport.template_fixture.b2bcustomer: class: %orocrm_sales.importexport.template_fixture.b2bcustomer.class% tags: - { name: oro_importexport.template_fixture }
orocrm_sales.importexport.template_fixture.data_converter.b2bcustomer: parent: oro_importexport.data_converter.template_fixture.configurable
orocrm_sales.importexport.processor.export_template.b2bcustomer: parent: oro_importexport.processor.export_abstract calls: - [setDataConverter, [@orocrm_sales.importexport.template_fixture.data_converter.b2bcustomer]] tags: - { name: oro_importexport.processor, type: export_template, entity: %orocrm_sales.b2bcustomer.entity.class%, alias: orocrm_sales_b2bcustomer }
Import and Export git checkout tags/step-6
Presentation title here
Import and export customization
Import and Export
Three steps are required for adding tags to import and exprort:
1. Create DataConverter with tags to Tags List header conversion rule and two methods to convert tag names list
2. Add Normalizer to load tags by their names
3. Add Strategy to save taggins
Presentation title here
Custom Data Converteruse Oro\Bundle\ImportExportBundle\Converter\AbstractTableDataConverter;
class B2BCustomerDataConverter extends AbstractTableDataConverter{ /** * {@inheritdoc} */ protected function getHeaderConversionRules() { return [ 'ID' => 'id', 'Name' => 'name', 'Channel' => 'channel:name', ]; } /** * {@inheritdoc} */ protected function getBackendHeader() { return ['id', 'name', 'channel']; }}
Import and Export git checkout tags/step-7
Presentation title here
Normalizers• Import and export use extended Serializer Component.
• Serializer converts plain data to entities and back using normalizers.
• Oro Serialier and Normalizers have additional parameter “context” to make normalization process more flexible.
orocrm_sales.importexport.normalizer.b2bcustomer: parent: oro_importexport.serializer.configurable_entity_normalizer tags: - { name: oro_importexport.normalizer }
Import and Export git checkout tags/step-8
Presentation title here
Custom Normalizeruse Oro\Bundle\ImportExportBundle\Serializer\Normalizer\DenormalizerInterface;use Oro\Bundle\ImportExportBundle\Serializer\Normalizer\NormalizerInterface;use OroCRM\Bundle\SalesBundle\Entity\B2bCustomer;
class B2BCustomerNormalizer implements NormalizerInterface, DenormalizerInterface{ /** * {@inheritdoc} */ public function denormalize($data, $class, $format = null, array $context = []) { return new B2bCustomer(); }
/** * {@inheritdoc} */ public function supportsDenormalization($data, $type, $format = null, array $context = []) { return $type === 'OroCRM\Bundle\SalesBundle\Entity\B2bCustomer'; }
/** * {@inheritdoc} */ public function normalize($object, $format = null, array $context = []) { /** @var B2BCustomer $object */ return ['name' => $object->getName()]; }
/** * {@inheritdoc} */ public function supportsNormalization($data, $format = null, array $context = []) { return $data instanceof B2bCustomer; }}
Import and Export
Presentation title here
Custom Strategy
use Oro\Bundle\ImportExportBundle\Strategy\StrategyInterfaceuse OroCRM\Bundle\SalesBundle\Entity\B2bCustomer;
class B2BCustomerStrategy extends StrategyInterface{ /** * @param B2BCustomer $entity * * {@inheritdoc} */ public function process($entity) { if (!$entity->getDataChannel()) { return null; }
return $entity; }}
Import and Export git checkout tags/step-9
Presentation title here
Strategy Events
namespace Oro\Bundle\ImportExportBundle\Event;
use Symfony\Component\EventDispatcher\Event;
class StrategyEvent extends Event{ const PROCESS_BEFORE = 'oro_importexport.strategy.process_before'; const PROCESS_AFTER = 'oro_importexport.strategy.process_after';
Import and Export
Presentation title here
Batch Job and services customization● https://github.com/akeneo/BatchBundle● http://docs.spring.io/spring-batch/reference/html/domain.html● https://github.com/orocrm/OroCRMMailChimpBundle/tree/master/ImportExport/Step
Batch job events● https://github.com/akeneo/BatchBundle/blob/master/Event/EventInterface.php
Documentation● https://github.com/orocrm/documentation/blob/master/book/importexport.rst● https://github.
com/orocrm/documentation/blob/master/cookbook/how_to_accelerate_import.rst● https://github.
com/orocrm/platform/blob/master/src/Oro/Bundle/ImportExportBundle/Resources/doc/index.md
Sources● https://github.com/sergeyz/crm-b2bcustomer-import
Information
Import and Export
Presentation title here
Q/A
Import and Export