Happening now! Shopify Community AMA: PayPal Express Migration to Shopify Payments | Ask your questions to be answered by our team.
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.

Display all merged cart lines in cart page

Solved

Display all merged cart lines in cart page

forsakenplace
Shopify Partner
3 0 1

After running a Cart transform function's Merge operation, you can see all the merged products together in the checkout page. 

forsakenplace_0-1712710628219.png

 

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.

 

forsakenplace_2-1712710718882.png

 

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".

 

Accepted Solution (1)

Tuckey
Shopify Partner
10 2 9

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

View solution in original post

Replies 3 (3)

Tuckey
Shopify Partner
10 2 9

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

forsakenplace
Shopify Partner
3 0 1

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 😋

Tuckey
Shopify Partner
10 2 9

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.