Magento2: [2.0.7] Providing a new postalcode does not refresh shipping alternatives.

Created on 3 Jun 2016  Β·  15Comments  Β·  Source: magento/magento2

Magento: 2.0.7 + 2.1.0-RC2
Theme: Luma

Steps to reproduce

  1. Add a product to cart
  2. Go to checkout
  3. Try changing address fields one by one.

    Expected result

  4. The shipping alternatives should refresh when address related fields such as postalcode are changed. Meaning the ajax call to
    index.php/rest/default/V1/guest-carts/xxxxxxxxxxx/estimate-shipping-methods should be called when peple change delivery address fields such as postal code etc.

    Actual result

  5. Does not refresh shipping alternatives when changing the address related fields.

Checkout

Most helpful comment

Hi, I think this is not solved yet... (I'm using magento 2.2.2 CE edition)

I have followed the same as @peec has mentioned, but here, my custom shipping validations are not loading, and even the .js files aren't load in my page, I don't know why ...
look:
checkout_index_index.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
   <body>
      <referenceBlock name="checkout.root">
         <arguments>
                <argument name="jsLayout" xsi:type="array">
                    <item name="components" xsi:type="array">
                        <item name="checkout" xsi:type="array">
                            <item name="children" xsi:type="array">
                                <item name="steps" xsi:type="array">
                                    <item name="children" xsi:type="array">
                                        <item name="shipping-step" xsi:type="array">
                                            <item name="children" xsi:type="array">
                                                <item name="step-config" xsi:type="array">
                                                    <item name="children" xsi:type="array">
                                                        <item name="shipping-rates-validation" xsi:type="array">
                                                            <item name="children" xsi:type="array">
                                                                <item name="inchoo" xsi:type="array">
                                                                    <item name="component" xsi:type="string">Inchoo_Shipping/js/view/inchoo</item>
                                                                </item>
                                                            </item>
                                                        </item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

checkout_cart_index.xml:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="checkout.cart.shipping">
            <arguments>
                <argument name="jsLayout" xsi:type="array">
                    <item name="components" xsi:type="array">
                        <item name="summary-block-config" xsi:type="array">
                            <item name="children" xsi:type="array">
                                <item name="shipping-rates-validation" xsi:type="array">
                                    <item name="children" xsi:type="array">
                                        <item name="inchoo" xsi:type="array">
                                            <item name="component" xsi:type="string">Inchoo_Shipping/js/view/inchoo</item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

And Finally, my inchoo.js in Inchoo/Shipping/view/frontend/web/js/view/inchoo.js, with this content:

define([
    'uiComponent',
    'Magento_Checkout/js/model/shipping-rates-validator',
    'Magento_Checkout/js/model/shipping-rates-validation-rules',
    '../model/inchoo-validatior',
    '../model/inchoo-rules'
],function (
        Component,
        defaultShippingRatesValidator,
        defaultShippingRatesValidationRules,
        shippingRatesValidator,
        shippingRatesValidationRules
    ) {
        'use strict';
        defaultShippingRatesValidator.registerValidator('carrierName', shippingRatesValidator);
        defaultShippingRatesValidationRules.registerRules('carrierName', shippingRatesValidationRules);
        return Component;
    }
);

But when I'm at guest checkout page, I've noticed that inchoo.js file is not loaded. Any idea of why it occurs?
Thanks in advance.

All 15 comments

To help us investigate and reproduce your issue, please, follow to reporting guidelines.

Updated issue.

This should be called after shipping details are filled out:
index.php/rest/default/V1/guest-carts/xxxxxxxxxxx/estimate-shipping-methods

Its only called on initial load of Checkout.

@peec, do you have any errors in the browser console during checkout step? Could you also attach debug and exception Magento log?

Hi Guys,

Same problem here. It's happend when you has shipping method "flat rate" disabled. No errors in the browser console.

Hi, @willstorm, do you have any configured shipping methods except Flat Rate?

Yes, I'm developed an extension.

I am also developing a custom extension. If its when flat rate is disabled, I think to reproduce then you disable all shipping methods, keep one custom one. E.g. https://github.com/magento/magento2-samples/tree/master/sample-module-shipping-provider

Looks a strange, we will investigate the case when only custom shipping method is configured.

I found another issue relating same problem.
https://github.com/magento/magento2/issues/4059

Hi @willstorm and @peec, I've been tested on the latest develop branch with SampleShippingProvider module - all works fine. The estimate-shipping-methods is triggered when country or zip code is changed.

Note: to trigger request for shipping methods estimation for additional fields like city, street, etc you need to update ModuleName\view\frontend\web\js\model\shipping-rates-validation-rules.js model.

Thank you, I now found this in the docs:
http://devdocs.magento.com/guides/v2.0/howdoi/checkout/checkout_carrier.html

And these files must be present:

view/
└── frontend
    β”œβ”€β”€ layout
    β”‚Β Β  β”œβ”€β”€ checkout_cart_index.xml
    β”‚Β Β  └── checkout_index_index.xml
    └── web
        └── js
            β”œβ”€β”€ model
            β”‚Β Β  β”œβ”€β”€ shipping-rates-validation-rules.js
            β”‚Β Β  └── shipping-rates-validator.js
            └── view
                └── shipping-rates-validation.js

I guess this issue can be closed.

Hi, I think this is not solved yet... (I'm using magento 2.2.2 CE edition)

I have followed the same as @peec has mentioned, but here, my custom shipping validations are not loading, and even the .js files aren't load in my page, I don't know why ...
look:
checkout_index_index.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
   <body>
      <referenceBlock name="checkout.root">
         <arguments>
                <argument name="jsLayout" xsi:type="array">
                    <item name="components" xsi:type="array">
                        <item name="checkout" xsi:type="array">
                            <item name="children" xsi:type="array">
                                <item name="steps" xsi:type="array">
                                    <item name="children" xsi:type="array">
                                        <item name="shipping-step" xsi:type="array">
                                            <item name="children" xsi:type="array">
                                                <item name="step-config" xsi:type="array">
                                                    <item name="children" xsi:type="array">
                                                        <item name="shipping-rates-validation" xsi:type="array">
                                                            <item name="children" xsi:type="array">
                                                                <item name="inchoo" xsi:type="array">
                                                                    <item name="component" xsi:type="string">Inchoo_Shipping/js/view/inchoo</item>
                                                                </item>
                                                            </item>
                                                        </item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

checkout_cart_index.xml:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="checkout.cart.shipping">
            <arguments>
                <argument name="jsLayout" xsi:type="array">
                    <item name="components" xsi:type="array">
                        <item name="summary-block-config" xsi:type="array">
                            <item name="children" xsi:type="array">
                                <item name="shipping-rates-validation" xsi:type="array">
                                    <item name="children" xsi:type="array">
                                        <item name="inchoo" xsi:type="array">
                                            <item name="component" xsi:type="string">Inchoo_Shipping/js/view/inchoo</item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

And Finally, my inchoo.js in Inchoo/Shipping/view/frontend/web/js/view/inchoo.js, with this content:

define([
    'uiComponent',
    'Magento_Checkout/js/model/shipping-rates-validator',
    'Magento_Checkout/js/model/shipping-rates-validation-rules',
    '../model/inchoo-validatior',
    '../model/inchoo-rules'
],function (
        Component,
        defaultShippingRatesValidator,
        defaultShippingRatesValidationRules,
        shippingRatesValidator,
        shippingRatesValidationRules
    ) {
        'use strict';
        defaultShippingRatesValidator.registerValidator('carrierName', shippingRatesValidator);
        defaultShippingRatesValidationRules.registerRules('carrierName', shippingRatesValidationRules);
        return Component;
    }
);

But when I'm at guest checkout page, I've noticed that inchoo.js file is not loaded. Any idea of why it occurs?
Thanks in advance.

hi @peec @joni-jones , can any one know where this ajax get call , full path in magento 2

index.php/rest/default/V1/guest-carts/xxxxxxxxxxx/estimate-shipping-methods

even more how to get xxxxxxxxxxx value? i want to manually fire ajax call , thanks

Same kind of issue I am facing as well. But this issue occurred randomly. Sometimes its fire the ajax request but sometimes it fails. I don't understand why this issue happens. Is anybody have any idea about it?

In case someone finds this still an issue with custom shipping methods, I hope https://github.com/magento/magento2/issues/4059#issuecomment-661124699 helps.

Was this page helpful?
0 / 5 - 0 ratings