Shopify/function-examples

Sorting delivery methods doesn't work for Local Delivery

Closed this issue · 5 comments

Here function output is defining the sorting of the shipping methods, but that is NOT what happens on the checkout. Local delivery seems to have a mind of it's own and sometimes appears randomly as the last shipping method, which is not what the sorting function specified. Is this known behaviour or issue?

Function Stdin:
Screenshot 2023-03-13 at 12 46 50 AM

Function Stdout:
Screenshot 2023-03-13 at 12 47 05 AM

Checkout:
Screenshot 2023-03-13 at 12 47 18 AM

Store name:
https://sylab-store.myshopify.com/

It seems when checkout page is rendered, then function runs 2-3 times. Some of those runs only show 2 shipping methods, seems like it takes time to load Local Delivery.
Screenshot 2023-03-13 at 1 54 40 AM

The problem happens when it takes time to load Local Delivery option on checkout. Then even though function runs again and sorting stdout is generated correctly, Local Delivery still appears at the end of the list on checkout, which is wrong. It disregards the sorting function.

PS. There is only one function I've deployed which tries to sort shipping methods.

Looks like the sorting is done on some shipping rates prefetch which might have only subset of delivery options.

Any solution for this?

It worked on my tests. Would like to better understand the issue here but seems I miss some context about your setup @SaeedYasin. @rameshr-shopify do you have any idea for this, why could it happen this way for local delivery?

Context for delivery customizations API doc.

We used to have some specific sorting logic for local delivery and instore pickup before, but it shouldn't be overriding function outputs. @SaeedYasin , are you able to share the checkout token (the url) of a checkout when you encountered this issue? We'd be able to get a better understanding of what's happening if we have that info.