“Cannot update the attribute for a line?”

I can’t update the attribute for just one line when there are two lines in the cart that share the same variant.

I’ve tried both GraphQL (cartLinesUpdate) and the Ajax cart API, but in both cases the update affects all lines with the same variant, instead of only the targeted cart line.
Example cart data:

{
    "token": ....,
    "items": [
        {
            "id": "gid://shopify/CartLine/099dc1ed-ba75-4c7f-8375-00a29d026f2e",
            "properties": {
                "package": "Student Package - Essential"
            },
            "quantity": 1,
            "variant_id": 40339286720578,
            ...
        },
        {
            "id": "gid://shopify/CartLine/e63318aa-6984-46bd-8930-1bf8f2496792",
            "properties": {
                "package": "Student Package - Essential"
            },
            "quantity": 1,
            "variant_id": 40339286720578,
            ...
        },
        {
            "id": 
"gid://shopify/CartLine/46598f42-b513-43f0-8f69-c79bac6cee5f",
            "properties": {
                "package": "Student Package - Essential"
            },
            "quantity": 1,
            "variant_id": 39400247197762,
            ...
        }
    ],
}

When I run a mutation to update an attribute on the cart line with ID:

gid://shopify/CartLine/099dc1ed-ba75-4c7f-8375-00a29d026f2e

Both lines with variant 40339286720578 end up being updated, not just the one specified.

Has anyone else run into the same issue? If so, how did you handle it?

Hey @nguyenhuyquang !

Have you used the Ajax API with line index instead of variant?

For example, you can update line items based on the index or line id instead of variant id

Hi @hujjatnazari ! I already tried this before using the Storefront API and encountered the same issue. Even though I specified the line index, it still updated both lines. After all this time, I had to handle it by deleting that line and adding a new one without my attribute. But that’s not what I wanted.

Hey @nguyenhuyquang - thanks for flagging this. Does this only happen when two separate cart lines share the same variant and are the variants a component in a bundle product? Just wanting to narrow down the behaviour to see if we can replicate on our end. Happy to dig into this!

Hi @Alan_G !

In my specific case:

I have configured a discount rule for a product pair consisting of Product A and Product B. When adding 2 units of Product A and 1 unit of Product B to the cart, the function executes and splits the 2 units of Product A into two separate line items. However, when I update the line properties for the non-discounted Product A line item, the changes are also applied to the other Product A line item simultaneously, instead of only affecting the intended line.

Thanks !

Hey @nguyenhuyquang :waving_hand: - thanks for the extra details on this one! I think we can take a closer look at this for sure, just have a few more questions for you so that we can investigate further.

Is the discount rule implemented via a Cart Transform Function or an automatic discount, and can you let me know if that logic sets or normalizes line attributes when it splits the Product A lines? I think from what you said, it’s just a discount rule, but I wanted to confirm.

When you make the update, are the two Product A lines completely identical in variant, selling plan, and properties? If you’re open to sharing the exact Storefront cartLinesUpdate or Ajax change request you’re sending, the API version, and the full cart payloads immediately before and after the update, including line IDs and properties, with any secrets redacted I can take a look.

Also, are you refetching the cart after each write and then using the returned line IDs for subsequent updates, and do you observe the line IDs changing after the discount recalculates? If you’re able to share, can you include timestamps and X‑Request‑ID headers from the affected requests in case we need to take a look at our logs?

Definitely happy to investigate further with you, hope to hear from you soon.

Hi @Alan_G . The discount rule implemented via Product discount Function .

Here is the data in my case:

  • This is my cart data before the update
{
  "id": "gid://shopify/Cart/hWN2obpqQS6UKXzEH18riPvY?key=a1ca0ae2afa6061ea8a1c5e2d7dd437a",
  "lines": {
    "nodes": [
      {
        "id": "gid://shopify/CartLine/5f3156dd-d611-43cf-8433-9f72232f3531?cart=hWN2obpqQS6UKXzEH18riPvY",
        "attributes": [
          {
            "key": "package",
            "value": ""
          }
        ],
        "merchandise": {
          "id": "gid://shopify/ProductVariant/39400247197762",
          "product": {
            "id": "gid://shopify/Product/6604176359490"
          },
          "price": {
            "amount": "329.0"
          },
          "title": "1200x750 / White / White Powdercoat"
        }
      },
      {
        "id": "gid://shopify/CartLine/b9bb5e15-38ce-4d74-bab5-f5b33c120b0d?cart=hWN2obpqQS6UKXzEH18riPvY",
        "attributes": [
          {
            "key": "package",
            "value": ""
          }
        ],
        "merchandise": {
          "id": "gid://shopify/ProductVariant/39400247197762",
          "product": {
            "id": "gid://shopify/Product/6604176359490"
          },
          "price": {
            "amount": "329.0"
          },
          "title": "1200x750 / White / White Powdercoat"
        }
      },
      {
        "id": "gid://shopify/CartLine/7a6496c2-ad35-4333-af66-8b49ff6fcb2b?cart=hWN2obpqQS6UKXzEH18riPvY",
        "attributes": [
          {
            "key": "package",
            "value": "Student Package - Essential"
          }
        ],
        "merchandise": {
          "id": "gid://shopify/ProductVariant/40339286720578",
          "product": {
            "id": "gid://shopify/Product/6932146061378"
          },
          "price": {
            "amount": "139.0"
          },
          "title": "Black Mesh"
        }
      }
    ]
  }
}
  • This is the API I called:
