0

i have a check in the checkout which spits out an error when you go to submit however the only way to fix the error is to go back into the cart and adjust what you have in it, currently i use this code in [MODULE]\Model\Giftcard.php

Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('checkout/cart'))->sendResponse();
Mage::throwException("Gift Card is not currently active", 'core/session');

what happens is that i get the error message but it doesn't redirect back to the cart

does anyone know what i'm doing wrong here

5
  • Do I understand you right? You don't need an exception to be thrown but redirect visitor to cart and display a message there?
    – user487772
    Oct 15 '13 at 6:20
  • @Tim yeh, the exception was originally there and before i added the redirect line when i commented the exception line the error didn't appear
    – Memor-X
    Oct 15 '13 at 21:33
  • Did you find a solution for the issue?
    – Sander Mangel
    Oct 17 '13 at 7:20
  • @SanderMangel oh yeh sorry, i was for sure that i had marked it, after i used your code it worked fine
    – Memor-X
    Oct 17 '13 at 20:58
  • No problem, just wanted to know if you needed any more help
    – Sander Mangel
    Oct 17 '13 at 21:15
5

When you throw an error right after the code for redirecting the execution will halt on the error thrown and that's it.

If you want to show an error to the user please use the session message stack.

Mage::getSingleton('checkout/session')->addError("Gift Card is not currently active");
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('checkout/cart'))->sendResponse();
2

You can also try this in [MODULE]\Model\Giftcard.php:

$redirectUrl= Mage::getUrl('checkout/cart');
Mage::getSingleton('checkout/session')->setRedirectUrl($redirectUrl);  

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.