How to import fixtures for your custom entity and attribute¶
Implement ReferableInterface¶
To ensure your entity is imported correctly, the first step is to implement the following interfaces.
Your entity should implement thePim\Bundle\CatalogBundle\Model\ReferableInterface
interface
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # /src/Acme/Bundle/IcecatDemoBundle/Entity/Vendor.php
<?php
namespace Acme\Bundle\IcecatDemoBundle\Entity;
use Pim\Bundle\CatalogBundle\Model\ReferableInterface;
/**
* @UniqueEntity(fields="code", message="This code is already taken")
*/
class Vendor implements ReferableInterface
{
public function getReference()
{
return $this->code;
}
}
|
Your entity repository should implement the Pim\Bundle\CatalogBundle\Entity\Repository\ReferableEntityRepositoryInterface
interface,
or be a subclass of Pim\Bundle\CatalogBundle\Entity\Repository\ReferableEntityRepository
1 2 3 | # /src/Acme/Bundle/IcecatDemoBundle/Resources/config/doctrine/Vendor.orm.yml
Acme\Bundle\IcecatDemoBundle\Entity\Vendor:
repositoryClass: Pim\Bundle\CatalogBundle\Entity\Repository\ReferableEntityRepository
|
Attribute value importation¶
If your entity implements the Pim\Bundle\CatalogBundle\Model\ReferableInterface
interface and is linked
to ProductValue
with a direct association of any cardinality, importation of product values requires
no configuration or coding on your side. Simply provide the reference to the linked entities in your import files,
and the importation will be done automatically.
If you have indirect associations, or if you cannot implement the interfaces in your entity and your repository, you will have to create a specific property transformer for your attribute type. (see Customizing the Import Behavior for more explanations)
To use of your property transformer, you will have to configure a guesser service similar to the one used by price collection attributes :
1 2 3 4 5 6 7 8 9 10 11 | # /vendor/akeneo/pim-community-dev/src/Pim/Bundle/ImportExportBundle/Resources/config/guessers.yml
services:
pim_import_export.transformer.guesser.prices:
class: "%pim_import_export.transformer.guesser.attribute.class%"
public: false
arguments:
- "@pim_import_export.transformer.property.prices"
- "%pim_catalog.entity.product_value.class%"
- prices
tags:
- { name: pim_import_export.transformer.guesser, priority: 40 }
|
Create a processor¶
If your entity and its associations implement the Pim\Bundle\CatalogBundle\Model\ReferableInterface
interface, creating the processor is done by simply configuring a new service in your DIC :
1 2 3 4 5 6 | # /src/Acme/Bundle/IcecatDemoBundle/Resources/config/processors.yml
services:
pim_import_export.processor.vendor:
parent: pim_base_connector.processor.transformer
arguments:
- "%pim_catalog.entity.vendor.class%"
|
Configure fixtures¶
The order and the processor for your fixtures is given in the fixtures.yml
configuration file:
1 2 3 4 | # /src/Acme/Bundle/IcecatDemoBundle/Resources/config/fixtures.yml
vendors:
csv:
processor: pim_import_export.processor.vendor
|
You can now add a vendors.csv
or a vendors.yml
file in your fixtures folder, it will be
loaded with other fixtures. (see How to Define my own Data Set with the Installer)
Create a connector¶
The processor created in the first step can be used to create a full import/export connector. Please read How to Create a New Connector for more details.