I've got a magento store that is working perfectly fine. But the only issue is that Error messages are not displaying where they suppose to be displayed.

For example the message displayed on the screenshot was supposed to be displayed on the onestepcheckout. But instead it is displayed on the homepage.

the main message that i'm concern with is the vat id error message:

on core i have found the public function of one of the messages that i want to place on a right page. currently the message "The VAT ID entered (%s) is not a valid VAT ID" is displayed on a wrong page. it suppose to display on onestepcheckout page:

public function getVatValidationUserMessage($customerAddress, $customerGroupAutoAssignDisabled, $validationResult)
    $message = '';
    $isError = true;
    $customerVatClass = $this->getCustomerVatClass($customerAddress->getCountryId(), $validationResult);
    $groupAutoAssignDisabled = Mage::getStoreConfigFlag(self::XML_PATH_CUSTOMER_VIV_GROUP_AUTO_ASSIGN);

    $willChargeTaxMessage    = $this->__('You will be charged tax.');
    $willNotChargeTaxMessage = $this->__('You will not be charged tax.');

    if ($validationResult->getIsValid()) {
        $message = $this->__('Your VAT ID was successfully validated.');
        $isError = false;

        if (!$groupAutoAssignDisabled && !$customerGroupAutoAssignDisabled) {
            $message .= ' ' . ($customerVatClass == self::VAT_CLASS_DOMESTIC
                ? $willChargeTaxMessage
                : $willNotChargeTaxMessage);
    } else if ($validationResult->getRequestSuccess()) {
        $message = sprintf(
            $this->__('The VAT ID entered (%s) is not a valid VAT ID.') . ' ',
        if (!$groupAutoAssignDisabled && !$customerGroupAutoAssignDisabled) {
            $message .= $willChargeTaxMessage;
    else {
        $contactUsMessage = sprintf($this->__('If you believe this is an error, please contact us at %s'),

        $message = $this->__('Your Tax ID cannot be validated.') . ' '
            . (!$groupAutoAssignDisabled && !$customerGroupAutoAssignDisabled
                ? $willChargeTaxMessage . ' ' : '')
            . $contactUsMessage;

    $validationMessageEnvelope = new Varien_Object();

    return $validationMessageEnvelope;

The message that you have noted in your question is dealt with on the customer_address_save_after event. Once the function as been called the message is simply added to the customer session as either a success or an error message.

if (!$validationMessage->getIsError()) {
} else {

Now these customer session messages can appear on pages that has one of the following blocks on it.

<block type="core/messages" name="global_messages" as="global_messages"/>
<block type="core/messages" name="messages" as="messages"/>

So if the user saves an address in the checkout the message is not guaranteed to display on the checkout page, as the complete page is not reloaded only the next section of the one page checkout. So the next page a user sees that could contain these messages could be the homepage.

  • I'm currently trying to move the validation message so it will appear on first loading of checkout/onepage. I've already manage to do that by editing public function getCustomerVatClass, but Magento now's adding message each step in Checkout, so after placing order we're ending up with 7 messages in sessions (duplicated with same content). Can you point some place where the validationMessage could be saved into sessions so it's displayed right after getting into checkout or after logging in?
    – versedi
    Oct 16 '14 at 11:27

It is a bug in Magento that the same message appears several times on the homepage/checkout page.

I did rewrite the addMessage method on my own module, so it checks if the message did not exist yet.

 * @author: ..
 * This class overrides the addMessage for customer.
 * Because when BTW is validated, a message appears multiple times.
 * With this rewrite we check if the message is not already added.
class MYMODULE_Customer_Model_Session extends Mage_Customer_Model_Session
     * Adding new message to message collection
     * @param   Mage_Core_Model_Message_Abstract $message
     * @return  Mage_Core_Model_Session_Abstract
    public function addMessage(Mage_Core_Model_Message_Abstract $message)
        // get all current messages
        $sessionMessages = $this->getMessages()->getItems();
        // loop thrue messages and find message with same text
        $found = false;
        foreach($sessionMessages as $sessionMessage) {
            if ( $sessionMessage->getCode() == $message->getCode() ) {
                $found = true; // found message with same text
        if ( !$found ) { // only add message if not already in session
        return $this;

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.