The success/notice/error messages like this are actually stored in the session, you don't output them directly with an echo (you shouldn't be adding an echo into a controller at all). Not sure if your core code has been altered (which you never need to do), but the section of core you are referring to should be something more along the lines of:
if (!$this->_getSession()->getNoCartRedirect(true)) {
if (!$cart->getQuote()->getHasError()) {
$message = $this->__('%s was updated in your shopping cart.', Mage::helper('core')->escapeHtml($item->getProduct()->getName()));
$this->_getSession()->addSuccess($message);
}
$this->_goBack();
}
In your original code you are missing a key element, the line $this->_getSession()->addSuccess($message);
. This is the line which adds the success message to the section. You will commonly also see this happen in the following format:
Mage::getSingleton('customer/session')->addSuccess('Some success message');
After this, just as importantly you have $this->_goBack();
which redirects the request so the message can be pulled from the session and rendered out in the next request.
Whilst you can add a success/notice/error message to the session at any point, all of the work to enable the message to be displayed is done in the controller after loading the layout by a call to the method _initLayoutMessages()
:
$this->loadLayout()
$this->_initLayoutMessages('customer/session');
$this->renderLayout();
Note that there are a fair few different options for which session namespace to add the message into, with customer/session
being just one. The full list (of frontend namespaces) is as follows:
catalog/session
checkout/session
catalogsearch/session
customer/session
paypal/session
review/session
tag/session'
wishlist/session
core/session
If you add a message into a particular session namespace, the same namespace must be passed as and argument when calling _initLayoutMessages()
in order for that message to be rendered out (with the exception of core/session
which is always rendered out). You can also pass multiple session namespaces as an array:
$this->_initLayoutMessages(array('catalog/session', 'customer/session'));
As long as you add a message into the session before the call to _initLayoutMessages()
then it will be displayed when the page renders and the global_messages
/messages
block is built, but because you are often not going to be able to make a decision about whether a message should be added before the call to _initLayoutMessages()
, this is the reason why you normally redirect the request at some point after adding the message so that the next request can render the message when it calls _initLayoutMessages()
.
So the flow is as follows
- Request reaches controller
- Layout is loaded, messages are initialised, layout is rendered
- Some logic is run which determines a message needs to be displayed
- Message is added to the session
- Request is redirected to some controller action
- Request reaches controller
- Layout is loaded, messages are initialised, layout is rendered
- Message added in previous request is displayed.
In your particular application all you need to do is alter the message added to the session and then either ensure this has been done before the call to _initLayoutMessages()
, or ensure you add in a redirect so that the message renders in the next request - if you are changing the message where I think you are, you'll need a redirect. So just append the extra text you need to the $message
variable:
$message = $this->__('%s was updated in your shopping cart. Some new text.', Mage::helper('core')->escapeHtml($item->getProduct()->getName()));
A side note, if you need to make the change in Mage_Checkout_CartController
you should be rewriting this class not changing the core class directly.