3

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.

1
  • Why do you want to show this link to "not logged in" users in the first place? Commented May 29, 2012 at 8:59

5 Answers 5

10

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');
Sign up to request clarification or add additional context in comments.

Comments

2

put this code in your controller

$session = Mage::getSingleton('customer/session');
if (!$session->getCustomerId()) {
    Mage::getSingleton('customer/session')->addError('You are not logged in');
}

Comments

2
  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"/>

Comments

0

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

Comments

0
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');

1 Comment

Please explain your lines of code so other users can understand its functionality. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.