1

我只想知道一个属性是什么,当它设置时会将订单标记为失败,以便failureAction()app/code/core/Mage/Checkout/controller/OnepageController.php调用。

我有一个 Observer.php,其中我正在为成功付款创建发票,并为失败的付款保存订单pending_payment状态并希望将它们重定向到购物车页面,并在顶部显示错误消息。

这一切都很好。只是对于不成功/失败的付款,以及使用pending_payment 状态保存订单n 将它们重定向到带有错误消息的购物车页面,我还想保留/保存购物车免于变空。

但没有运气

观察者.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()似乎没有奏效。任何有关如何在保存“已取消”状态的订单后避免购物车变空的帮助。

4

1 回答 1

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控制器操作中没有任何作用,如果你想手动调用它,你可以使用它构建它的 urlMage::getUrl()

于 2012-05-24T20:54:25.787 回答