2014-02-11 1 views
0

I ', пытаясь расширить модель Variant, поэтому я могу добавить свои поля поверх этого, которые будут использоваться в Продукте в соответствии с руководством here.LogicException после расширения модели Sylius 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 приложение/console doctrine: schema: update --force, которая обновила таблицу

Я не уверен, что пошло не так, я событие пытался расширить форму, но я не добавлять Все поля

EDIT 1 Я продлил форму, но я получил Different ошибка сейчас

Ни свойство «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, но это не кажется, что это не влияет

Я был бы признателен, если кто может помогите мне в этом

приветствует

+0

я не знаю, но Sylys это не похоже на проблему сущности, а на форму. Используете ли вы какую-либо форму в своих контроллерах, связанных с этим объектом? – DonCallisto

+0

Спасибо @DonCallisto, я согласен с вами в проблеме с не сущностью, так как мне удалось запустить команду doctrine и обновить таблицу, если я использую некоторые в контроллерах, все, что я сделал, - это расширение объекта и попытка расширить форму до посмотрите, не решит ли я эту проблему, но это не так, я мог бы пропустить правильную форму для расширения. Спасибо, в любом случае – Mat

ответ

0

D id вы найдете, откуда возникла проблема. У меня есть аналогичная попытка продлить еще одну модель в Sylius, и теперь я собирался попытаться расширить модель Variant. Благодаря

EDIT: это на самом деле работает нормально с моделью Variant, но я до сих пор есть проблемы с ImagineBlockType в случае, если кто приходит с решением (здесь сообщается https://github.com/Sylius/Sylius/issues/2544 выпуск)

Смежные вопросы