dependency-injectiondoctrineoverridingakeneo

How to properly override product attribute at Akeneo?


After I've overriden Attribute like this:

akeneo_storage_utils:
    mapping_overrides:
        -
            original: Akeneo\Pim\Structure\Component\Model\Attribute
            override: Vendor\AkeneoCustomizationsBundle\Entity\Attribute

I see Error: Class Akeneo\Pim\Structure\Component\Model\Attribute has no field or association named group exception when loading fixtures:


    Fixtures fixtures_currency_csv has been successfully executed.
    Fixtures fixtures_locale_csv has been successfully executed.
    Fixtures fixtures_user_group_csv has been successfully executed.
    Fixtures fixtures_category_csv has been successfully executed.
21:55:38 ERROR     [batch] Encountered an error executing the step: [Semantical Error] line 0, col 76 near 'group = :gro': Error: Class Akeneo\Pim\Structure\Component\Model\Attribute has no field or association named group
    An error occurred during the fixtures execution.
    Error #0 in class Doctrine\ORM\Query\QueryException: [Semantical Error] line 0, col 76 near 'group = :gro': Error: Class Akeneo\Pim\Structure\Component\Model\Attribute has no field or association named group
#0 akeneo/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(492): Doctrine\ORM\Query\QueryException::semanticalError('line 0, col 76 ...', Object(Doctrine\ORM\Query\QueryException))
#1 akeneo/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(765): Doctrine\ORM\Query\Parser->semanticalError('line 0, col 76 ...', Array)
#2 akeneo/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(272): Doctrine\ORM\Query\Parser->processDeferredPathExpressions()
#3 akeneo/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(360): Doctrine\ORM\Query\Parser->getAST()
#4 akeneo/vendor/doctrine/orm/lib/Doctrine/ORM/Query.php(286): Doctrine\ORM\Query\Parser->parse()
#5 akeneo/vendor/doctrine/orm/lib/Doctrine/ORM/Query.php(298): Doctrine\ORM\Query->_parse()
#6 akeneo/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php(992): Doctrine\ORM\Query->_doExecute()
#7 akeneo/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php(947): Doctrine\ORM\AbstractQuery->executeIgnoreQueryCache(NULL, 3)
#8 akeneo/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php(774): Doctrine\ORM\AbstractQuery->execute(NULL, 3)
#9 akeneo/vendor/akeneo/pim-community-dev/src/Akeneo/Pim/Structure/Bundle/Doctrine/ORM/Repository/AttributeRepository.php(340): Doctrine\ORM\AbstractQuery->getScalarResult()
#10 akeneo/vendor/akeneo/pim-community-dev/src/Akeneo/Pim/Structure/Component/Normalizer/Standard/AttributeGroupNormalizer.php(43): Akeneo\Pim\Structure\Bundle\Doctrine\ORM\Repository\AttributeRepository->getAttributeCodesByGroup(Object(Akeneo\Pim\Structure\Component\Model\AttributeGroup))
#11 akeneo/vendor/akeneo/pim-community-dev/src/Akeneo/Pim/Structure/Component/Normalizer/Versioning/AttributeGroupNormalizer.php(50): Akeneo\Pim\Structure\Component\Normalizer\Standard\AttributeGroupNormalizer->normalize(Object(Akeneo\Pim\Structure\Component\Model\AttributeGroup), 'standard', Array)
#12 akeneo/vendor/symfony/serializer/Serializer.php(153): Akeneo\Pim\Structure\Component\Normalizer\Versioning\AttributeGroupNormalizer->normalize(Object(Akeneo\Pim\Structure\Component\Model\AttributeGroup), 'flat', Array)

What I've missed?


Solution

  • After dumping a DQL query at getAttributeCodesByGroup method - I've realized that AttributeRepository have wrong class at query:

    "SELECT a.code FROM Akeneo\Pim\Structure\Component\Model\Attribute a WHERE a.group = :group"
    

    So, I've found its definition:

        pim_catalog.repository.attribute:
            class: 'Akeneo\Pim\Structure\Bundle\Doctrine\ORM\Repository\AttributeRepository'
            factory: 'doctrine.orm.entity_manager:getRepository'
            arguments: ['%pim_catalog.entity.attribute.class%']
            tags:
                - { name: 'pim_repository' }
    

    And realized - I should also update %pim_catalog.entity.attribute.class% with proper value.

    So, final config should be like this:

    parameters:
        pim_catalog.entity.attribute.class: Vendor\AkeneoCustomizationsBundle\Entity\Attribute
    
    akeneo_storage_utils:
        mapping_overrides:
            -
                original: Akeneo\Pim\Structure\Component\Model\Attribute
                override: Vendor\AkeneoCustomizationsBundle\Entity\Attribute