1. Presentation title here
Integrate your data into
OroCRM
CSV Import and Export
Sergey Zhuravel
https://github.com/sergeyz
https://twitter.com/sergey_zv
2. Presentation title here
Outline
1. Import and export - process overview
a. Jobs overview
b. Import schema
c. Export schema
2. Basic B2B Customer import and export
a. Fields configuration
b. Data converter
c. Import/export Strategy
d. Strategy events
e. Import and validation processors
f. Button configuraion reference
g. Export processor
h. Export template processor
3. Import and export customization
a. Data Converter with tags support
b. Tags Normalizer
c. Strategy with tags support
6. 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
7. 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
8. 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
9. Presentation title here
Fields configuration
order – manages column order
/**
* @ConfigField(
* defaultValues={
* "importexport"={
* "order"=10
* }
* }
* )
*/
protected $name;
Import and Export
10. 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
11. 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
13. 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
14. 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
15. 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
16. 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
17. 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
18. Presentation title here
Export template processor
Use registered fixture to export an example file.
parameters:
orocrm_sales.importexport.template_fixture.b2bcustomer.class:
OroCRMBundleSalesBundleImportExportTemplateFixtureB2bCustomerFixture
services:
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
19. 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
20. Presentation title here
Custom Data Converter
use OroBundleImportExportBundleConverterAbstractTableDataConverter;
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
21. 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
22. Presentation title here
Custom Normalizer
use OroBundleImportExportBundleSerializerNormalizerDenormalizerInterface;
use OroBundleImportExportBundleSerializerNormalizerNormalizerInterface;
use OroCRMBundleSalesBundleEntityB2bCustomer;
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 === 'OroCRMBundleSalesBundleEntityB2bCustomer';
}
/**
* {@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
23. Presentation title here
Custom Strategy
use OroBundleImportExportBundleStrategyStrategyInterface
use OroCRMBundleSalesBundleEntityB2bCustomer;
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
24. Presentation title here
Strategy Events
namespace OroBundleImportExportBundleEvent;
use SymfonyComponentEventDispatcherEvent;
class StrategyEvent extends Event
{
const PROCESS_BEFORE = 'oro_importexport.strategy.process_before';
const PROCESS_AFTER = 'oro_importexport.strategy.process_after';
Import and Export
25. 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/i
ndex.md
Sources
● https://github.com/sergeyz/crm-b2bcustomer-import
Information
Import and Export