Akeneo bundle creation

502 views Asked by At

I'm currently trying to add a translatable textarea into the description dashboard, as described here: https://docs.akeneo.com/3.2/manipulate_pim_data/category/add_new_properties_to_a_category.html My current Akeneo version is 3.2, due to some architectural limitations I cannot upgrade right now to v.4.

I slavishly followed the steps described above, still when I run pim-community-standard % php bin/console doctrine:schema:update --dump-sql --verbose I get this error:

In TreeListener.php line 72:
[Gedmo\Exception\UnexpectedValueException]
Tree object class: Akeneo\Pim\Enrichment\Component\Category\Model\Category must have tree metadata at this point

These are my files at the moment:

pim-community-standard/src/Acme/Bundle/CatalogBundle/Entity/CategoryTranslation.php:

<?php

namespace Acme\Bundle\CatalogBundle\Entity;

use Akeneo\Pim\Enrichment\Component\Category\Model\CategoryTranslation as BaseCategoryTranslation;

class CategoryTranslation extends BaseCategoryTranslation
{
    protected $description;

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

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

        return $this;
    }
}

pim-community-standard/src/Acme/Bundle/CatalogBundle/Entity/Category.php:

<?php

namespace Acme\Bundle\CatalogBundle\Entity;

use Akeneo\Pim\Enrichment\Component\Category\Model\Category as BaseCategory;

class Category extends BaseCategory
{
    public function getDescription()
    {
        $translated = ($this->getTranslation()) ? $this->getTranslation()->getDescription() : null;

        return ($translated !== '' && $translated !== null) ? $translated : '['.$this->getCode().']';
    }

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

        return $this;
    }

    public function getTranslationFQCN()
    {
        return CategoryTranslation::class;
    }
}

pim-community-standard/src/Acme/Bundle/CatalogBundle/Resources/config/entities.yml:

parameters:
    pim_catalog.entity.category.class: Acme\Bundle\CatalogBundle\Entity\Category
    pim_catalog.entity.category_translation.class: Acme\Bundle\CatalogBundle\Entity\CategoryTranslation

pim-community-standard/src/Acme/Bundle/CatalogBundle/DependencyInjection/AcmeCatalogExtension.php

<?php
// https://stackoverflow.com/questions/45730301/error-on-override-akeneo-entity
// https://github.com/akeneo/pim-community-dev/issues/7509
namespace Acme\Bundle\CatalogBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Extension\Extension;

class AcmeCatalogExtension extends Extension
{
    public function load(array $configs, ContainerBuilder $container)
    {
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('entities.yml');
    }
}

I added this code at the bottom of pim-community-standard/app/config/config.yml

akeneo_storage_utils:
    mapping_overrides:
        -
            original: Akeneo\Pim\Enrichment\Component\Category\Model\Category
            override: Acme\Bundle\CatalogBundle\Entity\Category
        -
            original: Akeneo\Pim\Enrichment\Component\Category\Model\CategoryTranslation
            override: Acme\Bundle\CatalogBundle\Entity\CategoryTranslation

Plus the two .orm.yml files. Here is my full bundle filesystem:

Bundle screenshot

In fact, my new classes extend the same ones I'm overriding in config.yml. So I'm not getting why I'm getting any error. Note that I actually did a lot of trial and error so I'm not sure, are previous versions of the extensions getting cached in any way?

1

There are 1 answers

0
freshdevelop On

AcmeCatalogBundle needs to be registered into /app/config/AppKernel.php, like this:

protected function registerProjectBundles()
    {
        return [
            // your app bundles should be registered here
            new \Acme\Bundle\CatalogBundle\AcmeCatalogBundle(),
        ];
    }