Main issue: how to inspect cart data in Shopify Liquid and derive the original (pre-discount) price and percentage saved in Dawn’s main-cart-items.liquid.
Context and key details:
Code location: main-cart-items.liquid, looping with {% for item in cart.items %}.
Liquid is a server‑side templating language; it doesn’t support console.log. Use Liquid output/filters to inspect data.
Guidance provided:
To inspect data, render JSON in the template: {{ cart | json }}, {{ cart.items | json }}, or inside the loop {{ item | json }}.
Cart data is also available via the unauthenticated AJAX endpoint: GET /cart.json.
References shared: Shopify docs for cart object, JSON filter, AJAX API. Hydrogen (Shopify’s React-based custom storefront framework) mentioned as an alternative for React workflows.
OP’s follow-up results (key outputs):
cart.total_discount: 0; cart.original_total_price: 2999; cart.total_price: 2999; item_count: 1; currency shows as CurrencyDrop; cart.items shows as CartItemDrop.
The single cart item is on sale for $29.99, but totals show no discount, so original and total match, and JSON filter “did not seem to do anything” for these checks.
Status:
No resolution yet. OP still needs a way to display original price before discount and percentage saved. Code snippets and outputs are central to the issue.
I am new to Liquid, I come from a React.js background, and I am used to being able to console.log() every array of data I would like to investigate. However, with Liquid it seems like I have lost the ability to log iterable chunks of data to the console. I would love to know how to do something similar to console.log() with Liquid.
I am in the file “main-cart-items.liquid” with the Dawn theme. I see a for loop that looks like this:
{%- for item in cart.items -%}
And I have been trying to find out what cart.items is for 2 hours now. Can anyone help me please? I have tried things like {{ cart }} {{ cart.items }} {{ item }} and nothing seems to be showing up.
*unfortunately due to shopify silliness there is no longer a document listing the global objects instead you have to look at each thing individually in the docs
To get the cart data available on the unauthenticated ajax api just hit /cart.json
Also be aware of Hydrogen shopifys framework for custom storefronts that may be a more suitable buy in for react based development houses. Because the tooling for liquid based theme dev in the online-sales channel isn’t even third rate.
Thank you for your reply, however I am still stuck. I went and tested every key in the cart object, and commented out what each one displays. “| JSON” did not seem to do anything for me in these specific cases.
I need to display the original price before the discount and the percentage saved.
Here are the results: