2

How to avoid repetition of same message at addError()/addSuccess().

Example:

public function a(){
Mage::getSingleton('core/session')->addError("Custom Error");
}


public function b(){
Mage::getSingleton('core/session')->addError("Custom Error");
}

In some cases I call both function a() and function b().
I don't want both error message at a time.

  • You should give more details about your issue. This is very unclear. – Marius Sep 22 '14 at 9:25
3

You can use the addUniqueMessages method from the session.
But the problem is that you have to pass as parameter an instance of Mage_Core_Model_Message_Abstract or an array with instances of the same class.
So your code should look like this:

public function a(){
    $message = Mage::getModel('core/message_error', 'Custom Error');
    Mage::getSingleton('core/session')->addUniqueMessages($message);
}


public function b(){
    $message = Mage::getModel('core/message_error', 'Custom Error');
    Mage::getSingleton('core/session')->addUniqueMessages($message);
}

The example above is for error messages. but it works for other types:

core/message_success, core/message_notice, core/message_warning

0

Admin

$message = Mage::getModel('core/message_error', $message);
Mage::getSingleton('adminhtml/session_quote')->addUniqueMessages($message);

Front End

$message = Mage::getModel('core/message_error', 'Custom Error');
Mage::getSingleton('core/session')->addUniqueMessages($message);

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.