CART JSON doesn't include compare at price in item object

Highlighted
Shopify Partner
26 0 7

Why the cart.json doesn't return the compare at price of each item? 

I'm using an ajax cart, and I would like to display how much the clients are saving on products on sales. 
Each item returns: line_price:1400  / original_line_price:1400  / original_price:1400 / price:1400

But all these properties are related to discount codes, so there is no way to know if a product is on sale.

Wouldn't make sense to add the compare_at_price in the Item object ? 

Robots Hate Monkeys
1 Like
Highlighted
Shopify Staff (Retired)
Shopify Staff (Retired)
531 0 97

Hey Frederico,


You can use the variant ID to fetch the compare at price from the product endpoint. There aren't any immediate plans to add the compare at price to the cart model.

1 Like
Highlighted
Shopify Partner
26 0 7

I'm actually storing the compare at price in localstorage when the user clicks on the "add to cart" button, using variant ID as key and the price as value, so I can easily get the value for each cart item.

 

Robots Hate Monkeys
0 Likes
Highlighted
Shopify Expert
146 0 28

how do we use the variant ID to get the compare_at_price? can you post an example?

1 Like
Highlighted
Shopify Expert
9929 104 1765

Out of interest, why do you need this via cart.json? What's the use case?

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
Highlighted
Shopify Expert
146 0 28

My client wants to display a message about products on sale being FInal Sale in the cart - and only display the notice if there is a sale product in their cart. Since we are using an AJAX cart, i need to loop through the items in JS and check if one is on sale and then conditionally hide / show the message.

 

 

0 Likes
Highlighted
Tourist
3 0 2

Frederico is right. Spent hours today debuging and I have the same issue. The Cart get endpoint returns line items without the compare at price ( It is included but is equal to sales price ).

Why would we need this via JSON ? Why would Shopify release include in their official theme - I need it because I'd like to show in my cart drawer The Item Sales Price and Original Price, why not ?

Please see here in Timber - In Cart Handlerbars template it is expected a discounted price and if you look also in cart-ajax.js of this theme you would see it is also expecting the discounted price to be reflected in the JSON response.

This is my first attempt at shopify coming from Laravel and to be honest i am very discouraged, documentations are lacking info and are outdated besides many other limitations. Maybe the guys at shopify don't care but it's my humble opinion. 

1 Like
Highlighted
Shopify Expert
9929 104 1765

If you need different data to be returned from an endpoint, make an alternate template for the cart that returns a JSON string containing whatever you need.

This might not cover all use cases but should for the one talked about here.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
Highlighted
Tourist
3 0 2

Hello Jason, Thanks for the reply. I understand and it is what I am actually doing, using timber as a starting point but the problem here seems from the backend.

E.g Choose any product and give it a Price & Compare at price, this should set the product on sales .
Now in my cart drawer ( Front end ) when I fecth the cart items via Json just as Timber did it doesn't include both prices only the Sales / Discounted price.

See Screenshot -  Discounted Price / Original Price / Line Price ect.. all are correct and equal to the sales price but there isn't a way to know if the product has a discount & the price before.


I hope I am missing something here  - What do you think ?

 

 

1 Like
Highlighted
Shopify Partner
26 0 7
{%- layout none -%}
{%- for tag in product.tags -%}
  {%- if tag contains 'color' -%}
    {%- assign colortag = tag -%}
  {%- endif -%}
{%- endfor -%}
{
  "details":"{{product.metafields.custom_fields.product_details}}",
  "colortag":"{{colortag}}",
  "product":{{product | json }}
}

What Jason suggest solves the issue. I use custom json templates everywhere. 
Attached an example of product json with 2 extra parameters: a metafield and a tag.
I use this to display via ajax alternative colors.

The default product.json doesn't include metafields, and instead of goign through all the tags by code, i expose the one I need ( colortag ). 

Raja Khoury you can do the same with any template.

Robots Hate Monkeys
0 Likes