Jonathan Rooch
Jonathan Rooch

Reputation: 31

How to add Custom error message in magento

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

Answers (5)

richa mathur
richa mathur

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

Ketan Borada
Ketan Borada

Reputation: 864

  1. 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");
  1. 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

Markie
Markie

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

srgb
srgb

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

Mufaddal
Mufaddal

Reputation: 5381

you can use addError() function to include your error message in session

Upvotes: 0

Related Questions