Redirect in CheckOut

901 views Asked by At

I currently work on a magento payment module which has to check if certain fields in a users profile/account are set.

If they do not exist/have no content, I want to either 1. redirect to /customer/account/edit/ 2. display a notice that the fields in question has to be filled

or the other way around.

This is initialized by an AJAX call from Magentos core OnePage Checkout.

I tried several things like

Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account/edit/'));
    Mage::app()->getResponse()->sendResponse();
    exit;

and other things.

From the observer I somehow get a redirect but always end at /default/checkout/cart (which is default?)

In the model I see in chromes network tab that the correct page gets loaded but somehow it wont redirect to the page.No redirect but loaded to dev tools

Please let me know if you need more Infos on the problem.

Edit 1: got rid of the second Mage::getURL, still no redirect.

Edit 2: I guess that if I could somehow 'hijack' the response for opcheckout.js it could do the redirect. Or should I maybe just add an extra js which listens as well? I think because the hole thing is triggered by an AJAX call the redirect just doesn't take place at the correct place. More ideas are welcome.

Edit 3: I try to figure at the moment out how to build a response fo the mentioned opcheckout.js which does not trigger the next step but does trigger redirect

1

There are 1 answers

0
Daniel Böttner On BEST ANSWER

Solved it

Solution:

Create an an Override for

  • /app/code/core/Mage/Checkout/controllers/OnepageController.php

This should be for example

  • app/code/local/{NameSpace}/{ModuleName}/controllers/OnepageController.php

Pay special attention to the "s" the folder is plural not singular. Took me ten minutes to see why my controller was not working.

The controller should be build like this:

require_once Mage::getModuleDir('controllers', "Mage_Checkout").DS."OnepageController.php";
    class MOOD_BonimaScoreIdent_OnepageController extends Mage_Checkout_OnepageController {
       public function indexAction(){
            parent::indexAction();
       }

       public function savePaymentAction(){
         //just an example
        $result['redirect']=Mage::getUrl('customer/account/edit/');
        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
       return;
       }
    }

The config.xml part to include the controller override is simply:

<frontend>
<routers>
                <checkout>
                    <args>
                        <modules>
                            <MyModuleName before="Mage_Checkout">Namespace_MyModuleName</MyModuleName>
                        </modules>
                    </args>
                </checkout>
        </routers
</frontend>