PayPal网关拒绝了请求。购物车项目金额的总数与订单金额不匹配。 Magento的

时间:2014-10-02 12:32:54

标签: php mysql magento zend-framework paypal

我很清楚最新情况。我不知道如何解决它。由于我要求paypal包含订单项,因此它会计算总订单项,但它们与总计不匹配。

的config.xml

    <sales>
        <quote>
            <totals>
                <biddiscount>
                    <class>winints/biddiscount</class>
                    <before>subtotal</before>
                </biddiscount>
                <globaldiscount>
                    <class>winints/globaldiscount</class>
                    <before>subtotal</before>
                </globaldiscount>
            </totals>
        </quote>
    </sales>

GlobalDiscount Class

<?php
/**
 * Created by PhpStorm.
 * User: numerical25
 * Date: 5/17/14
 * Time: 7:49 PM
 */

class Superior_WinInts_Model_Globaldiscount extends Mage_Sales_Model_Quote_Address_Total_Subtotal {

    protected  $amount = 0;
    protected  $set = 0;

    public function collect(Mage_Sales_Model_Quote_Address $address) {
        if ($address->getData('address_type') == 'billing')
            return $this;
        $discount = Mage::app()->getRequest()->getParam('global_discount_amount');
        $grandTotal = $address->getGrandTotal();
        $baseGrandTotal = $address->getBaseGrandTotal();
        if(Mage::getSingleton('customer/session')->isLoggedIn() && $discount) {

            $customer =  Mage::getModel('customer/customer')->load(Mage::getSingleton('customer/session')->getId());
            $credit =  Mage::getModel("winints/wallet")
                ->getCustomerStoreCreditTotal($customer->getId());
            if($credit >= $discount) {
                $this->amount = $discount;
            }
            Mage::getSingleton('core/session')->setGlobalDiscount($discount);

            $totals = array_sum($address->getAllTotalAmounts());
            $baseTotals = array_sum($address->getAllBaseTotalAmounts());
            //You have to set Grand and Base Grand Total for this crap to work
            $address->setDiscountAmount(-$discount);
            $address->setBaseDiscountAmount(-$discount);
            $address->setGrandTotal($grandTotal - $discount);
            $address->setBaseGrandTotal($baseGrandTotal - $discount);
            $address->setSubtotal($baseGrandTotal - $discount);

        } else if (Mage::getSingleton('core/session')->getGlobalDiscount()) {
            $discount = Mage::getSingleton('core/session')->getGlobalDiscount();
            $this->amount = Mage::getSingleton('core/session')->getGlobalDiscount();
            $address->setDiscountAmount(-$discount);
            $address->setBaseDiscountAmount(-$discount);
            $address->setGrandTotal($grandTotal - $discount);
            $address->setBaseGrandTotal($baseGrandTotal - $discount);
            $address->setSubtotal($baseGrandTotal - $discount);
        }
        return $this;
    }

    public function fetch(Mage_Sales_Model_Quote_Address $address)
    {
        if(Mage::getSingleton('core/session')->getGlobalDiscount()) {
            if(!$this->set) {
                $address->addTotal(array(
                    'code'=>$this->getCode(),
                    'title'=>Mage::helper('catalog')->__('Global Discount (-)'),
                    'value'=> $this->amount
                ));
                $this->set = 1;
            }
        }
        return $this;
    }
}

我已经完成了教程告诉我的所有内容,我尝试更新基本总数,总计,小计,一切。它仍然无法正确匹配

我做错了什么?

还有其他帖子,但不清楚。显然,订单项从总计中计算错误。

1 个答案:

答案 0 :(得分:1)

想出来,是的,在线参考不正确。

在你的配置xml

            <globaldiscount>
                <class>winints/globaldiscount</class>
                <before>subtotal</before>
            </globaldiscount>

更改标签之前的to和值应为&#34; grand_total&#34;

<after>grand_total</after>

如果您在小计之前或之后放置,您的折扣将不会注意总计,因为总计是最后计算的。

因此,您的代码可能会计算小计但不会计算总计,这可能会给paypal一个不准确的估算值