我只想知道一个属性是什么,在设置时会将订单标记为失败,以便调用failureAction()
app/code/core/Mage/Checkout/controller/OnepageController.php
。
我有一个Observer.php,我在这里创建了成功付款的发票,以及有pending_payment
状态的失败付款保存订单,并希望将它们重定向到购物车页面,并在顶部显示错误消息。< / p>
这一切都很好。只是对于不成功/失败的付款,以及保存具有pending_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()
似乎没有做到这一点。有关如何在保存已取消状态的订单后保存我的购物车变空的任何帮助。
答案 0 :(得分:0)
你可能应该看看./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();
控制器操作中的failureAction
不执行任何操作,如果您想手动调用它,可以使用Mage::getUrl()
构建它的URL