How to Add New Properties to a Category

The Akeneo PIM allows the classification of products inside a customizable category tree.

Add Properties to your own Category

The first step is to create a class that extends PIM Category class.

Note

Class inheritance is implemented with a Doctrine discriminator map. Please be sure not to use Category as the name of your class so as to avoid unexpected problems.

For example, we can add a description property with a text field.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# /src/Acme/Bundle/CatalogBundle/Entity/MyCategory.php
<?php

namespace Acme\Bundle\CatalogBundle\Entity;

use Pim\Bundle\CatalogBundle\Entity\Category;

class MyCategory extends Category
{
    protected $description;

    public function getDescription()
    {
        return $this->description;
    }

    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }
}
1
2
3
4
5
6
7
8
# /src/Acme/Bundle/CatalogBundle/Resources/config/doctrine/MyCategory.orm.yml
Acme\Bundle\CatalogBundle\Entity\MyCategory:
    type: entity
    repositoryClass: Pim\Bundle\CatalogBundle\Entity\Repository\CategoryRepository
    fields:
        description:
            type: string
            length: 255

Define the Category Class

You need to update your category entity parameter used in entities.yml file:

1
2
3
# /src/Acme/Bundle/CatalogBundle/Resources/config/entities.yml
parameters:
    pim_catalog.entity.category.class: Acme\Bundle\CatalogBundle\Entity\MyCategory

Note

You don’t have to add enough code for resolve target entities doctrine configuration. We already have a resolve which inject the new value for your category.

The same procedure can be applied to redefine the product and product value entities.