A space to discuss online store customization, theme development, and Liquid templating.
After running a Cart transform function's Merge operation, you can see all the merged products together in the checkout page.
Is there any way to have that kind of display for the cart items, but in the cart page? Currently, the cart will only display the parent item of that Merge Operation.
I looked at the cart object but, following the example in the pictures, there is only one item in the cart object with no additional properties that even hint at this being a parent of merged items. I think it would be helpful to have that same type of display as the checkout page for the cart page, with an arrow toggle button that either "shows X items" or "hides X items".
Solved! Go to the solution
This is an accepted solution.
I can't test this right now but you should be able to display the components of a bundle using the item_components property on the line_item using something like:
{%- for item in cart.items -%}
{% comment %} inside the item currently {% endcomment %}
{% for component in item_components %}
{% comment %} inside the item components now {% endcomment %}
{{ component.title }}
{% endfor %}
{%- endfor -%}
See the Liquid objects - Line Item
This is an accepted solution.
I can't test this right now but you should be able to display the components of a bundle using the item_components property on the line_item using something like:
{%- for item in cart.items -%}
{% comment %} inside the item currently {% endcomment %}
{% for component in item_components %}
{% comment %} inside the item components now {% endcomment %}
{{ component.title }}
{% endfor %}
{%- endfor -%}
See the Liquid objects - Line Item
Thank you for that suggestion! There was just one little error in the code that it should be calling item.intem_components, like so.
{%- for item in cart.items -%}
{% comment %} inside the item currently {% endcomment %}
{% for component in item.item_components %}
{% comment %} inside the item components now {% endcomment %}
{{ component.title }}
{% endfor %}
{%- endfor -%}
The item_components seems to be exactly the property that I was looking for. I think my main issue was that I was just looking at what was getting outputted when I was printing out the cart object, or printing out a cart line object. The item_components property was not being displayed. Guess that one is on me for not looking at the docs 😋.
Ah sorry! My fault for coding it in shopify browser quickly without error underlinining.
Yeah that tends to happen without being able to output all property/values on objects in Liquid, it gets a bit confusing when you're a few objects deep. I mainly just put the docs there for the next person who has the same question, or if you wanted to look at other problems.