Magento notification messages

when ever we create custom extention we need to show some user defined flash messages
this article help you, how messasing system works in magento and how we can use it for our custom work
Default Magento installation has a bunch of notification messages that get outputted to the browser
It is something every theme and/or extension developer should know about. This notification system uses exactly four different message types. These are: notice, success, error, warning.
Messages are stored on a session model.
1. ‘core/session’
2. ‘adminhtml/session’
3. ‘customer/session’
4. ‘catalog/session’
5. ‘catalogsearch/session’
6. ‘checkout/session’
7. ‘connect/session’
8. ‘install/session’
9. ‘tag/session’
10. ‘wishlist/session’
Each of these session models is capable of accepting those four types of messages by method call like shown on the example below.

Once you add a message to the session model, it will get rendered on the front-end on the next page that gets loaded.
Notice how warning messages are not styled at all, so you might want to give it a slight touch of styling if you are doing a custom theme development, just in case someone decides to throw something in them. Below is an example of HTML that gets outputted in browser for the messages.

Once the messages are rendered, they are cleared from session model. This is important to keep in mind, as it tells you basically that it makes no sense to do a message adding within theme (.phtml) files.
Proper way is to add messages through your controller actions, or even block and model classes. You can do a quick search for string “session’)->add” across entire Magento, this will give you a list of all notification messages Magento uses.
The order at which these messages appear on the store frontend and entire HTML output are defined in Mage_Core_Block_Messages class within getGroupedHtml() method, so there is no theme .phtml file you can edit to change the sort order.
This should give you enough insight in order to stay on top with Magento notification messages.

Leave a Comment

Your email address will not be published. Required fields are marked *

*