We are creating on the fly variant of product on the product page. Right after creating this new variant, we add it to the cart with Shopify Ajax API (/cart/add.js). But at the same time when we go to the cart page, it shows an empty line item without properties of the newly created variant like zero price, no image just show quantity as below in the screenshot.
Sometimes it shows correct but sometimes this way. After refreshing a couple of times cart page, it brings complete properties.
Here is the video covering this issue and of API responses.
https://drive.google.com/file/d/1b2YGcyEYEZU7IA4s7eNqHTdfahT8HCDN/view
We have investigated this issue and these are the evaluations:
- We are running 3 Ajax APIs.
As you can see, before AJAX API calls we are creating a new variant with admin API having price “36.79” and its id is “40160393625751”. - In the 1st Ajax API call (/cart/add.js), we are adding the newly created variant in the cart with the id “40160393625751”, in response, we are getting the added variant with its complete data including price, total price, image path, and quantity. Add.js response:
{id: 40160393625751, properties: null, quantity: 1, variant_id: 40160393625751,…}
discounted_price: 3679
discounts: []
featured_image: {aspect_ratio: 1, alt: "Canvas Lunch Bag", height: 1000,…}
final_line_price: 3679
final_price: 3679
gift_card: false
grams: 454
handle: "canvas-lunch-bag"
id: 40160393625751
image: "https://cdn.shopify.com/s/files/1/0520/4954/3319/products/Lunchbag_Khaki_Front_8ae0e1f4-407d-4ac0-89e6-961b306ef351.jpg?v=1620449416"
key: "40160393625751:8f7aed7a54ec9390d98246a56d3f7405"
line_level_discount_allocations: []
line_level_total_discount: 0
line_price: 3679
options_with_values: [{name: "Color", value: "Khaki - Your Price Rs.36.79"}]
original_line_price: 3679
original_price: 3679
price: 3679
product_description: "This is a demonstration store. You can purchase products like this from United By Blue.↵Reusable, durable, and roomy. Our lunchbag has a snap-closure top that rolls down to perfect for trail snacks and lunches. Small enough to throw in any of our bags.↵↵100% Organic Cotton↵Leather Trim↵Lifetime Guarantee↵↵"
product_has_only_default_variant: false
product_id: 6839736664215
product_title: "Canvas Lunch Bag"
product_type: "Bags"
properties: null
quantity: 1
requires_shipping: false
sku: ""
taxable: false
title: "Canvas Lunch Bag - Khaki - Your Price Rs.36.79"
total_discount: 0
url: "/products/canvas-lunch-bag?variant=40160393625751"
variant_id: 40160393625751
variant_options: ["Khaki - Your Price Rs.36.79"]
variant_title: "Khaki - Your Price Rs.36.79"
vendor: "United By Blue"
- In the 2nd Ajax API call (/cart/change.js), the newly added variant as a cart line item has complete properties like price, total price, image path, and quantity. As you can see we are highlighting in the video. Change.js response:
attributes: {}
cart_level_discount_applications: []
currency: "PKR"
item_count: 1
items: [{id: 40160393625751, properties: {}, quantity: 1, variant_id: 40160393625751,…}]
0: {id: 40160393625751, properties: {}, quantity: 1, variant_id: 40160393625751,…}
discounted_price: 3679
discounts: []
featured_image: {aspect_ratio: 1, alt: "Canvas Lunch Bag", height: 1000,…}
final_line_price: 3679
final_price: 3679
gift_card: false
grams: 454
handle: "canvas-lunch-bag"
id: 40160393625751
image: "https://cdn.shopify.com/s/files/1/0520/4954/3319/products/Lunchbag_Khaki_Front_8ae0e1f4-407d-4ac0-89e6-961b306ef351.jpg?v=1620449416"
key: "40160393625751:8f7aed7a54ec9390d98246a56d3f7405"
line_level_discount_allocations: []
line_level_total_discount: 0
line_price: 3679
options_with_values: [{name: "Color", value: "Khaki - Your Price Rs.36.79"}]
original_line_price: 3679
original_price: 3679
price: 3679
product_description: "This is a demonstration store. You can purchase products like this from United By Blue.↵Reusable, durable, and roomy. Our lunchbag has a snap-closure top that rolls down to perfect for trail snacks and lunches. Small enough to throw in any of our bags.↵↵100% Organic Cotton↵Leather Trim↵Lifetime Guarantee↵↵"
product_has_only_default_variant: false
product_id: 6839736664215
product_title: "Canvas Lunch Bag"
product_type: "Bags"
properties: {}
quantity: 1
requires_shipping: false
sku: ""
taxable: false
title: "Canvas Lunch Bag - Khaki - Your Price Rs.36.79"
total_discount: 0
url: "/products/canvas-lunch-bag?variant=40160393625751"
variant_id: 40160393625751
variant_options: ["Khaki - Your Price Rs.36.79"]
variant_title: "Khaki - Your Price Rs.36.79"
vendor: "United By Blue"
items_subtotal_price: 3679
note: null
original_total_price: 3679
requires_shipping: false
token: "0d4386c33dc64a3f98f6b2cc10b693bc"
total_discount: 0
total_price: 3679
total_weight: 454
- In the 3rd Ajax API call (/cart.js), we are getting the cart line items. The problem is all here. The newly created variant with the id “40160393625751” that is added in the cart with API call (/cart/add.js) made a line item but without all properties ready like price, title, image. It just shows the id and quantity at the start and after some time again this ajax API (/cart.js) brings the complete properties of this new variant added or refreshing couple to times cart page with an unspecified time taken. Cart.js response:
attributes: {}
cart_level_discount_applications: []
currency: "PKR"
item_count: 1
items: [{id: 40160393625751, properties: null, quantity: 1, variant_id: 40160393625751,…}]
0: {id: 40160393625751, properties: null, quantity: 1, variant_id: 40160393625751,…}
discounted_price: 0
discounts: []
featured_image: {aspect_ratio: null, alt: null, height: null, url: null, width: null}
final_line_price: 0
final_price: 0
gift_card: false
grams: 0
handle: null
id: 40160393625751
image: null
key: "40160393625751:8f7aed7a54ec9390d98246a56d3f7405"
line_level_discount_allocations: []
line_level_total_discount: 0
line_price: 0
options_with_values: null
original_line_price: 0
original_price: 0
price: 0
product_description: null
product_has_only_default_variant: false
product_id: null
product_title: null
product_type: null
properties: null
quantity: 1
requires_shipping: null
sku: null
taxable: null
title: null
total_discount: 0
url: ""
variant_id: 40160393625751
variant_options: null
variant_title: null
vendor: null
items_subtotal_price: 0
note: null
original_total_price: 0
requires_shipping: false
token: "0d4386c33dc64a3f98f6b2cc10b693bc"
total_discount: 0
total_price: 0
total_weight: 0
There might be a problem in response to the Cart.js API for a couple of seconds preparing a cart line item.
If anyone has already faced this issue and have figured out any solution then please share your solution.
