How to Manipulate Families¶
Prerequisites¶
The Akeneo PIM project introduces services to help you manage your catalog entities.
As stated above, the family factory and the attribute requirement factory are some of the services that you can get from the Symfony container:
// family factory
$this->container->get('pim_catalog.factory.family');
// family manager
$this->container->get('pim_catalog.manager.family');
// attribute requirement factory
$this->container->get('pim_catalog.factory.attribute_requirement');
In the following examples, we will use $ff
as the family factory service and $arf
as the attribute requirements factory.
Create a family¶
// create a family
$family = $ff->createFamily();
$family->setCode('shirt');
- Add some requirements to this family
Note
For this example, we will assume that we already have some attributes (to learn more about attribute creation, you can read the How to Manipulate Attributes cookbook) and some channels
// Set the attribute color required for the channel ecommerce
$family->addAttributeRequirement(
$arf->createAttributeRequirement(
$color,
$ecommerce,
true
)
);
- And don’t forget to save everything to the database
// save the family in database
$fm->save($family);