Magento - 从控制器重定向到结帐成功页面不起作用

时间:2015-10-26 15:26:40

标签: php magento redirect

我到处都谷歌,但在保存订单后我没有得到任何帮助我想重定向到成功页面。我正在使用 我的支付控制器中有Mage_Core_Controller_Varien_Action :: _ redirect(' checkout / onepage / success',array(' _secure' => true))。这是我的代码。

    public function responseAction() 
      {
         $data = $this->getRequest()->getParams();
        if ($data['data']){
            $quoteObj = Mage::getModel('sales/quote')->load($data['data']);
            $quoteObj->assignCustomer(Mage::getSingleton('customer/session')->getCustomer());

            $quoteObj->collectTotals()->getPayment()->setMethod('payme');
            $quoteObj->collectTotals()->save();

            //Feed quote object into sales model
            $service = Mage::getModel('sales/service_quote', $quoteObj);        
            //submit all orders to MAGE
            $service->submitAll();
            //Setup order object and gather newly entered order
            $order = $service->getOrder();          
            //Now set newly entered order's status to complete so customers can enjoy their goods. 
            $order->setStatus('complete');
            //Finally we save our order after setting it's status to complete.
            $order->save();
            Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/success', array('_secure'=>true));

}

3 个答案:

答案 0 :(得分:0)

您的控制器正在扩展哪个类? /app/code/community/Phoenix/Moneybookers/controllers/ProcessingController.php /app/code/core/Mage/Paypal/controllers/StandardController.php 似乎是做一些类似于你想要完成的事情;看看他们的来源。它们都扩展了 Mage_Core_Controller_Front_Action 。尝试在控制器中扩展Mage_Core_Controller_Front_Action类并使用

  

$ this-> _redirect('checkout / onepage / success',array('_ secure'=> true));

而不是

  

Mage_Core_Controller_Varien_Action :: _ redirect('checkout / onepage / success',array('_ secure'=> true));

换句话说,不要将_redirect方法作为静态方法调用,而是从控制器本身调用。

答案 1 :(得分:0)

你可以试试Mage :: getUrl($ route,$ params);

答案 2 :(得分:0)

首先,您需要加载会话并设置一些必需的参数。否则,您将被重定向到购物车,如Mage_Checkout_OnepageController::successAction()

中所示

尝试

$session = Mage::getSingleton('checkout/type_onepage')->getCheckout();

$quoteId = $reorder->getQuote()->getId(); // just an example
$orderId = Mage::getModel("sales/order")->getCollection()->getLastItem()->getEntityId()
$incrementId = Mage::getModel("sales/order")->getCollection()->getLastItem()->getIncrementId();


$session->setLastSuccessQuoteId($quoteId);
$session->setLastQuoteId($quoteId);
$session->setLastOrderId($orderId); // Required, otherwise getOrderId() is empty on success.phtml
$session->setLastRealOrderId($incrementId);

// Now the redirect supposed to work
$this->_redirect('checkout/onepage/success', array('_secure'=>true));