3

I am using magento 1.8. I have custom theme. I am unable to get newsletter error/success messages when customer submit their email-id for subscription.

I have done many changes to get and print messages. But it won't work.

I am getting messages by below code

$messages = Mage::getSingleton('core/session')->getMessages(true);
    echo "<pre>"; var_dump($messages);

object(Mage_Core_Model_Message_Collection)#281 (2) {
  ["_messages":protected]=>
  array(0) {
  }
  ["_lastAddedMessage":protected]=>
  object(Mage_Core_Model_Message_Error)#120 (6) {
    ["_type":protected]=>
    string(5) "error"
    ["_code":protected]=>
    string(102) "Il y a eu un problème lors de l'inscription : This email address is already assigned to another user."
    ["_class":protected]=>
    string(0) ""
    ["_method":protected]=>
    string(0) ""
    ["_identifier":protected]=>
    NULL
    ["_isSticky":protected]=>
    bool(false)
  }
}

But I am unable to print it. I have tried below code.

   foreach($messages->getItems() as $message) {
        echo $message->getText();
}

Even I am not getting any thing in forloop. Help me,, Thanks in advance:)

8

You can print the messages in a template like this:

<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>

But there is a catch.
For example the newsletter subscription message is added to Mage::getSingleton('core/session').
So in order to see te core/session messages you need to add this in the controller that renders the template:

$this->_initLayoutMessages('core/session');

after calling

$this->loadLayout();
  • 1
    Wow, good to know, thanks! I always thought it is a core bug, that only core/session is rendered! :D – Fabian Blechschmidt Aug 21 '14 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.