如何在Sylius 1.4中覆盖模型

时间:2019-04-26 16:58:21

标签: sylius

我想在Sylius 1.4的Customer上添加新字段(类型)
我使用doc覆盖了Model,但无法正常工作。

src \ Entity \ Customer \ Customer.php

<?php

declare(strict_types=1);

namespace App\Entity\Customer;

use Doctrine\ORM\Mapping\MappedSuperclass;
use Doctrine\ORM\Mapping\Table;
use Sylius\Component\Core\Model\Customer as BaseCustomer;

/**
 * @MappedSuperclass
 * @Table(name="sylius_customer")
 */
class Customer extends BaseCustomer
{

    /** @var string */
    protected $type = 'i';

    /**
     * {@inheritdoc}
     */
    public function getType(): string
    {
        return $this->type;
    }

    /**
     * {@inheritdoc}
     */
    public function setType(?string $type): void
    {
        $this->type = $type;
    }

}

src \ Resources \ config \ doctrine \ Customer.orm.xml

<?xml version="1.0" encoding="UTF-8"?>

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                                      http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <mapped-superclass name="App\Entity\Customer" table="sylius_customer">

        <field name="type" column="type" type="string" length="1">
            <options>
                <option name="default">i</option>
            </options>
        </field>

    </mapped-superclass>

</doctrine-mapping>

config \ packages \ _sylius.yaml(不变)

sylius_customer:
    resources:
        customer:
            classes:
                model: App\Entity\Customer\Customer

最后,使用:php bin /控制台make:migration

 [WARNING] No database changes were detected.


 The database schema and the application mapping information are already in sync.

什么是假的?

2 个答案:

答案 0 :(得分:0)

尝试将类定义中的@MappedSuperclass更改为@Entity。如果不起作用,请在Customer.orm.xml中将mapped-superclass更改为entity

答案 1 :(得分:0)

我认为您需要实现CustomerInterface

use Doctrine\ORM\Mapping\MappedSuperclass;
use Doctrine\ORM\Mapping\Table;
use Sylius\Component\Core\Model\Customer as BaseCustomer;
use Sylius\Component\Core\Model\CustomerInterface;

/**
 * @MappedSuperclass
 * @Table(name="sylius_customer")
 */
class Customer extends BaseCustomer implements CustomerInterface
{ 
/*...*/