1

I'm trying to create a module with custom shipping method. So I've followed this tutorial to create it. This link and this link, to configure shipping carrier validations.

The problem is, if I change the zip/postcode, the shipping's value does not change. My question is, how can I update the shipping cost value when customer update its address information (postcode to be more specific)? Or when we use the guest-checkout and there is no address information?

Thanks in advance.

2 Answers 2

3

I had the same problem. The problem is on your xml definition of the rates validation:

<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>

In your xml, when you define the js validator:

<item name="inchoo" xsi:type="array">

You must change the name to:

<item name="inchoo-rates-validation" xsi:type="array">

And inchoo must be the same as carrier code of your shipping method. The problem is when magento try lo find and load all validators in :

...vendor/magento/module-checkout/Block/Checkout/LayoutProcessor.php

on method processShippingChildrenComponents

private function processShippingChildrenComponents($shippingRatesLayout)
{
    $activeCarriers = $this->getShippingConfig()->getActiveCarriers(
        $this->getStoreResolver()->getCurrentStoreId()
    );
    foreach (array_keys($shippingRatesLayout) as $carrierName) {
        $carrierKey = str_replace('-rates-validation', '', $carrierName);
        if (!array_key_exists($carrierKey, $activeCarriers)) {
            unset($shippingRatesLayout[$carrierName]);
        }
    }
    return $shippingRatesLayout;
}

If magento does not find the same name as carrier, unset the file in layout.

Regards

Mauro M. Martinez

4
0

Please find below the solution

 <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" 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">
                                                 <!-- add a new validator-->
                                                 <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="asap-rates-validation" xsi:type="array">
                                                                     <item name="component" xsi:type="string">Company_Modulename/js/view/asap</item>
                                                                 </item>
                                                             </item>
                                                         </item>
                                                     </item>
                                                 </item>
                                             </item>
                                         </item>
                                     </item>
                                 </item>
                             </item>
                         </item>
                     </item>
                 </argument>
             </arguments>
     </referenceBlock>
 </body>

Please note that you should use the carrier name for 'asap'.

<item name="asap-rates-validation" xsi:type="array">
     <item name="component" xsi:type="string">Company_Modulename/js/view/asap</item>
</item>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.