我正在尝试扩展Variant模型,以便我可以在指南here后面的产品中添加我的字段 .
每当我尝试创建产品时,我都会收到此错误消息
表单的视图数据应该是Faumix \ ProductPriceBundle \ Entity \ Variant类的实例,但是是Sylius \ Bundle \ CoreBundle \ Model \ Variant类的实例 . 您可以通过将“data_class”选项设置为null或添加视图转换器来将此类错误设置为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 doctrine:schema:update --force更新了表
我不确定出了什么问题,我事件试图扩展表单,但我没有添加所有字段
EDIT 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,但它似乎没有影响
如果有人能帮助我,我将不胜感激
问候
1 回答
你找到了问题的来源吗?我有一个类似的尝试在Sylius扩展另一个模型,我只是想尝试扩展Variant模型 . 谢谢
编辑:这实际上与Variant模型工作正常但我仍然遇到ImagineBlockType的问题,以防任何人提出解决方案(此处报告的问题https://github.com/Sylius/Sylius/issues/2544)