繁体   English   中英

购物车总额计算不正确

[英]Cart total is not calculated correctly

当我在购物车中添加2个产品时,我的sylius项目中出现异常问题。购物车总数不正确。 即使产品没有折扣或调整,它总是比应有的少。 我没有更改sylius的原始逻辑,但是更改了ChannelPricing实体并添加了oldPrice和Discount字段。 我不确定这是否与此有关。 我试着回头看看它会改变什么,但是没有运气。 您会看到它是如何计算错误的 您可以在此处看到单价与总计之间的差异 这是我的渠道定价代码:

 <?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之后,它可以按预期运行,并且无法再进行复制。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM