Magento2 – Shipping Method Not Rendering in Checkout

magento2shipping-methods

I am using Magento 2 version 2.1.8

In checkout step, we have the Flat Rate shipping method enabled & we added a simple product to cart.

We can see the Flat Rate method returned via AJAX but the method is not displayed in frontend. It is still "Sorry, no quotes are available…"

Check
enter image description here

How can I debug the issue on Magento 2?

Where is the code check the shipping methods to show ?

Best Answer

I finally figured out the issue.

The code to check the shipping method to show is in the template file vendor/magento/module-checkout/view/frontend/web/template/shipping.html

...
    <div class="checkout-shipping-method">
        <div class="step-title" data-bind="i18n: 'Shipping Methods'" data-role="title"></div>
        <!-- ko foreach: getRegion('before-shipping-method-form') -->
        <!-- ko template: getTemplate() --><!-- /ko -->
        <!-- /ko -->
        <div id="checkout-step-shipping_method"
             class="step-content"
             data-role="content"
             role="tabpanel"
             aria-hidden="false">
            <!-- ko if: rates().length  -->
            <form class="form methods-shipping" id="co-shipping-method-form" data-bind="submit: setShippingInformation" novalidate="novalidate">
                <div id="checkout-shipping-method-load">
...
            </form>
            <!-- /ko -->
            <!-- ko ifnot: rates().length > 0 --><div class="no-quotes-block"><!-- ko i18n: 'Sorry, no quotes are available for this order at this time'--><!-- /ko --></div><!-- /ko -->
        </div>
    </div>
...

Focus on the line

<!-- ko if: rates().length  -->

It checks whether or not we have any available rate. If we have any, it shows the shipping method with rates. If not then show No quotes block.

The available rates is getting from the view vendor/magento/module-checkout/view/frontend/web/js/view/shipping.js

...
            /**
             * Shipping Method View
             */
            rates: shippingService.getShippingRates(),
...

The logic Magento 2 to set shipping rates is beyond this single post, but you can check more details in

vendor/magento/module-checkout/view/frontend/web/js/model/shipping-rate-processor/new-address.js
vendor/magento/module-checkout/view/frontend/web/js/model/shipping-rate-processor/customer-address.js

Focus on lines related to

shippingService.setShippingRates(...)

For my case, there was an extension that overrides the shipping view of default Magento

vendor/magento/module-checkout/view/frontend/web/js/view/shipping.js
=>
it is overridden by another extension

And in the code of that extension, it checks one more condition to show only shipping methods it allows, so the default Flat Rate returned but it is not in the allowed shipping method, then nothing showed!

So post here for anybody has the same issue can have a light if face with a similar issue!

Related Topic