我',尝试扩展 Variant 模型,以便我可以在此基础上添加我的字段,以便按照此处的指南在产品中使用。
每当我尝试创建产品时都会出现此错误
表单的视图数据应该是 Faumix\ProductPriceBundle\Entity\Variant 类的实例,但它是 Sylius\Bundle\CoreBundle\Model\Variant 类的实例。您可以通过将“data_class”选项设置为 null 或添加将 Sylius\Bundle\CoreBundle\Model\Variant 类的实例转换为 Faumix\ProductPriceBundle\Entity\Variant 的实例的视图转换器来避免此错误。500 内部服务器错误 - LogicException
这是我的实体
<?php
namespace Faumix\ProductPriceBundle\Entity;
use Sylius\Bundle\CoreBundle\Model\Variant as BaseVariant;
class Variant extends BaseVariant{
protected $unitCost;
protected $landedCost;
protected $averagePrice;
protected $profitMargin;
protected $discountA;
protected $discountB;
protected $supplier;
protected $supplierCurrency;
protected $supplierPrice;
protected $reorderLevel;
/**
* {@inheritdoc}
*/
public function setUnitCost($unitCost)
{
$this->unitCost = $unitCost;
return $this;
}
/**
* {@inheritdoc}
*/
public function getUnitCost()
{
return $this->unitCost;
}
/**
* {@inheritdoc}
*/
public function setLandedCost($landedCost)
{
$this->landedCost = $landedCost;
return $this;
}
/**
* {@inheritdoc}
*/
public function getLandedCost()
{
return $this->landedCost;
}
/**
* {@inheritdoc}
*/
public function setAveragePrice($averagePrice)
{
$this->averagePrice = $averagePrice;
return $this;
}
/**
* {@inheritdoc}
*/
public function getAveragePrice()
{
return $this->averagePrice;
}
/**
* {@inheritdoc}
*/
public function setProfitMargin($profitMargin)
{
$this->profitMargin = $profitMargin;
return $this;
}
/**
* {@inheritdoc}
*/
public function getProfitMargin()
{
return $this->profitMargin;
}
/**
* {@inheritdoc}
*/
public function setDiscountA($discountA)
{
$this->discountA = $discountA;
return $this;
}
/**
* {@inheritdoc}
*/
public function getDiscountA()
{
return $this->discountA;
}
/**
* {@inheritdoc}
*/
public function setDiscountB($discountB)
{
$this->discountB = $discountB;
return $this;
}
/**
* {@inheritdoc}
*/
public function getDiscountB()
{
return $this->discountB;
}
/**
* {@inheritdoc}
*/
public function setSupplierPrice($supplierPrice)
{
$this->supplierPrice = $supplierPrice;
return $this;
}
/**
* {@inheritdoc}
*/
public function getSupplierPrice()
{
return $this->supplierPrice;
}
/**
* {@inheritdoc}
*/
public function setReorderLevel($reorderLevel)
{
$this->reorderLevel = $reorderLevel;
return $this;
}
/**
* {@inheritdoc}
*/
public function getReorderLevel()
{
return $this->reorderLevel;
}
/**
* {@inheritdoc}
*/
public function setSupplier($supplier)
{
$this->supplier = $supplier;
return $this;
}
/**
* {@inheritdoc}
*/
public function getSupplier()
{
return $this->supplier;
}
/**
* {@inheritdoc}
*/
public function setSupplierCurrency($currency)
{
$this->supplierCurrency = $currency;
return $this;
}
/**
* {@inheritdoc}
*/
public function getSupplierCurrency()
{
return $this->supplierCurrency;
}
}
这是我的实体 xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-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"
xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"
>
<entity name="Faumix\ProductPriceBundle\Entity\Variant" table="sylius_variant">
<field name="unitCost" column="unit_cost" type="float" nullable="true">
<gedmo:versioned />
</field>
<field name="landedCost" column="landed_cost" type="float" nullable="true"/>
<field name="profitMargin" column="profitMargin" type="integer" nullable="true"/>
<field name="averagePrice" column="average_price" type="float" nullable="true" />
<field name="discountA" column="discount_a" type="float" nullable="true">
<gedmo:versioned />
</field>
<field name="discountB" column="discount_b" type="float" nullable="true">
<gedmo:versioned />
</field>
<field name="reorderLevel" column="reorder_level" type="integer" nullable="true">
<gedmo:versioned />
</field>
<field name="supplierPrice" column="supplier_price" type="float" nullable="true">
<gedmo:versioned />
</field>
<field name="supplier" column="supplier" type="string" nullable="true">
<gedmo:versioned />
</field>
<field name="supplierCurrency" column="supplier_currency" type="string" nullable="true">
<gedmo:versioned />
</field>
<gedmo:loggable />
</entity>
</doctrine-mapping>
到目前为止一切正常,即使我运行了 php app/console dictionary:schema:update --force 来更新表格
不知道出了什么问题,我尝试扩展表单,但我没有添加所有字段
编辑 1 我已经扩展了表格,但现在出现了不同的错误
属性“unitCost”和方法之一“getUnitCost()”、“isUnitCost()”、“hasUnitCost()”、“__get()”都不存在并且在类“Sylius\Bundle\CoreBundle\Model\”中具有公共访问权限变体”。500 内部服务器错误 - NoSuchPropertyException
这是表单类
namespace Faumix\ProductPriceBundle\Form\Type;
use Sylius\Bundle\CoreBundle\Form\Type\VariantType as BaseVariantType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class VariantType extends BaseVariantType {
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder
->add('unitCost', 'text', array(
'data_class' => 'Sylius\Bundle\CoreBundle\Model\Variant',
'label' => 'Unit Cost',
))
->add('landedCost', 'sylius_money', array(
'label' => 'Landed Cost',
'data_class' => 'Faumix\ProductPriceBundle\Entity\Variant'
))
->add('averagePrice', 'text', array(
'label' => 'average Price',
'data_class' => 'Faumix\ProductPriceBundle\Entity\Variant'
))
->add('profitMargin', 'text', array(
'label' => 'profit Margin',
'data_class' => 'Faumix\ProductPriceBundle\Entity\Variant'
))
->add('discountA', 'text', array(
'label' => 'discount A',
'data_class' => 'Faumix\ProductPriceBundle\Entity\Variant'
))
->add('discountB', 'text', array(
'label' => 'discount B',
'data_class' => 'Faumix\ProductPriceBundle\Entity\Variant'
))
->add('supplier', 'text', array(
'label' => 'supplier',
'data_class' => 'Faumix\ProductPriceBundle\Entity\Variant'
))
->add('supplierCurrency', 'text', array(
'label' => 'supplierCurrency',
'data_class' => 'Faumix\ProductPriceBundle\Entity\Variant'
))
->add('supplierPrice', 'text', array(
'label' => 'supplier Price',
'data_class' => 'Faumix\ProductPriceBundle\Entity\Variant'
))
->add('reorderLevel', 'text', array(
'label' => 'reorder Level',
'data_class' => 'Faumix\ProductPriceBundle\Entity\Variant'
))
;
}
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver
->setDefaults(array(
// 'data_class' => 'Faumix\ProductPriceBundle\Entity\Variant',
'data_class' => 'Sylius\Bundle\CoreBundle\Model\Variant',
'validation_groups' => $this->validationGroups,
'master' => false
))
;
}
}
我试过不定义 data_class 但似乎没有影响
如果有人可以帮助我,我将不胜感激
问候