如何在Sylius 1.4中覆盖Model

问题描述 投票:0回答:2

我想在Sylius 1.4中的Customer上添加新字段(类型) 我使用doc来覆盖Model,但它不起作用。

SRC \实体\用户\ 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 \资源\ CONFIG \原则\ 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 / console make:migration

 [WARNING] No database changes were detected.


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

什么是假的?

sylius
2个回答
0
投票

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


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
{ 
/*...*/
© www.soinside.com 2019 - 2024. All rights reserved.