mutation cartLinesUpdate($cartId: ID!, $lines: [CartLineUpdateInput!]!) {
  cartLinesUpdate(cartId: $cartId, lines: $lines) {
    cart {
      id
      lines(first: 100) {
        nodes {
          id
          attributes {
            key
            value
          }
        }
      }
    }
    userErrors {
      field
      message
    }
    warnings {
      message
    }
  }
}

------
{
  "variables": {
  "cartId": "gid://shopify/Cart/hWN2obpqQS6UKXzEH18riPvY?key=a1ca0ae2afa6061ea8a1c5e2d7dd437a",
  "lines": [
    {
      "id": "gid://shopify/CartLine/b9bb5e15-38ce-4d74-bab5-f5b33c120b0d?cart=hWN2obpqQS6UKXzEH18riPvY",
      "attributes": [
        {
          "key": "package",
          "value": "Student Package - Essential"
        }
      ]
    }
  ]
}
}

- This is my cart data after the update

{
  "id": "gid://shopify/Cart/hWN2obpqQS6UKXzEH18riPvY?key=a1ca0ae2afa6061ea8a1c5e2d7dd437a",
  "lines": {
    "nodes": [
      {
        "id": "gid://shopify/CartLine/5f3156dd-d611-43cf-8433-9f72232f3531?cart=hWN2obpqQS6UKXzEH18riPvY",
        "attributes": [
          {
            "key": "package",
            "value": "Student Package - Essential"
          }
        ],
        "merchandise": {
          "id": "gid://shopify/ProductVariant/39400247197762",
          "product": {
            "id": "gid://shopify/Product/6604176359490"
          },
          "price": {
            "amount": "329.0"
          },
          "title": "1200x750 / White / White Powdercoat"
        }
      },
      {
        "id": "gid://shopify/CartLine/72acf72e-206a-46a6-83e3-458aae50c066?cart=hWN2obpqQS6UKXzEH18riPvY",
        "attributes": [
          {
            "key": "package",
            "value": "Student Package - Essential"
          }
        ],
        "merchandise": {
          "id": "gid://shopify/ProductVariant/39400247197762",
          "product": {
            "id": "gid://shopify/Product/6604176359490"
          },
          "price": {
            "amount": "329.0"
          },
          "title": "1200x750 / White / White Powdercoat"
        }
      },
      {
        "id": "gid://shopify/CartLine/7a6496c2-ad35-4333-af66-8b49ff6fcb2b?cart=hWN2obpqQS6UKXzEH18riPvY",
        "attributes": [
          {
            "key": "package",
            "value": "Student Package - Essential"
          }
        ],
        "merchandise": {
          "id": "gid://shopify/ProductVariant/40339286720578",
          "product": {
            "id": "gid://shopify/Product/6932146061378"
          },
          "price": {
            "amount": "139.0"
          },
          "title": "Black Mesh"
        }
      }
    ]
  }
}

As you can see, when I updated the line gid://shopify/CartLine/b9bb5e15-38ce-4d74-bab5-f5b33c120b0d?cart=hWN2obpqQS6UKXzEH18riPvY, the properties data was updated for both lines.
Thanks!

Thanks @nguyenhuyquang, appreciate you sending this our way. I’ll do some more digging on my end here and loop back with you once I have more info to share.

1 Like

Thanks @Alan_G . I hope to hear from you soon.

Hey @nguyenhuyquang :waving_hand: , we’re looking into this as possible issue on our end now. I don’t have a turnaround time to share at the moment, but I’ll keep my eyes on this and update you as soon as I have more info to share :slight_smile:

3 Likes

Hey @nguyenhuyquang and all :waving_hand: , just following up on this. I was able to work with some folks internally. Currently, this is expected behaviour as split lines are for the moment, only created as visible when BOGO discounts are applied.

That said, I definitely understand that this isn’t ideal, so I’m logging a feature request on my end for you too. If you’d like me to include any use cases/notes in the feature request, just let me know here and I’d be happy to include those.

1 Like

Hey folks :waving_hand: - closing the loop here to confirm I’ve set up this feature request on our end. Please let me know if I can help out with anything else, happy to help!

1 Like