Magento – Redirect in OnePage Checkout during checkout in “Shipping Method” to shipping provider’s web (onepage)

checkoutonepage-checkoutredirectshippingshipping-methods

I'm using OnePage module checkout.

I created my shipping method module. If is my method selected, need to redirect to provider's web. Here customer choose closest place to his shipping address and then it's redirected back to checkout. What's the best way where to do redirection? In controller? Is is even possible (isn't it restricted just to "Payment methods")?

UPDATED:
There seems to be two ways:

  • Redirect just after "Shipping Method" section and to be returned back to OnePage by provider's web after choosing the place. This requires to hack skin/frontend/base/default/js/opcheckout.js and app/code/core/Mage/Checkout/controllers/OnepageController.php, because when it goes back to OnePage from providers's web, it needs to:
    1. Save new address (previously choosen in "Shipping" section.
    2. Jump jump to next section ("Payment method") – i.e. skip everything up to "Shipping Method".
  • Another option seems to be to hack OnepageController.php to do redirect at the beginning of successAction() method.

I also wanted to get inspiration from PayPal modules, which do redirect, but I wasn't succeed.

Best Answer

You can do this by Magento event observer functionality whenever magento predispatch a controller then trigger event controller_action_predispatch_youfullaction

Mage::dispatchEvent('controller_action_predispatch_' .
    this->getRequest()->getRouteName(), array('controller_action' => $this));

you need trigger an event when shipping method is select and click save button to goto next button you need event and redirect to third party from observer.

Here is an example that depends on Magento default

checkout onepage and trigger event on
controller_action_predispatch_checkout_onepage_saveShippingMethod
<frontend>
        <events>
            <controller_action_predispatch_checkout_onepage_saveShippingMethod>
                <observers>
                    <my_fire_events>
                        <class>magento38137/observer</class>
                        <method>myredirection</method>
                    </my_fire_events>
                </observers>
            </controller_action_predispatch_checkout_onepage_saveShippingMethod>
        </events>
</frontend>
Related Topic