Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Storefront API: Custom Shipping Rate as per Order Price and Discount

Storefront API: Custom Shipping Rate as per Order Price and Discount

samiiiip
Visitor
1 0 1

@Zameer : If you could have a look, or let me know, if you need further information. 

We have following shipping rate condition set in Shopify: 
$0 for orders above 30$
$2.99 for any order
And we need to implement least priced available shipping rate handle on checkout on app using storefront API version 2021-10.

For order of 40$, The available shipping rate from storefront api is:

"availableShippingRates": {
"ready": true,
"shippingRates": [
{
"handle": "shopify-Free%20Delivery-0.00",
"priceV2": {
"amount": "0.0",
"currencyCode": "AUD"
},
"title": "Free Delivery"
},
{
"handle": "shopify-Delivery-2.99",
"priceV2": {
"amount": "2.99",
"currencyCode": "AUD"
},
"title": "Delivery"
}
]
},

Once discount is applied and order amount is less than 30, we get 
"availableShippingRates": {
"ready": true,
"shippingRates": [
{
"handle": "shopify-Delivery-2.99",
"priceV2": {
"amount": "2.99",
"currencyCode": "AUD"
},
"title": "Delivery"
}
]
},
But after the discount is removed using 
checkoutDiscountCodeRemove mutation. 
There is no change in available shipping rate. We understand there is some asynchronous thing going on in background in shopify but, there is no way to tell, if the background task is finished. the ready field in checkout as well as available shipping rate is true. 

Available shipping rate should include free shipping ("handle": "shopify-Free%20Delivery-0.00") but it's 

"availableShippingRates": {
"ready": true,
"shippingRates": [
{
"handle": "shopify-Delivery-2.99",
"priceV2": {
"amount": "2.99",
"currencyCode": "AUD"
},
"title": "Delivery"
}
]
}

Only when 
checkoutDiscountCodeRemove is called 2 times or after polling checkout object again, it shows the correct result:

"availableShippingRates": {
"ready": true,
"shippingRates": [
{
"handle": "shopify-Free%20Delivery-0.00",
"priceV2": {
"amount": "0.0",
"currencyCode": "AUD"
},
"title": "Free Delivery"
},
{
"handle": "shopify-Delivery-2.99",
"priceV2": {
"amount": "2.99",
"currencyCode": "AUD"
},
"title": "Delivery"
}
]
},
 
Reply 1 (1)

viico
Shopify Partner
5 0 0

We are facing the same problem here, shippingRates are not updated when calling methods such as checkoutLineItemsUpdate

It's problematic and it's forcing us to retrieve data a second time and hopping that it is up to date.

 

@samiiiip Did you find any solution ?