- Instead of you, I added the new custom step before and not after the Shipping Information step but I discovered the same behavior. Did you managed to solve it?
- It should be possible to use the
navigateTo(code, scrollToElement)
function of the Magento_Checkout/js/model/step-navigator
for this purpose.
- Actual the
next()
function of the step-navigator.js
is called in the setShippingInformation()
function of the Magento_Checkout/js/view/shipping.js
(which will be called by clicking the Next button).
- In order to override this function you can copy the whole
shipping.js
file to your custom module and add the following to your custom checkout_index_index.xml
.
checkout_index_index.xml
<item name="steps" xsi:type="array">
...
<item name="shipping-step" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shippingAddress" xsi:type="array">
<item name="component" xsi:type="string"><Vendor>_<ModuleName>/js/view/shipping</item>
</item>
</item>
</item>
...
</item>
If this does work, I suggest you to not override the whole shipping.js
file, but extending it, like itself extends the Magento_Ui/js/form/form
(Component
). Then you should be able to just override the setShippingInformation()
function.
Your Solution:
Step: 1
Override Controller: \app\code\local\Htech\Checkout\controllers\OnepageController.php
require_once Mage/Checkout/controllers/OnepageController.php';
class Htech_Checkout_OnepageController extends Mage_Checkout_OnepageController{
/**
* Save checkout billing address
*/
public function saveBillingAction()
{
if ($this->_expireAjax()) {
return;
}
if ($this->getRequest()->isPost()) {
$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'])) {
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';
}
}
$this->_prepareDataJSON($result);
}
}
}
Step: 2
Create Config file:\app\code\local\Htech\Checkout\etc\config.xml
Block: \app\code\local\Mage\Checkout\Block\Onepage\Abstract.php
Copy Abstract.php from core and change _getStepCodes()
method to following
protected function _getStepCodes()
{
return array('login', 'billing', 'shipping_method', 'payment', 'review');
}
Step: 3
Change Layout: \app\design\frontend\rwd\default\layout\checkout.xml
Remove/Comment All Block with shipping.phtml
file form checkout_onepage_index
and checkout_onepage_progress
i.e.
<block type="checkout/onepage_progress" name="shipping.progress" template="checkout/onepage/progress/shipping.phtml"></block>
<block type="checkout/onepage_shipping" name="checkout.onepage.shipping" as="shipping" template="checkout/onepage/shipping.phtml" />
<block type="checkout/onepage_progress" name="shipping.progress" template="checkout/onepage/progress/shipping.phtml"></block>
Step: 4
Template: \app\design\frontend\rwd\default\template\checkout\onepage.phtml
Add This code After <div class="step-title">....</div>
<div id="checkout-step-<?php echo $_stepId ?>" class="step a-item" style="display:none;">
<?php if($_stepId=='shipping_method'){ ?>
<?php echo $this->getLayout()->createBlock('checkout/onepage_shipping')->setTemplate('checkout/onepage/shipping.phtml')->toHtml(); ?>
<?php } ?>
<?php echo $this->getChildHtml($_stepId) ?>
</div>
If Some one have short mehtod for this then share.
Output:
Best Answer
Please have a look at this class
Magento\Quote\Model\Quote
in this class you have this method isVirtual() [image attached]
if the return result is true, Magento will skip the Shipping Step.
You can override this method or create a "after plugin" (recommended) to change the return value as you want
https://devdocs.magento.com/guides/v2.0/extension-dev-guide/plugins.html