FROM CACHE - en_header

Item price is $0 when redirecting to the cart right after adding a new variation

VincentDamour
Shopify Partner
2 0 0

Hello there,

I have a problem with my code. I create a new variation with the API, add it to the cart then redirect to the cart page. The cart page will then contain the newly added item, but with a price of $0. If a wait a little bit or refresh, the price will be set correctly. I feel like Shopify needs to process something before making the price available. I know I can fetch cart.js until the price is okay, but I was wondering if there is any other way to wait for the price to bet set before redirecting to the cart page.

Thank you,

Vincent

Replies 4 (4)
sillycube
Shopify Partner
700 16 106

I use setInterval to check if it's ready. If it returns 200, clearInterval and finish the remaining work. But it's not stable. Do you have a better approach?

BYOB - Build Your Own Bundles, SPO - SEO App to research keywords & edit social link preview
David_Weru
Shopify Partner
163 15 37

Hello,

If it gets reset as soon as the page loads, you could fetch the variant price along with the item and just add it in the displayed element using jquery or just javascript.

 

When the page loads, the expected behavior will resume.

 

sillycube
Shopify Partner
700 16 106

@David_Weru 

No, it's not getting reset. But the new variant options and product name cannot be shown. You can refer to a post I made on SO. There is a screenshot. 

BYOB - Build Your Own Bundles, SPO - SEO App to research keywords & edit social link preview
David_Weru
Shopify Partner
163 15 37

Would it be possible to post the code you wrote to do this?  I'd like to see what's going wrong.

 

Also correcting it would be easier.