购物车总数计算不正确
Cart total is not calculated correctly
我有一个不寻常的问题..在我的 sylius 项目中,当我将 2 个产品添加到购物车时,购物车总数不正确。它总是低于应有的价格,即使产品没有折扣或调整。我没有改变背后的 sylius 原始逻辑,但我改变了 ChannelPricing 实体并添加了字段 oldPrice 和折扣。我不确定这是否与它有关。我试着恢复看看它会改变什么,但没有运气。
这是我的频道定价代码:
<?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;
}
}
我很确定 ChannelPricing 修改会改变一切。您是否尝试查看与您的 OrderItem 相关的 ChannelPricing 上保存的内容?
这是我想象的版本控制错误.. 在我将它更新到最新版本后 dev-master 它按预期工作,我无法再重现它了。
我有一个不寻常的问题..在我的 sylius 项目中,当我将 2 个产品添加到购物车时,购物车总数不正确。它总是低于应有的价格,即使产品没有折扣或调整。我没有改变背后的 sylius 原始逻辑,但我改变了 ChannelPricing 实体并添加了字段 oldPrice 和折扣。我不确定这是否与它有关。我试着恢复看看它会改变什么,但没有运气。
<?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;
}
}
我很确定 ChannelPricing 修改会改变一切。您是否尝试查看与您的 OrderItem 相关的 ChannelPricing 上保存的内容?
这是我想象的版本控制错误.. 在我将它更新到最新版本后 dev-master 它按预期工作,我无法再重现它了。