使Sylius ProductImage可翻译

时间:2017-04-25 15:38:15

标签: php symfony doctrine sylius

我开始'疯狂使Sylius ProductImage可翻译。我需要一个ProductImage名称和slug用于搜索引擎优化目的。

我已经做过的事情是:

  • 通过param覆盖ProductIamge:sylius.model.product_image.class
  • 添加了TranslatableInterface及其所需的功能
  • 添加了ProductImageTranslation实体
  • 为ProductImage.orm.yml&添加了映射文件。 ProductImageTranslation.orm.yml
  • 扩展config.yml

ProductImage.orm.yml

AppBundle\Entity\ProductImage:
    type: entity
    table: sylius_product_image

ProductImageTranslation.orm.yml

AppBundle\Entity\ProductImageTranslation:
    type: entity
    table: app_product_image_translation
    id:
        id:
          type: integer
          generator:
        strategy: AUTO
    fields:
        name:
            type: string
            nullable: true
        slug:
            type: string
            nullable: true
            unique: true

config.yml

sylius_resource:
    resources:
        app.product_image:
            classes:
                model: AppBundle\Entity\ProductImage
                form: AppBundle\Form\Type\ProductImageType
            translation:
                classes:
                    model: AppBundle\Entity\ProductImageTranslation
                    form: AppBundle\Form\Type\ProductImageTranslationType

结果是以下错误:

An exception occurred while executing 'SELECT t1.type AS type_2, t1.path AS path_3, t1.id AS id_4, t1.owner_id AS owner_id_5 FROM sylius_product_image t1 WHERE t0.owner_id = ?' with params [22]:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 't0.owner_id' in 'where clause'

在我看来,由于缺少连接的转换表而发生错误。

1 个答案:

答案 0 :(得分:0)

您还需要覆盖sylius_core(http://docs.sylius.org/en/latest/customization/model.html

中的默认ProductImage

config.yml:

sylius_resource:
    resources:
        app.product_image:
            classes:
                model: AppBundle\Entity\ProductImage
            translation:
                classes:
                    model: AppBundle\Entity\ProductImageTranslation

sylius_core:
    resources:
        product_image:
            classes:
                model: AppBundle\Entity\ProductImage

然后按照可翻译指南:http://docs.sylius.org/en/latest/cookbook/custom-translatable-model.html

如果您遵循所有指南,您将能够生成新实体,但您将获得以下内容:

The association AppBundle\Entity\ProductImageTranslation#translatable refers to the inverse side field AppBundle\Entity\ProductImage#translations which does not exist.

您可以通过修改Sylius\Bundle\CoreBundle\DependencyInjection\Configuration来使其发挥作用 并在'product_image'下添加一个“翻译”节点,这显然不是一件事......

也许如果一个sylius核心成员可以给我们一个线索......