-2

I have form and button coupon code in onepage checkout But when i apply coupon code, it always redirect to checkout/cart. -I want to redirect page to checkout/onepage after apply coupon code -I try change function _goBack() in CartController() like this :

protected function _goBack()
{
$this->_redirect('checkout/onepage');
return $this;
}

It works but doesn't show message block if correct or fail code, if i go any another page, it display this message. I try add getMessagesBlock()->toHtml() ?> to template but it don't show Pls help me

  • where you added the message??? – Asish Hira Apr 28 '16 at 8:03
  • i added it to template checkout/onepage.phtml – Khuebt Apr 28 '16 at 8:13
0

Add this message code on your function

$message = 'Error Message';
Mage::getSingleton('core/session')->addError($message);
Show Success message in frontend

$message = 'Success Message';
Mage::getSingleton('core/session')->addSuccess($message);

This will prepare your message and show it on frontend when you will redirect to any page.

Hope this will help you! Happy learning

0

Following explanations for Magento ver. 1.9.1.0:

In the couponPostAction() of the CartController.php the messages are added to the Mage::getSingleton('checkout/session') as you can see $this->_getSession()->addSuccess(.... This is the reason for which when the indexAction() of the CartController.php is called you can see:
$this->loadLayout() ->_initLayoutMessages('checkout/session') ->_initLayoutMessages('catalog/session') so the messages are rendered in the cart page.

In the checkout template (checkout/onepage.phtml), even if you put
getMessagesBlock()->toHtml() (or echo $this->getMessagesBlock()->getGroupedHtml() for my version of Magento) the block message is not displayed because the checkout/session messages are not initialized in the indexAction() of the OnepageController.php. Here, only the $this->_initLayoutMessages('customer/session'); is called.

Solution: you should also initialize checkout/session layout messages when the onepage checkout is being called.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.