1

I have a save address function in my checkout and after the validation in the controller takes place if there is an error the following gets rendered.

if(isset($result['error']) && $result['error']){

    foreach($result['message'] as $msg){

        Mage::getSingleton('checkout/session')->addError($msg);                     
        $this->_message[] = $msg;
    }

    return $this->_redirectUrl($this->_getRefererUrl());
}

The referrer is a method belonging to the same controller so I assumed setting the variable $this->_message would mean I can access the message from the referrer method but it seems as though the class gets re-instantiated because if I do a var_dump($this->_message); in the referrer method it is null. I know there are messages getting set because if I don't redirect back to the referrer Mage::getSingleton('checkout/session')->addError($msg); works - aka it displays which fields need to be filled in on the form.

How can I make the messages available to the referrer method?

0

I've added them to an array and stored this in the session like so

if(isset($result['error']) && $result['error']){

    foreach($result['message'] as $msg){

        Mage::getSingleton('checkout/session')->addError($msg);
        $this->_message[] = $msg;
    }
            Mage::getSingleton( 'customer/session' )->setData( 'validationMessages', $this->_message);
            return $this->_redirectUrl($this->_getRefererUrl());
}

But using session variables isn't my desired solution so any other answers still very welcome!

0

If you are redirecting from one page to another page then storing message in session is the best solution.

If your referrer url is not from the checkout steps, then setting error message in checkout/session will not display message. so in that case, either store message in customer/session or using core/session would be better solution.

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.