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>
First, you need to update for config.xml like below, Change
<blocks>
<methods>
<rewrite>
<shipping_method>Emizentech_Restricteway_Checkout_Block_Onepage_Shipping_Method</shipping_method>
</rewrite>
</methods>
</blocks>
to
<blocks>
<restricteway>
<class>Emizentech_Restricteway_Block</class>
</restricteway>
<checkout>
<rewrite>
<onepage_shipping_method>Emizentech_Restricteway_Block_Checkout_Onepage_Shipping_Method</onepage_shipping_method>
</rewrite>
</checkout>
</blocks>
The block file Emizentech/Restricteway/Checkout/Block/Onepage/Shipping/Method.php you created is also wrong, You need to create Emizentech/Restricteway/Block/Checkout/Onepage/Shipping/Method.php file
Now in your file, add below code.
class Emizentech_Restricteway_Block_Checkout_Onepage_Shipping_Method extends Mage_Checkout_Block_Onepage_Shipping_Method
{
protected function _construct()
{
if(Mage::getModel('checkout/cart')->getQuote()->getGrandTotal() > 1100){
$this->getCheckout()->setStepData('shipping_method', array(
'label' => Mage::helper('checkout')->__('Unloading Method'),
'is_show' => $this->isShow()
));
}else{
$this->getCheckout()->setStepData('shipping_method', array(
'label' => Mage::helper('checkout')->__('Shipping Method'),
'is_show' => $this->isShow()
));
parent::_construct();
}
}
}
EDITS:
app\etc\modules\Emizentech_Restricteway.xml
<?xml version="1.0"?>
<config>
<modules>
<Emizentech_Restricteway>
<active>true</active>
<codePool>local</codePool>
<version>0.1.0</version>
</Emizentech_Restricteway>
</modules>
</config>
app\code\local\Emizentech\Restricteway\etc\config.xml
<?xml version="1.0"?>
<config>
<modules>
<Emizentech_Restricteway>
<version>0.1.0</version>
</Emizentech_Restricteway>
</modules>
<global>
<helpers>
<restricteway>
<class>Emizentech_Restricteway_Helper</class>
</restricteway>
</helpers>
<blocks>
<restricteway>
<class>Emizentech_Restricteway_Block</class>
</restricteway>
<checkout>
<rewrite>
<onepage_shipping_method>Emizentech_Restricteway_Block_Checkout_Onepage_Shipping_Method</onepage_shipping_method>
</rewrite>
</checkout>
</blocks>
</global>
</config>
app\code\local\Emizentech\Restricteway\Block\Checkout\Onepage\Shipping\Method.php
<?php
class Emizentech_Restricteway_Block_Checkout_Onepage_Shipping_Method extends Mage_Checkout_Block_Onepage_Shipping_Method
{
protected function _construct()
{
$cartGrandTotal = Mage::getModel('checkout/cart')->getQuote()->getGrandTotal();
$conditionOrderAmount = Mage::getStoreConfig('setting/setorder/order_amount');
if($cartGrandTotal > $conditionOrderAmount)
{
$this->getCheckout()->setStepData('shipping_method', array(
'label' => Mage::helper('checkout')->__('Unloading Method'),
'is_show' => $this->isShow()
));
}
else
{
$this->getCheckout()->setStepData('shipping_method', array(
'label' => Mage::helper('checkout')->__('Shipping Method 456'),
'is_show' => $this->isShow()
));
parent::_construct();
}
}
}
This code is working for me. Please check with your code.
Best Answer
Magento saves all checkout step data using AJAX.
Magento has a feature to go back to the cart page whenever an AJAX request goes to
onFailure
state during any of the checkout steps.An AJAX response calls the
onFailure() function whenever a header response is
HTTP/1.1 500 Internal Server Error`.Or use 403 (permission denied):
...Or 503 (service unavailable):
In your case you need to send a 500/403/503 header response code to ensure that the Prototype AJAX
onFailure
is called.saveShipping()
function saves shipping data using AJAX` and the response is the JSON content.On receipt of this response the checkout is going to move to the next step.
That means that
$this->_redirect('checkout/cart');
is not being run.