简体   繁体   English

购物车总额计算不正确

[英]Cart total is not calculated correctly

I have unusual problem..in my sylius project when I add 2 products to the cart, cart total is not correct. 当我在购物车中添加2个产品时,我的sylius项目中出现异常问题。购物车总数不正确。 It is always less than it should be, even though there are no discounts or adjustments attached to the products. 即使产品没有折扣或调整,它总是比应有的少。 I have not changed sylius original logic behind that, but I have changed ChannelPricing entity and added fields oldPrice and discount. 我没有更改sylius的原始逻辑,但是更改了ChannelPricing实体并添加了oldPrice和Discount字段。 I'm not sure if that had anything to do with it. 我不确定这是否与此有关。 I tried reverting to see would it change anything, but no luck. 我试着回头看看它会改变什么,但是没有运气。 您会看到它是如何计算错误的 您可以在此处看到单价与总计之间的差异 This is my code for 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;
    }
 }`

And

 sylius_core:
    driver: doctrine/orm
    resources:
        channel_pricing:
            classes:
                model: AppBundle\Entity\ChannelPricing

Also code for the form extension 还为表单扩展编码

 <?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;
    }
}

I'm pretty sure that the ChannelPricing modification changes everything. 我很确定ChannelPricing修改会更改所有内容。 Did you try to see what is saved on the ChannelPricing related to your OrderItem? 您是否尝试查看与您的OrderItem相关的ChannelPricing中保存了什么?

我想象这是由于版本控制引起的错误..在将其更新为最新的dev-master之后,它可以按预期运行,并且无法再进行复制。

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

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