如何在 Akeneo 正确覆盖产品属性?
How to properly override product attribute at Akeneo?
在我像这样覆盖属性之后:
akeneo_storage_utils:
mapping_overrides:
-
original: Akeneo\Pim\Structure\Component\Model\Attribute
override: Vendor\AkeneoCustomizationsBundle\Entity\Attribute
我在加载固定装置时看到 Error: Class Akeneo\Pim\Structure\Component\Model\Attribute has no field or association named group
异常:
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)
我错过了什么?
在 getAttributeCodesByGroup
方法中转储 DQL 查询后 - 我意识到 AttributeRepository 在查询时有错误的 class:
"SELECT a.code FROM Akeneo\Pim\Structure\Component\Model\Attribute a WHERE a.group = :group"
所以,我找到了它的定义:
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' }
并意识到 - 我还应该用适当的值更新 %pim_catalog.entity.attribute.class%
。
所以,最终配置应该是这样的:
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
在我像这样覆盖属性之后:
akeneo_storage_utils:
mapping_overrides:
-
original: Akeneo\Pim\Structure\Component\Model\Attribute
override: Vendor\AkeneoCustomizationsBundle\Entity\Attribute
我在加载固定装置时看到 Error: Class Akeneo\Pim\Structure\Component\Model\Attribute has no field or association named group
异常:
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)
我错过了什么?
在 getAttributeCodesByGroup
方法中转储 DQL 查询后 - 我意识到 AttributeRepository 在查询时有错误的 class:
"SELECT a.code FROM Akeneo\Pim\Structure\Component\Model\Attribute a WHERE a.group = :group"
所以,我找到了它的定义:
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' }
并意识到 - 我还应该用适当的值更新 %pim_catalog.entity.attribute.class%
。
所以,最终配置应该是这样的:
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