Nested cart lines for addons now works šŸ”„

It can show both places but relies on some liquid logic. There’s some examples in the post.

1 Like

Oh I can use this code snipet to display in cart page or cart drawer, right?

I have more concern whether we can remove the nest items only?

Hey again. Is this what you’re looking for?

oh Thanks. The cart clears both parent & nest items, but the children aren’t reflected inside the response

What would be the best approach to set the instructions (can_remove: false) or (can_update_quantity: false) during the add to cart?

Thank you!

1 Like

Fetch request

await fetch(window.Shopify.routes.root + 'cart/add.js', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        items: [
          { id: variant_id, parent_line_key: key, quantity: quantity, instructions: { can_update_quantity: false, can_remove: false } }
        ]
      })
 });

Payload

{
    "id": 44875894096044,
    "parent_line_key": "39372678234284:431608d3917496767dae82679a108e0e",
    "quantity": 3,
    "instructions": {
        "can_update_quantity": false,
        "can_remove": false
    }
}

Response

{
    "id": 44875894096044,
    "properties": {},
    "quantity": 3,
    "variant_id": 44875894096044,
    "key": "44875894096044:6ee20082f3ef3dc41248e430927e01d0",
    "parent_relationship": {
        "parent_key": "39372678234284:431608d3917496767dae82679a108e0e"
    },
    "instructions": {
        "can_remove": true,
        "can_update_quantity": true
    },
    ...
}
1 Like

Hey @app

I’m note sure! I have not tested that.

Honestly I’m unsure if that is a read_only property?

Yes indeed. It looks like the documentation is unfinished.

1 Like

Hi everyone,

I encountered a problem with nested cart lines.
Is it possible that public line_item properties are not visible in the Order Status Page for a variant with a child item (add-on with nested cart lines) ?

Actually I can see the public line item properties on:

  • Cart
  • Checkout
  • Thank You Page

Thank you for your support!
Gio

I’m wondering what the support is for these within packing slips?

Also just to add here, seems rather stupid we have parent_relationship, but then don’t have anything like child_items, meaning if we want to display nested items in liquid, we’d have to loop over ALL cart.items again, seems silly to have to do this.

cc @ceri_waters

1 Like

I just noticed that the parent relation does not work if a discount is applied to the parent item. Is that a known problem?

2 Likes

Also trying to adjust the instructions (can_remove: false) and (can_update_quantity: false) on ATC but it does not seem to be working.. There must be a way to manage those values, right? It seems weird to include variables will always return true…

1 Like

I’m not sure at all, but I’d guess that the true value is either determined by something sales channel / product specific or thought for something coming later. I can’t find any resources on it at all. Maybe even something when it’s used through Functions?

I’m using the Nested add-on, but when I use Add to Cart with a product from the Bundles app, it shows an error as in this screenshot: https://prnt.sc/sx5pFZhGwpVQ.
Is this because Shopify does not allow nested add-ons to be used together with product bundles?

Not sure - what does the network tab show?

But would make sense, as nested items and bundles has a lot of overlap. In what case do you see those two being used together?

’m seeing a reproducible issue with nested cart lines on Cart AJAX when attaching a child to an existing parent using parent_line_key.

Works reliably

If I add parent + child in one /cart/add.js request using parent_id, nested relationship is created correctly and response includes parent_relationship.parent_key.

Fails intermittently

If parent is already in cart and I add child separately with parent_line_key, I sometimes get HTTP 200 with:

{ā€œitemsā€:[]}

Then the child is added as top-level (not nested).

Payload used in failing path:

{

ā€œitemsā€: [

{

  "id": 45404245754041,

  "quantity": 1,

  "parent_line_key": "45493436317881:766cd7bd8a296445263574d6671027e0"

}

]

}

I verify the parent key from /cart.js immediately before sending, so this isn’t an old hardcoded key.

I also see this console warning from listener code:

[shop_events_listener] Error in handleXhrDone: Payload body and response have different number of items

(it looks like it compares request items count vs response items count and throws when response is empty).

Has anyone else seen received this issue ?