cancel
Showing results for 
Search instead for 
Did you mean: 

On onepage checkout page my custom shipping method rates are not updating automatically

SOLVED
Highlighted

On onepage checkout page my custom shipping method rates are not updating automatically

I'm new to Magento development. I have implemented Magento2 custom shipping method extension which will display shipping rates by calling my own rest api with origin, destination address and items from the cart.

 

After adding products to cart and as soon as i enter into one page check out page and fill/update all mandatory fields in the destination address form rates are not refreshing automatically. So on shipping section nothing showing.

 

But if browser saved a destination address / if i refresh the browser rates are showing properly without any issue. Also If i enable any other shipping method like flat rate, table rate or any third party (UPS, FEDEX) carrier shipping along with my custom shipping as soon as i filled destination address rates are automatically coming including enabled shipping method rates and my custom shipping method rates. 

 

Looks like my custom shipping method is getting cached and not automatically refreshed on onepage checkout if i enter/update the destination address. Can anybody help on this. 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: On onepage checkout page my custom shipping method rates are not updating automatically

Hi Rahul

 

After I created view and added the JS validations to destination address form fields started working. I referred Flat rate module -> Magento_OfflineShipping

 

Thank you for the support. :-)

View solution in original post

5 REPLIES 5
Highlighted

Re: On onepage checkout page my custom shipping method rates are not updating automatically

@shiva _penmetsa it seems when you fill your address and goes to the shipping method at that time your api is not able to get the destination address.

 

So can you please check while showing shipping address are you getting the destination address or not?

 

Thanks

Highlighted

Re: On onepage checkout page my custom shipping method rates are not updating automatically

Hey Rahul

 

Thank you. My API able to pull the destination address. Here the problem is my shipping method not triggering by Magento after fill the destination address. But If I enable either one of existing shipping methods like Table rate, flat rate or any carrier FEDEX, UPS shipping methods along with my custom shipping method automatically my shipping method is triggering by Magento once destination address filled.   

 

Do you have any idea does Magento cache the shipping methods by default. We need to tell Magento don't cache it? Because if I enable any other shipping method then automatically showing both shipping rates once fill the destination address. At the same time if i disable all the shipping methods except my custom shipping method. Rate are not showing until unless i refresh browser rates after enter the destination address.

Highlighted

Re: On onepage checkout page my custom shipping method rates are not updating automatically

@shiva _penmetsa Magento doesn't save the shipping data in cache.

 

Instead when you fill the shipping address it hits the ajax through which all the shipping methods got to know about the shipping address and accordingly methods are shown.

 

So in your case that ajax is not able to pull your shipping method so just check that ajax function.

 

Thanks

Highlighted

Re: On onepage checkout page my custom shipping method rates are not updating automatically

Hi Rahul,

 

I thought ajax is not able to pull my shipping method due to cache. But if Magento does not cache the shipping method then can you help me on understanding on the flow. 

 

I see in the browser network tab. If I enable both flat rate and my shipping method then as soon as I filled the destination address below api call is calling <host>/rest/default/V1/guest-carts/j6pqVW2NYHNijSEZYtrZIQ7eZlBCIJgb/estimate-shipping-methods and rates are coming. But if I disable flat rate and enable only my shipping method then the api call is not happening. 

 

Here is my implementation. I created a custom module as per Magento standard structure. 

app/code/<company>/<module-name>/registration.php

app/code/<company>/<module-name>/etc/module.php

app/code/<company>/<module-name>/etc/config.php

app/code/<company>/<module-name>/etc/adminhtml/system.php

app/code/<company>/<module-name>/Model/Carrier/Shipping.php

 

In Shipping.php i extended the Magento\Shipping\Model\Carrier\AbstractCarrier and implemented Magento\Shipping\Model\Carrier\CarrierInterface

 

Have two methods implemented 

 

 public function getAllowedMethods()
{
return [$this->_code => $this->getConfigData('name')];
}

 

public function collectRates(RateRequest $request) () {

 

In this method i'm calling my API with source, destination, cart items. Once i receive rates looping it and creating Magento\Quote\Model\Quote\Address\RateResult\MethodFactory reference for each carrier rate and setting into Magento\Shipping\Model\Rate\ResultFactory reference.

}

If i enable flat rate, shipping method section looks like this with multiple rates

Magentorates-1.png

 

If i disable flat rate nothing comes but if i refresh browser i'm able see my API rates.

 

Can you please help what exactly i'm missing. Why Ajax unable to call my Shipping method if i enable only my shipping method. 

 

 

Highlighted

Re: On onepage checkout page my custom shipping method rates are not updating automatically

Hi Rahul

 

After I created view and added the JS validations to destination address form fields started working. I referred Flat rate module -> Magento_OfflineShipping

 

Thank you for the support. :-)

View solution in original post