Hey all,
I’m running into an issue when switching markets (via the country selector) and using a custom cart/checkout validation function.
When switching markets Shopify runs the cart validation function. If the function returns an error, it appears to be prevent the market from changing.
The theme code is using the localization
form (like Dawn) but no error messages exist on the form.errors
object - so there’s no way to see the exact error that prevent the market switch.
Here’s an example:
Let’s say you a function that prevents having 2 or more items of a specific product in Canada.
If the country selected is USA, and you add 3 of that product, the cart is valid as expected.
If you change the market from USA to Canada, the page refreshes and redirects to the homepage (the form helper adds this redirect value) with USA still selected in the country selector.
If you view the function logs in the partner dashboard it displays two function runs for this example:
- Validating the cart against Canada, which returns the error (as expected)
- Validating the cart against USA, which has no error.
You can test this on Dawn (15.2) if you’re curious, but you would need a cart function to validate against a specific country. You can add the form.errors
logic to the form (since not included in Dawn) to see that it is empty.
Expected behaviour
Since the localization form is validating the cart on change, I would assume there would be a way to surface the cart errors and then handle those in the front end - since the error is preventing the market switch.
For now we’ll probably just empty the cart on market change which isn’t ideal.
This is a weird one, so any help would be much appreciated.
Thanks in advance!
Craig