All things Shopify and commerce
I had a sample code like below
fetch('/cart/change.js', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ line,
quantity,
sections,
sections_url }) }) .then(async (res) => {
if (res.status === 422) {
var body = await res.json();
console.log('Body', body);
return res.json()
}
return res.text()
}) .then((json) => { console.log(json); }) .catch((error) => { console.error('Error:', error); });
The code is just some sample. The errors I receive in my terminal. Is match with the errors in our Checkout Rule
However we actually receive something totally different when parse the body.
Is this intended or anyway we can get something like error response in /cart/add.js which work perfectly fine with Checkout Validation Rule
{
"status": 422,
"message": "Cart Error",
"description": "You can't add purchase than 1 pre-order product in your cart."
}
I am also looking the solution for this issue.
Shopify added the validation on storefront api that response is mostly 422 in case of fail that is big issue and stop the execution of theme after ajax request. Can any one helpe to know who dawn theme handle the cart drawer after add and change the cart item.
Thanks
Zain
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024