Magento Authorize.net Direct Post 未清空购物车(未将报价设置为无效)

Magento Authorize.net Direct Post not emptying cart (not setting quote as inactive)

在我正在构建的使用 Authorize.net 直接 Post 作为付款方式的网站中,我 运行 遇到了一个问题,即成功完成订单后购物车不会被停用.在 Mage_Authorizenet_Model_Directpost 中,我能够确认报价在第 574 行作为订单授权步骤的一部分被停用。

Mage::getModel('sales/quote')
    ->load($order->getQuoteId())
    ->setIsActive(false)
    ->save();

但是,在 directpost.js 中,当 Authorize.net 加载 IFrame 并调用 returnQuote 函数时,它会重定向到 Mage_Authorizenet_Directpost_PaymentController 的 returnQuoteAction 调用 _returnCustomerQuote 函数。

if ($order->getId()) {
            $quote = Mage::getModel('sales/quote')
                ->load($order->getQuoteId());
            if ($quote->getId()) {
                $quote->setIsActive(1)
                    ->setReservedOrderId(NULL)
                    ->save();
                $this->_getCheckout()->replaceQuote($quote);
            }
            $this->_getDirectPostSession()->removeCheckoutOrderIncrementId($incrementId);
            $this->_getDirectPostSession()->unsetData('quote_id');
            if ($cancelOrder) {
                $order->registerCancellation($errorMsg)->save();
            }
        }

请注意报价再次被设置为有效。除非取消订单,否则我不知道他们为什么这样做。我在想,也许我在这里的逻辑中遗漏了一些东西。我们已经完成了一些单页结帐定制和一些对实际订单提交的定制,但我没有看到任何会影响它的东西。 Magento 是否期望报价稍后会在调用链中被禁用?我很难调试它,因为我无法单步执行代码,因为 Authorize.net Direct Post 不会将响应中继回我的本地。

感谢您提供的任何帮助。

据我所知,如果来自 Authorize.net 的请求参数包含错误消息,看起来 _returnCustomerQuote 可能会被调用,即使它是成功的。这是来自 Mage_Authorizenet_Directpost_PaymentController

的 redirectAction
    if (!empty($redirectParams['success'])
        && isset($redirectParams['x_invoice_num'])
        && isset($redirectParams['controller_action_name'])
    ) {
        $this->_getDirectPostSession()->unsetData('quote_id');
        $params['redirect_parent'] = Mage::helper('authorizenet')->getSuccessOrderUrl($redirectParams);
    }
    if (!empty($redirectParams['error_msg'])) {
        $cancelOrder = empty($redirectParams['x_invoice_num']);
        $this->_returnCustomerQuote($cancelOrder, $redirectParams['error_msg']);
    }

但是,在我的情况下,我可以通过查看 access.log [组合] 判断有一个条目来自 /checkout/onepage/authorizenet/directpost_payment/returnQuote

在扯了一会儿头发并研究了代码并做了一些研究之后,我觉得这可能只是绑定到 directpost.js.[=15= 中的 onLoadIframe 的 loadIframe 函数中的一个错误。 ]

     loadIframe : function() {
        if (this.paymentRequestSent) {
            switch (this.controller) {
                case 'onepage':
                    this.paymentRequestSent = false;
                    if (!this.hasError) {
                        this.returnQuote();
                    }
                    break;
                case 'sales_order_edit':
                case 'sales_order_create':
                    if (!this.orderRequestSent) {
                        this.paymentRequestSent = false;
                        if (!this.hasError) {
                            this.returnQuote();
                        } else {
                            this.changeInputOptions('disabled', false);
                            toggleSelectsUnderBlock($('loading-mask'), true);
                            $('loading-mask').hide();
                            enableElements('save');
                        }
                    }
                    break;
            }
            if (this.tmpForm) {
                document.body.removeChild(this.tmpForm);
            }
        }
    },

在我看来,它正在检查重定向操作填充 iframe 时是否发送了付款请求。如果发送了付款请求,如果它使用的是单页控制器,并且如果响应中没有错误,那么 return 报价,因此保持活动状态并且项目保留在购物车中...

这对我来说没有意义,所以我删除了 this.hasError 中的爆炸。现在下单后购物车清空了,我好像没有其他问题了

现在看起来像这样,我很想有人告诉我我错了(严重)。

loadIframe : function() {
    if (this.paymentRequestSent) {
        switch (this.controller) {
            case 'onepage':
                this.paymentRequestSent = false;
                if (this.hasError) {
                    this.returnQuote();
                }
                break;
            case 'sales_order_edit':
            case 'sales_order_create':
                if (!this.orderRequestSent) {
                    this.paymentRequestSent = false;
                    if (!this.hasError) {
                        this.returnQuote();
                    } else {
                        this.changeInputOptions('disabled', false);
                        toggleSelectsUnderBlock($('loading-mask'), true);
                        $('loading-mask').hide();
                        enableElements('save');
                    }
                }
                break;
        }
        if (this.tmpForm) {
            document.body.removeChild(this.tmpForm);
        }
    }
},

在 'sales_order_create' 控制器的情况下似乎是这样,但我现在暂时不考虑 Magento。