Php Sylius:覆盖序列化程序配置“;Model.Product.yml“;公开更多文件的步骤

Php Sylius:覆盖序列化程序配置“;Model.Product.yml“;公开更多文件的步骤,php,symfony,sylius,Php,Symfony,Sylius,我是Sylius的新手,我正在使用RESTAPI。 我的问题是:如何覆盖序列化文件以公开更多文件。 例如: vendor/sylius/sylius/src/sylius/Bundle/ProductBundle/Resources/config/serializer/Model.Product.yml 当我通过添加一些字段作为原型和翻译进行测试时,它们工作得非常好 Sylius\Component\Product\Model\Product: exclusion_policy: ALL xml

我是Sylius的新手,我正在使用RESTAPI。 我的问题是:如何覆盖序列化文件以公开更多文件。 例如:

vendor/sylius/sylius/src/sylius/Bundle/ProductBundle/Resources/config/serializer/Model.Product.yml

当我通过添加一些字段作为原型和翻译进行测试时,它们工作得非常好

Sylius\Component\Product\Model\Product:
exclusion_policy: ALL
xml_root_name: product
properties:
    id:
        expose: true
        type: integer
        xml_attribute: true
    name:
        expose: true
        type: string
    description:
        expose: true
        type: string
    attributes:
        expose: true
        max_depth: 2
    createdAt:
        expose: true
        type: DateTime
    updatedAt:
        expose: true
        type: DateTime
    archetype:
        expose:
        serialized_name: archetypes
    translations:
        expose: true
        serialized_name: translations
virtual_properties:
    getVariants:
        serialized_name: variants

如何覆盖此配置?

您应该首先创建自己的包来扩展核心包(假设您使用的是Sylius标准版)

然后重写产品模型,以下-->应位于YourBundle\Entity\Product.php中


最后,创建Resources\config\serializer\Entity.Product.yml并在此处执行任何您想要的操作:)

您应该首先创建自己的包来扩展核心包(假设您使用的是Sylius标准版)

然后重写产品模型,以下-->应位于YourBundle\Entity\Product.php中

最后,创建Resources\config\serializer\Entity.Product.yml,并在此处执行您想要的操作:)