在我正在构建的使用 Authorize.net Direct 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 中的 onLoadIframe 绑定(bind)的 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 时是否发送了付款请求。如果发送了付款请求,如果使用的是 onepage Controller ,并且响应中没有错误,则返返回价,从而使其保持事件状态并且商品保留在购物车中...
这对我来说没有意义,所以我从 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” Controller 的情况下,但我暂时不考虑 Magento。
关于Magento Authorize.net Direct Post 未清空购物车(未将报价设置为非事件状态),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28112928/