How to skip onepage checkout shipping information?
-
16-10-2019 - |
Question
I have created a new option as pickup @ office
in onepage billing section instead of the other two options Ship to this address
Ship to different address
. If customer selects this pickup @ office
option he can use any address for the billing address. But the shipping address will be set progametically. I have done up to this step. What I want to do next is to directly move to the shipping methods
section by skipping shipping address
. For this is there a better way except overriding OnepageController.php.
Any suggestions will be appreciated. Thanks in advanced.
Solution
Finally this was the only solution I was able to find.
Need to override the controller Mage_Checkout_OnepageController
config.xml
<config>
. . . . . .
<global>
<rewrite>
<test_cart> <!--This can be any unique id -->
<from><![CDATA[#^/checkout/onepage/#]]></from> <!-- the URL which u want to override-->
<to>/mymodule/onepage/</to> <!-- destination url -->
</test_cart>
</rewrite>
. . . . .
</global>
. . . . . .
</config>
app\code\local\Mynamespace\Mymodule\controllers\OnepageController.php
<?php
require_once 'Mage/Checkout/controllers/OnepageController.php';
class Mynamespace_Mymodule_OnepageController extends Mage_Checkout_OnepageController
{
public function saveBillingAction()
{
if ($this->_expireAjax()) {
return;
}
if ($this->getRequest()->isPost()) {
// $postData = $this->getRequest()->getPost('billing', array());
// $data = $this->_filterPostData($postData);
$data = $this->getRequest()->getPost('billing', array());
$customerAddressId = $this->getRequest()->getPost('billing_address_id', false);
if (isset($data['email'])) {
$data['email'] = trim($data['email']);
}
$result = $this->getOnepage()->saveBilling($data, $customerAddressId);
if (!isset($result['error'])) {
/* check quote for virtual */
if ($this->getOnepage()->getQuote()->isVirtual()) {
$result['goto_section'] = 'payment';
$result['update_section'] = array(
'name' => 'payment-method',
'html' => $this->_getPaymentMethodsHtml()
);
} elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1) {
$result['goto_section'] = 'shipping_method';
$result['update_section'] = array(
'name' => 'shipping-method',
'html' => $this->_getShippingMethodsHtml()
);
$result['allow_sections'] = array('shipping');
$result['duplicateBillingInfo'] = 'true';
} else {
$result['goto_section'] = 'shipping_method'; // set the checkout step which you want to move
}
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
}
}