Reputation: 31
I included a link named track your order
in footer. If user click this link without logged in, it should show error message like please login to track your order
.
I'm new to magento please guide me to do this.
Upvotes: 3
Views: 18455
Reputation: 11
Mage::getSingleton('core/session')->addSuccess('Success Message');
Mage::getSingleton('core/session')->addError('Error Message');
Mage::getSingleton('core/session')->addWarning('Warning Message');
Mage::getSingleton('core/session')->addNotice('Notice Message');
Upvotes: 0
Reputation: 864
- Set Your Message.
Mage::getSingleton("core/session")->addSuccess("Add success message");
Mage::getSingleton("core/session")->addError("Please login");
Mage::getSingleton("core/session")->addNotice("Add notification message");
- Display Your Message in Footer.
<?php echo $this->getChildHtml('global_messages'); ?>
3.Define Block in Layout. (Optional If use custom Extension Or not Defined)
<block type="core/messages" name="global_messages" as="global_messages"/>
Upvotes: 2
Reputation: 760
Added because this question appears in Google.
For a yellow "warning" message (the one you probably want for this purpose), use
Mage::getSingleton('core/session')->addNotice('Please log in to track your order');
For a green "success" message, use
Mage::getSingleton('core/session')->addSuccess('Tracking successful');
For a red "error" message, use
Mage::getSingleton('core/session')->addError('There was an error tracking your parcel');
Upvotes: 10
Reputation: 5193
put this code in your controller
$session = Mage::getSingleton('customer/session');
if (!$session->getCustomerId()) {
Mage::getSingleton('customer/session')->addError('You are not logged in');
}
Upvotes: 2
Reputation: 5381
you can use addError()
function to include your error message in session
Upvotes: 0