Magento Forum

How do I display error / success messages after redirect
 
aiva
Jr. Member
 
Total Posts:  17
Joined:  2009-02-04
 

I have a custom module that redirects to a cart. I need it to display a message when the user arrives in the cart. Now i’ve tried this in my module’s controller:

Mage::getSingleton('checkout/session')->addError("Payment canceled");
$this->_redirect('checkout/cart');

..and as you might have guessed, it doesn’t work. The redirect works, but no message is displayed. Can it be done this way - with a redirect at all and what am I missing then?

Cheers

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ashley
Member
 
Total Posts:  51
Joined:  2008-07-23
 

Try this,

Mage::getSingleton('checkout/session')->addError(Mage::helper('checkout')->__("Payment Cancelled"));

I havn’t tested it, but am working on a very similair thing at the moment in a custom checkout and essentially I use:

$this->getCheckoutSession()->addError(Mage::helper('checkout')->__($error));

Regards
Ashley

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ashley
Member
 
Total Posts:  51
Joined:  2008-07-23
 

You could also try this which I found in the Cart.php file

$this->getCheckoutSession()->setRedirectUrl($product->getProductUrl());
$this->getCheckoutSession()->setUseNotice(true);
Mage::throwException($result);

This has a redirect but also tells the checkout that there are error messages

 
Magento Community Magento Community
Magento Community
Magento Community
 
aiva
Jr. Member
 
Total Posts:  17
Joined:  2009-02-04
 

Thanks for the suggestions Ashley but neither of them seem to work for me.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nidus
Jr. Member
 
Total Posts:  1
Joined:  2009-08-12
 

<div id="messages_product_view">
<?php Mage::app()->getLayout()->getMessagesBlock()->setMessages(Mage::getSingleton('customer/session')->getMessages(true));
echo $this->getMessagesBlock()->getGroupedHtml(); ?>
</div>
that is all folks

 
Magento Community Magento Community
Magento Community
Magento Community
 
zmove
Guru
 
Total Posts:  317
Joined:  2008-04-30
 

Hello,

nidus, where is your message in the code you give ? When can I put my custom message string?

 
Magento Community Magento Community
Magento Community
Magento Community
 
arne-s
Member
 
Total Posts:  59
Joined:  2010-07-18
 

The solution is simple, before doing the redirect, use session_write_close();

you would have thought that the magento redirect functions would take care of this, but apparently not

 
Magento Community Magento Community
Magento Community
Magento Community
 
Nitroware
Jr. Member
 
Total Posts:  20
Joined:  2010-01-22
 

It is a combination of all your answers.  This works for me from just about any block:

//A Success Message
        Mage::getSingleton('checkout/session')->addSuccess("Your cart has been updated successfully!");

        
//A Error Message
        
Mage::getSingleton('checkout/session')->addError("Your cart has been updated successfully!");

        
//A Info Message (See link below)
        
Mage::getSingleton('checkout/session')->addNotice("This is just a FYI message...");

        
//These two lines are required to get it to work
        
session_write_close(); //THIS LINE IS VERY IMPORTANT!
        
$this->_redirect('checkout/cart');

Credit due to posts above and:

http://www.deepcodeonline.com/blog/magento/how-to-display-error-success-and-notice-messages-in-magento/

 
Magento Community Magento Community
Magento Community
Magento Community
 
cherylfoster
Jr. Member
 
Total Posts:  3
Joined:  2010-12-23
 

The short answer is that you must use the validation class to validate individual fields. You will end up with a validation program for each entry. Flex inputs have built in error message screen and highlight invalid entries to display.

 
Magento Community Magento Community
Magento Community
Magento Community
 
emankady
Jr. Member
 
Total Posts:  1
Joined:  2012-01-14
 
nidus - 30 December 2009 07:09 AM

<div id="messages_product_view">
<?php Mage::app()->getLayout()->getMessagesBlock()->setMessages(Mage::getSingleton('customer/session')->getMessages(true));
echo $this->getMessagesBlock()->getGroupedHtml(); ?>
</div>
that is all folks

Thumps up

 
Magento Community Magento Community
Magento Community
Magento Community
 
Apptha_Team
Jr. Member
 
Total Posts:  11
Joined:  2013-08-19
 

You can try this coding to display error / success messages after redirect

For Frontend
Success Message:
Mage::getSingleton(\\\\\\\’core/session\\\\\\\’)->addSuccess(\\\\\\\’Your Success Message\\\\\\\’);

Error Message :
Mage::getSingleton(\\\\\\\’core/session\\\\\\\’)->addError(\\\\\\\’Your Error Message\\\\\\\’);

For Backend
Success Message:
Mage::getSingleton(\\\\\\\’adminhtml/session\\\\\\\’)->addSuccess(\\\\\\\’Your Success Message\\\\\\\’);

Error Message :
Mage::getSingleton(\\\\\\\’adminhtml/session\\\\\\\’)->addError(\\\\\\\’Your Error Message\\\\\\\’);

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top