Skip to content

Latest commit

 

History

History
52 lines (36 loc) · 2 KB

customize-import-behavior.rst

File metadata and controls

52 lines (36 loc) · 2 KB

Customizing the Import Behavior

Importations in the PIM are largely automatized by using the Doctrine metadata, through a set of guessers and property transformers. Import behavior is customizable for all entities by adding new prioritized guessers and transformers.

Creating a Guesser

Guessers are used at the beginning of each importation to link each property of the imported data to a property transformer.

For example, to skip all columns starting by a #, the following guesser could be created :

../../src/Acme/Bundle/DemoConnectorBundle/Transformer/Guesser/CommentGuesser.php

The way the guesser works is simple :

  • If the column's title does not start by a #, null is returned.
  • If the column starts by a # an array containing the transformer service and its options is returned

The guesser must be included in the following way in the DIC :

../../src/Acme/Bundle/DemoConnectorBundle/Resources/config/guessers.yml

As you can see, the transformer returned by the guesser will be the pim_import_export.transformer.property.skip transformer.

Creating a Transformer

In the following example, we create a transformer which prepends a string to a scalar value :

../../src/Acme/Bundle/DemoConnectorBundle/Transformer/Property/PrependTransformer.php

This transformer prepends a string comming to the value, to make it work, you should therefore add a custom guesser which returns the value to be prepended in the options.

To add the transformer to the DIC, proceed in the following way:

../../src/Acme/Bundle/DemoConnectorBundle/Resources/config/transformers.yml