Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Add to cart api broken image and null title issue

Add to cart api broken image and null title issue

alifaiz1804
Shopify Partner
12 0 3

Hi, I have a backend API that creates a variant against a product and returns its variant_id. 

 

On the Shopify theme side. I'm calling my backend API and adding the variant_id(received in API response) to the cart. The variant_id is successfully added to the cart but shows a broken image, title, and 0.00 for the price the first time. and on reload it shows the image and title correctly. The flow works fine mainly but sometimes it shows the described error.

 

 

Add to cart code:
$.ajax({
type: 'POST',
url: '/cart/add.js',
dataType: 'json',
async:false,
data: {
"quantity": 1,
"id": variantId,
properties: {
'items': variantsInfo
}
},
success: function (success) {
fetchCart();
openCartDrawer();

var cartContents = fetch(window.Shopify.routes.root + 'cart.js')
.then(response => response.json())
.then(data => { console.log(data) });
}
});
Replies 0 (0)