我有一个不寻常的问题..在我的sylius项目中,当我将2个产品添加到购物车时,购物车总数不正确。尽管产品没有任何折扣或调整,但它总是低于应有的水平。我没有更改sylius原始逻辑,但我更改了ChannelPricing实体并添加了字段oldPrice和discount。我不确定这与它有什么关系。我试图恢复,看它会改变什么,但没有运气。 这是我的channelpricing代码:
<?php
namespace AppBundle\Entity;
use Sylius\Component\Core\Model\ChannelPricing as BaseChannelPricing;
class ChannelPricing extends BaseChannelPricing
{
/**
* @var int
*/
protected $oldPrice;
/**
* @var float
*/
protected $discount;
/**
* @return mixed
*/
public function getOldPrice()
{
return $this->oldPrice;
}
/**
* @param mixed $oldPrice
*/
public function setOldPrice($oldPrice)
{
$this->oldPrice = $oldPrice;
}
/**
* @return mixed
*/
public function getDiscount()
{
return $this->discount;
}
/**
* @param mixed $discount
*/
public function setDiscount($discount)
{
$this->discount = $discount;
}
}`
并且
sylius_core:
driver: doctrine/orm
resources:
channel_pricing:
classes:
model: AppBundle\Entity\ChannelPricing
也是表单扩展名的代码
<?php
namespace AppBundle\Form\Extension;
use Sylius\Bundle\CoreBundle\Form\Type\Product\ChannelPricingType;
use Symfony\Component\Form\AbstractTypeExtension;
use Sylius\Bundle\MoneyBundle\Form\Type\MoneyType;
use Sylius\Component\Core\Model\ChannelInterface;
use Symfony\Component\Form\Extension\Core\Type\PercentType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
class ChannelPricingTypeExtension extends AbstractTypeExtension
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
/** @var ChannelInterface $channel */
$channel = $event->getData()->getChannel();
$form = $event->getForm();
$form->remove('price')
->add('oldPrice',MoneyType::class,[
'label' => 'Stara cijena',
'currency' => $channel->getBaseCurrency()->getCode(),
])
->add('discount',PercentType::class,[
'label' => 'Popust',
])->add('price',MoneyType::class,[
'label' => 'Cijena',
'currency' => $channel->getBaseCurrency()->getCode(),
]);
})
;
}
/**
* Returns the name of the type being extended.
*
* @return string The name of the type being extended
*/
public function getExtendedType()
{
return ChannelPricingType::class;
}
}
答案 0 :(得分:0)
我很确定ChannelPricing修改会改变一切。您是否尝试查看与您的OrderItem相关的ChannelPricing上保存的内容?
答案 1 :(得分:0)
由于我想象的版本控制,这是一个错误..在我将它更新到最新的开发大师后,它正在按预期工作,我不能再复制它了。