I’m using the Local Pickup Delivery Option Generator API to customize the list of local pickup locations to my buyers. The user needs to select a location in the cart before the checkout (due to some other processing that we need to do). I pass this information to the checkout as a cart attribute. And once in the checkout, I need to display only that location as the local pickup location so the user does not have to select the same location again.
I have the function working correctly. However, I notice that it will not call my function if the user goes back to the cart and changes the location. So it seems that the list returned from my function is cached by shopify somehow and and it’s not calling it every time the user goes from the cart to checkout. I did notice that if I change the product in the cart ( by adding or deleting a product), the function gets called again.
So my question is, how do I make sure that my function gets called every time the user goes to checkout, particularly after changing the location in Cart? Also, this function (Local pickup delivery option generator API) is marked with api_version=“unstable”. But I do not see anything in the API reference indicating that it’s in beta or anything. Should I not be using this API for production system?
Hi Byung,
The caching behavior you observe is likely due to Shopify’s optimization mechanisms. To ensure your function is invoked every time the user transitions from the cart to checkout, you can try the following approaches:
- Invalidate the Cache: Modify the cart in a way that forces Shopify to re-evaluate the local pickup options. For example, adding or removing a dummy product or updating a cart attribute might trigger the function.
- Use Cart Attributes: Ensure that the cart attribute storing the selected location is updated whenever the user changes the location in the cart. This might help Shopify recognize the change and call your function again.
Unfortunately, Shopify does not provide a direct way to force the function to be called on every transition. You may need to experiment with the above methods to find a reliable workaround.
RE: Using the API in production - being marked as unstable
indicates that it’s still in development and subject to changes. While it is not explicitly stated as being in beta, using an unstable
API in a production environment carries risks:
- The API may change without notice, potentially breaking your implementation.
- Shopify may not provide support for issues encountered with
unstable
APIs.
If possible, consider using stable alternatives or waiting for the API to reach a stable version before deploying it in production.
Thank you for your response. Well, at least I know that I’m not imagining the behavior. Changing the cart attribute does not help as that’s what I’m doing now whenever the user selects a different location on the cart. I have tried playing with product changes and that’s also not very reliable either.
But the last point (re: unstable api) gives me pause from using this for now.