Php 如何以编程方式标记订单失败-Magento
我只想知道一个属性是什么,它在设置时会将订单标记为失败,以便调用Php 如何以编程方式标记订单失败-Magento,php,magento,Php,Magento,我只想知道一个属性是什么,它在设置时会将订单标记为失败,以便调用app/code/core/Mage/Checkout/controller/OnepageController.php的failureAction() 我有一个Observer.php,其中我正在为成功付款和失败付款创建发票,保存状态为pending\u payment的订单,并希望将它们重定向到购物车页面,顶部显示一条错误消息 所有这些都发生得很好。只是,对于未成功/失败的付款,除了保存具有待定付款状态的订单n将其重定向到购物车
app/code/core/Mage/Checkout/controller/OnepageController.php的failureAction()
我有一个Observer.php,其中我正在为成功付款和失败付款创建发票,保存状态为pending\u payment
的订单,并希望将它们重定向到购物车页面,顶部显示一条错误消息
所有这些都发生得很好。只是,对于未成功/失败的付款,除了保存具有待定付款状态的订单n将其重定向到购物车页面并显示错误消息外,我还希望保留/保存购物车,防止购物车变空
但是没有运气
Observer.php
public function implementOrderStatus($event)
{
$order = $event->getEvent()->getOrder();
if ($this->_getPaymentMethod($order) == 'mypaymentmodule')
{
$quote = Mage::getModel('sales/quote')->load($order->getQuoteId());
if($order->getPayment()->getCcTransId() == NULL)
{
$order->cancel();
$order->setStatus('canceled');
$order->save();
$quote->setIsActive(1)->save();
/*$state = 'pending_payment';
$status = 'pending_payment';
$comment = 'Payment transaction failed due to incorrect AVS/CVD details.';
$isNotified = false;
$order->setState($state,$status,$comment,$isNotified)->save();
$order->setCanSendNewEmailFlag(false);*/
Mage::getSingleton('checkout/session')->addError('Sorry, either of your card information (billing address or card validation digits) dint match. Please try again');
Mage::app()->getFrontController()->getResponse()->setRedirect('checkout/cart/')->sendResponse();
}
else
{
if ($order->canInvoice())
$this->_processOrderStatus($order);
}
}
return $this;
}
但是$quote->setIsActive(true)->save()
似乎没有奏效。关于如何在保存状态为“已取消”的订单后将购物车保存为空的任何帮助。您可能应该看看/app/code/core/Mage/Sales/Model/order.php
。在这里,您可以找到订单的几个常量,这些常量可用于设置订单的状态,如下所示:
<?php
// [...] all your code within your custom action or script
//load your order by order_id (or by increment_id, if you like to, here, it's your order id
$order = Mage::getModel('sales/order')->load($your_order_id);
$order->setState(Mage_Sales_Model_Order::STATE_CANCELED); //or whatever distinct order status you'd like
$order->save();
谢谢您的回复。我已经尝试了您建议的代码,但这并没有让我进入失败页面。我真正想做的是保存购物车,即$quote->setIsActive(true)->save()
,以避免购物车在失败/取消的订单上变空,这样客户就不必再次添加商品。有什么想法吗?观察者会听哪个事件?您可能可以通过发送一个标题将位置更改回购物车,从而通过它的异常处理。它的sales\u order\u place\u发生在事件之后。如果我抛出异常,我将无法保存状态为“待定付款”的订单。我会吗?我需要它,以便店主可以在后端看到每个失败的付款交易。
事件后的销售\订单\下订单\发出订单模型,因此您应该能够在抛出错误之前修改它,中止流程-如果这不起作用,您可以使用orderwriteMage_Sales_Model_Order::\u placePayment
来包含您自己的支票。我通过将参数true添加到此语句$Order->setState(Mage_Sales_Model_Order::STATE_Cancelled,true)来实现这一点//或者你想要的任何不同的订单状态