ошибка при переопределении сущности акенео

Я пытаюсь переопределить объект category проекта akeneo. Я следую документу, но всегда получаю ошибку, которую не могу решить.

добавил это в config.yml

-
    original: Pim\Bundle\CatalogBundle\Entity\Category
    override: MyBundle\CatalogBundle\Entity\Category

in entities.yml

parameters:
    pim_catalog.entity.category.class: MyBundle\CatalogBundle\Entity\Category

переопределение, category.php

<?php

namespace MyBundle\CatalogBundle\Entity;

use Pim\Bundle\CatalogBundle\Entity\Category as BaseCategory;

class Category extends BaseCategory
{
    protected $test;

    public function getTest()
    {
        return $this->test;
    }

    public function setTest($test)
    {
        $this->test = $test;

        return $this;
    }
}

category.orm.yml

MyBundle\CatalogBundle\Entity\Category:
    type: entity
    table: pim_catalog_category
    changeTrackingPolicy: DEFERRED_EXPLICIT
    repositoryClass: Akeneo\Bundle\ClassificationBundle\Doctrine\ORM\Repository\CategoryRepository
    uniqueConstraints:
        pim_category_code_uc:
            columns:
                - code
    gedmo:
        tree:
            type: nested
    fields:
        test:
            type: string
            length: 255
            nullable: true

Затем в браузере у меня есть следующая ошибка:

UnexpectedValueException in TreeListener.php line 74: Tree object class: Pim\Bundle\CatalogBundle\Entity\Category must have tree metadata at this point

вот функция, которая выдает исключение, это часть расширений доктрины gedmo

 public function getStrategy(ObjectManager $om, $class)
{
    if (!isset($this->strategies[$class])) {
        $config = $this->getConfiguration($om, $class);

        if (!$config) {
            throw new \Gedmo\Exception\UnexpectedValueException("Tree object class: {$class} must have tree metadata at this point");
        }
        $managerName = 'UnsupportedManager';
        if ($om instanceof \Doctrine\ORM\EntityManager) {
            $managerName = 'ORM';
        } elseif ($om instanceof \Doctrine\ODM\MongoDB\DocumentManager) {
            $managerName = 'ODM\\MongoDB';
        }
        if (!isset($this->strategyInstances[$config['strategy']])) {
            $strategyClass = $this->getNamespace().'\\Strategy\\'.$managerName.'\\'.ucfirst($config['strategy']);

            if (!class_exists($strategyClass)) {
                throw new \Gedmo\Exception\InvalidArgumentException($managerName." TreeListener does not support tree type: {$config['strategy']}");
            }
            $this->strategyInstances[$config['strategy']] = new $strategyClass($this);
        }
        $this->strategies[$class] = $config['strategy'];
    }

    return $this->strategyInstances[$this->strategies[$class]];
}

person t-n-y    schedule 17.08.2017    source источник


Ответы (2)


Убедитесь, что вы загружаете parent.

В файл /src/Acme/Bundle/CatalogBundle/AcmeCatalogBundle.php добавляем

public function getParent()
{
    return 'PimCatalogBundle';
}
person Juan Manuel Pinzon Giraldo    schedule 03.08.2018

Решение:

Вышеупомянутая проблема возникла из-за DependencyInjection. Чтобы решить эту проблему, следуйте приведенным ниже инструкциям:

Создание класса расширения:

1) It has to live in the DependencyInjection namespace of the bundle;
2) It has to implement the ExtensionInterface, which is usually achieved by extending the Extension class;
3) The name is equal to the bundle name with the Bundle suffix replaced by Extension (e.g. the Extension class of the AcmeBundle would be called AcmeExtension and the one for AcmeCatalogBundle would be called AcmeCatalogExtension).

# /src/Acme/Bundle/CatalogBundle/DependencyInjection/AcmeCatalogExtension.php

<?php

namespace Acme\Bundle\CatalogBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\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');
    }
}

Дайте мне знать, если у вас возникнут вопросы

person karthik    schedule 27.12.2018