总收入为0.01英镑的magento支付总额不匹配

时间:2014-09-01 12:02:52

标签: php magento

我正在使用此扩展程序为所有订阅的新闻订阅者提供5%的折扣,其工作正常,但我得到的唯一错误是当我查看magento后端的订单时,它说Total Due£0.01以及世界付费交易记录它说总订单金额为5.43英镑

小计£2.85 运输与发货处理2.59英镑 折扣(5%折扣小计)£2.71 税£0.14 总计5.44英镑 支付总额5.43英镑 退款总额£0.00 总到期£0.01

以下是我正在使用的扩展程序的代码:

<?php

class Sugarcode_Customdiscount_Model_Observer
{
    public function setDiscount($observer)
    {
        if(isset($_SESSION["subscribed_customer"]))
        {
            $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($_SESSION["subscribed_customer"]);
            $isSubscribed = "";
            if($subscriber->getId())
            {
                $isSubscribed = $subscriber->getData('subscriber_status') == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED;
                if($isSubscribed)
                {
                    $quote = $observer->getEvent()->getQuote();
                    $quoteid = $quote->getId();
                    //$total = $quote->getGrandTotal();
                    $total = $quote->getSubtotal();

                    $discountAmount = number_format(($total - $total / 1.05), 2);
                    if($quoteid)
                    {
                        if($discountAmount > 0)
                        {
                            $total = $quote->getBaseSubtotal();
                            $quote->setSubtotal(0);
                            $quote->setBaseSubtotal(0);

                            $quote->setSubtotalWithDiscount(0);
                            $quote->setBaseSubtotalWithDiscount(0);

                            $quote->setGrandTotal(0);
                            $quote->setBaseGrandTotal(0);


                            $canAddItems = $quote->isVirtual() ? ('billing') : ('shipping');
                            foreach($quote->getAllAddresses() as $address)
                            {

                                $address->setSubtotal(0);
                                $address->setBaseSubtotal(0);

                                $address->setGrandTotal(0);
                                $address->setBaseGrandTotal(0);

                                $address->collectTotals();

                                $quote->setSubtotal((float) $quote->getSubtotal() + $address->getSubtotal());
                                $quote->setBaseSubtotal((float) $quote->getBaseSubtotal() + $address->getBaseSubtotal());
                                $quote->setSubtotalWithDiscount((float) $quote->getSubtotalWithDiscount() + $address->getSubtotalWithDiscount());
                                $quote->setBaseSubtotalWithDiscount((float) $quote->getBaseSubtotalWithDiscount() + $address->getBaseSubtotalWithDiscount());
                                $quote->setGrandTotal((float) $quote->getGrandTotal() + $address->getGrandTotal());
                                $quote->setBaseGrandTotal((float) $quote->getBaseGrandTotal() + $address->getBaseGrandTotal());
                                $quote->save();

                                $quote->setGrandTotal($quote->getBaseSubtotal() - $discountAmount)
                                ->setBaseGrandTotal($quote->getBaseSubtotal() - $discountAmount)
                                ->setSubtotalWithDiscount($quote->getBaseSubtotal() - $discountAmount)
                                ->setBaseSubtotalWithDiscount($quote->getBaseSubtotal() - $discountAmount)
                                ->save();


                                if($address->getAddressType() == $canAddItems)
                                {
                                    $address->setSubtotalWithDiscount((float) $address->getSubtotalWithDiscount() - $discountAmount);
                                    $address->setGrandTotal((float) $address->getGrandTotal() - $discountAmount);
                                    $address->setBaseSubtotalWithDiscount((float) $address->getBaseSubtotalWithDiscount() - $discountAmount);
                                    $address->setBaseGrandTotal((float) $address->getBaseGrandTotal() - $discountAmount);

                                    // When Mageno Promo Code is used
                                    if($address->getDiscountDescription())
                                    {
                                        $address->setDiscountAmount(($address->getDiscountAmount() - $discountAmount));
                                        //$address->setDiscountAmount($total - $discountAmount);
                                        $address->setDiscountDescription($address->getDiscountDescription());
                                        //$address->setBaseDiscountAmount($total - $discountAmount);
                                        $address->setBaseDiscountAmount(-($address->getBaseDiscountAmount() - $discountAmount));
                                    }
                                    // When Subscribed Customer 5% discount is used
                                    else
                                    {
                                        //$address->setDiscountAmount(-($discountAmount));
                                        $address->setDiscountAmount($total - $discountAmount);
                                        $address->setDiscountDescription("5% Discounted Subtotal");
                                        $address->setBaseDiscountAmount($total - $discountAmount);
                                        //$address->setBaseDiscountAmount(-($discountAmount));
                                    }

                                    $address->save();
                                }
                            }

                            foreach($quote->getAllItems() as $item)
                            {
                                //We apply discount amount based on the ratio between the GrandTotal and the RowTotal
                                $rat = $item->getPriceInclTax() / $total;
                                $ratdisc = $discountAmount * $rat;

                                $item->setDiscountAmount(($item->getDiscountAmount() + $ratdisc) * $item->getQty());
                                $item->setBaseDiscountAmount(($item->getBaseDiscountAmount() + $ratdisc) * $item->getQty())->save();
                            }
                        }
                    }
                }
            }
        }
    }
}

2 个答案:

答案 0 :(得分:0)

我检查了你的代码,它没有任何问题。问题应该在其他地方。您可能重写了销售订单模型吗?通过逐个禁用模块配置文件中的功能,尝试找到它。

答案 1 :(得分:0)

得到解决方案  替换以下内容:

foreach($quote->getAllItems() as $item)
{
    //We apply discount amount based on the ratio between the GrandTotal and the RowTotal
    $rat = $item->getPriceInclTax() / $total;
    $ratdisc = $discountAmount * $rat;
    $item->setDiscountAmount(($item->getDiscountAmount() + $ratdisc) * $item->getQty());
    $item->setBaseDiscountAmount(($item->getBaseDiscountAmount() + $ratdisc) * $item->getQty())->save();
}

with:

foreach($quote->getAllItems() as $item)
{
    //We apply discount amount based on the ratio between the GrandTotal and the RowTotal
    //$rat = $item->getPriceInclTax() / $total;
    //$ratdisc = $discountAmount * $rat;

    $item->setDiscountAmount($discount) + $ratdisc) * $item->getQty());
    $item->setBaseDiscountAmount($discount) * $item->getQty())->save();
}

// $折扣 - &gt;你打折金额