Question

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

Was it helpful?

Solution

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();

OTHER TIPS

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

$redirectUrl= Mage::getUrl('checkout/cart');
Mage::getSingleton('checkout/session')->setRedirectUrl($redirectUrl);  
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top