明天一切美好 2022-05-05 14:22 采纳率: 33.3%
浏览 175
已结题

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

问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
<?php
class Gw_Commonn_Model_Sales_Quote_Address_Total_Card extends Mage_Sales_Model_Quote_Address_Total_Abstract{
    protected $_code = 'card';
    protected $_money = 0;
    protected $_base_money = 0;
    protected $_point = '';
    //protected $_product_id = 0;
    protected $_set = 1;

    public function collect(Mage_Sales_Model_Quote_Address $address)
    {
        parent::collect($address);
        $this->_setAmount(0);
        $this->_setBaseAmount(0);
        $items = $this->_getAddressItems($address);
        if (!count($items)) {
            return $this; //this makes only address type shipping to come through
        }
        $quote = $address->getQuote();
        $this->getAllProductId($quote);
        if ($this->_set) {
            $this->getPointValue();
        }
        $address->setFeeAmount($this->_money);
        $address->setBaseFeeAmount($this->_base_money);
        $address->setPointCode($this->_point);
        $quote->setFeeAmount($this->_money);
        $quote->setBaseFeeAmount($this->_base_money);
        $quote->setPointCode($this->_point);
        $address->setGrandTotal($address->getGrandTotal() - $address->getFeeAmount());
        $address->setBaseGrandTotal($address->getBaseGrandTotal() - $address->getBaseFeeAmount());
        return;
    }
 
    public function fetch(Mage_Sales_Model_Quote_Address $address)
    {
        if ($this->_point) {
            $address->addTotal(array(
                'code'=> $this->getCode(),
                'title'=> 'gift card ('. $this->_point .')',
                'value'=> - $this->_money / 2
            ));
        }
        return $this;
    }

    /**
     * 获取积分金额
     */
    public function getPointValue()
    {
        $customer_id = Mage::getSingleton("customer/session")->getCustomer()->getId();
        $data = Mage::getModel('rewardpoints/discountgift')->getCollection()
            ->addFieldToFilter('customer_id', $customer_id)
            ->addFieldToFilter('type', MW_RewardPoints_Model_Discountgift::POINT)//
            ->addFieldToFilter('used', 1)//未使用
            ->addFieldToFilter('style', 1)
            ->setOrder('value', 'DESC')
            ->getData();
        if ($data) {
            $_money = Mage::helper('directory')->currencyConvert(
                $data[0]['value'],
                'USD',
                Mage::app()->getStore()->getCurrentCurrencyCode()
            );
            $this->_money = number_format($_money, 2);
            $this->_base_money = number_format($data[0]['value'], 2);
            $this->_point = $data[0]['code'];
            //$this->_product_id = $data[0]['product_id'];
        }
    }

    /**
     * 判断商品是否在当前购物车中
     * @param $products
     */
    public function getProduct($quote)
    {
        $items = $quote->getAllItems();
        $products = [];
        foreach($items as $item) {
            array_push($products, $item->getProductId());
        }
        if (!empty($this->_product_id) && !in_array($this->_product_id, $products)) {
            $this->_money = 0;
            $this->_point = '';
            $this->_base_money = 0;
        }
    }

    /**
     * 获取最大金额的产品
     * @param $quote
     * @throws Mage_Core_Model_Store_Exception
     */
    public function getAllProductId($quote)
    {
        $items = $quote->getAllItems();
        $products = [];
        foreach($items as $item) {
            array_push($products, $item->getProductId());
        }
        $customer_id = Mage::getSingleton("customer/session")->getCustomer()->getId();
        $data = Mage::getModel('rewardpoints/discountgift')->getCollection()
            ->addFieldToFilter('customer_id', $customer_id)
            ->addFieldToFilter('type', MW_RewardPoints_Model_Discountgift::POINT)//
            ->addFieldToFilter('product_id', array('in' => $products))//
            ->addFieldToFilter('used', 1)//未使用
            ->addFieldToFilter('style', 2)
            ->setOrder('value', 'DESC')
            ->getData();
        if ($data) {
           $_money = Mage::helper('directory')->currencyConvert(
                $data[0]['value'],
                'USD',
                Mage::app()->getStore()->getCurrentCurrencyCode()
            );
            $this->_money = number_format($_money, 2);
            $this->_base_money = number_format($data[0]['value'], 2);
            $this->_point = $data[0]['code'];
            //$this->_product_id = $data[0]['product_id'];
            $this->_set = 0;
        }
    }

}


<!--自定义 费用展示的-->
        <sales>
            <quote>
                <totals>
                    <card>
                        <class>commonn/sales_quote_address_total_card</class>
                        <before>subtotal</before>
                        <after>grand_total</after>
                    </card>
                </totals>
            </quote>
       </sales>


运行结果及报错内容

paypal购物车金额和订单金额不匹配。
但是把 $address->setBaseGrandTotal($address->getBaseGrandTotal() - $address->getBaseFeeAmount());注释掉就好了,关键是setBaseGrandTotal不能注释掉

我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答

4条回答 默认 最新

  • 一起随缘 2022-05-05 15:32
    关注

    看下如图所示括号中的赋值是否正确

    img

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 5月9日
  • 赞助了问题酬金10元 5月5日
  • 赞助了问题酬金10元 5月5日
  • 赞助了问题酬金5元 5月5日
  • 展开全部

悬赏问题

  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码