Cart Transform merge operation merging all quantities even when quantity = 1

I’m facing an issue with the Shopify Cart Transform merge operation where it seems to merge all available quantities of the involved cart lines even when I specify quantity: 1 for each line in the merge payload.

Here’s the situation:
Cart Input

{
  "cart": {
    "lines": [
      {
        "id": "gid://shopify/CartLine/LINE_1",
        "quantity": 2,
        "merchandise": { "id": "gid://shopify/ProductVariant/VARIANT_1" }
      },
      {
        "id": "gid://shopify/CartLine/LINE_2",
        "quantity": 2,
        "merchandise": { "id": "gid://shopify/ProductVariant/VARIANT_2" }
      },
      {
        "id": "gid://shopify/CartLine/LINE_3",
        "quantity": 2,
        "merchandise": { "id": "gid://shopify/ProductVariant/VARIANT_3" }
      }
    ]
  }
}

Transform Output

{
  "operations": [
    {
      "merge": {
        "title": "Bundle Test",
        "parentVariantId": "gid://shopify/ProductVariant/BUNDLE_VARIANT",
        "cartLines": [
          { "cartLineId": "gid://shopify/CartLine/LINE_1", "quantity": 1 },
          { "cartLineId": "gid://shopify/CartLine/LINE_2", "quantity": 1 },
          { "cartLineId": "gid://shopify/CartLine/LINE_3", "quantity": 1 }
        ],
        "price": { "percentageDecrease": { "value": 50 } }
      }
    }
  ]
}

Observed Behavior:
Even though each referenced cart line has 2 units and I specify quantity: 1 in the merge, the result is a single merged bundle with quantity 2 meaning Shopify merged all available units from those lines.

Expected Behavior:
I expected it to merge just 1 unit of each line (to form 1 bundle) and leave the remaining quantity as individual lines.

Question:

  • Is this the intended behavior of the merge operation?

  • Does Shopify always merge the entire cart line, regardless of the quantity value?

  • If so, is the correct approach to perform a split operation first, and then merge only the new single-quantity lines?

Would appreciate any clarification or confirmation from Shopify or anyone who has implemented similar bundling logic!

I recall somebody else talking about this..
I believe the solution was to give your intended bundled products unique line properties so that you end with a unique cart line id.

2 Likes

@ceri_waters Do you happen to have a link / reference to this thread or post?

I’m also stuck on a similar problem but on POS, so the usual workarounds for the Online stores through line item attributes aren’t great solutions here.

Thank you for your time and input!

I don’t sorry I think it was in the Slack Community rather than here

1 Like

Hey @lezlet, @ceri_waters is right that for online stores, the trick is unique line item properties for each line item, so that each line item (even though they’re the same variant) has quantity of 1:

{
  "cart": {
    "lines": [
      {
        "id": "gid://shopify/CartLine/cd6a1c58-b2c2-44ed-aec1-117dade96aa0",
        "quantity": 1,
        "merchandise": {
          "id": "gid://shopify/ProductVariant/51608446665005"
        }
      },
      {
        "id": "gid://shopify/CartLine/7edaf106-9ac5-4fbf-a0cd-dbecdd25d9fe",
        "quantity": 1,
        "merchandise": {
          "id": "gid://shopify/ProductVariant/51608446665005"
        }
      },
      {
        "id": "gid://shopify/CartLine/93084782-938a-4485-9f34-5fafffa5a5da",
        "quantity": 1,
        "merchandise": {
          "id": "gid://shopify/ProductVariant/51608446042413"
        }
      },
      {
        "id": "gid://shopify/CartLine/16281e02-71ad-4eec-a220-409afce36da6",
        "quantity": 1,
        "merchandise": {
          "id": "gid://shopify/ProductVariant/51608446042413"
        }
      },
      {
        "id": "gid://shopify/CartLine/4e7bbaa6-d2ca-417a-a5f4-3d5f7c228011",
        "quantity": 1,
        "merchandise": {
          "id": "gid://shopify/ProductVariant/51608446697773"
        }
      },
      {
        "id": "gid://shopify/CartLine/3e7b3dc8-92f5-4eb3-9e4c-ffb322d8920e",
        "quantity": 1,
        "merchandise": {
          "id": "gid://shopify/ProductVariant/51608446697773"
        }
      }
    ]
  }
}

But then you also need to use multiple MERGE operations:

{
  "operations": [
    {
      "merge": {
        "cartLines": [
          {
            "cartLineId": "gid://shopify/CartLine/4e7bbaa6-d2ca-417a-a5f4-3d5f7c228011",
            "quantity": 1
          },
          {
            "cartLineId": "gid://shopify/CartLine/cd6a1c58-b2c2-44ed-aec1-117dade96aa0",
            "quantity": 1
          },
          {
            "cartLineId": "gid://shopify/CartLine/16281e02-71ad-4eec-a220-409afce36da6",
            "quantity": 1
          }
        ],
        "parentVariantId": "gid://shopify/ProductVariant/51608446730541",
        "price": {
          "percentageDecrease": {
            "value": 50
          }
        }
      }
    },
    {
      "merge": {
        "cartLines": [
          {
            "cartLineId": "gid://shopify/CartLine/3e7b3dc8-92f5-4eb3-9e4c-ffb322d8920e",
            "quantity": 1
          },
          {
            "cartLineId": "gid://shopify/CartLine/7edaf106-9ac5-4fbf-a0cd-dbecdd25d9fe",
            "quantity": 1
          },
          {
            "cartLineId": "gid://shopify/CartLine/93084782-938a-4485-9f34-5fafffa5a5da",
            "quantity": 1
          }
        ],
        "parentVariantId": "gid://shopify/ProductVariant/51608446730541",
        "price": {
          "percentageDecrease": {
            "value": 50
          }
        }
      }
    }
  ]
}

I’m not as familiar with POS, so not 100% sure of a good solution for that. It’s non-technical, but what about just scanning each of the items individually and inputting a discount code, instead of using a MERGE operation for POS?

Thanks @robbiesherrard and the Shopify support team ticket that we raised. Looks like there’s not a great way to get around this other than to add a line item property to separate out the line item.

In our case that’s not a great solution because in a large cart on POS, it just becomes messy for the cashier.

We finally took the plunge and solved for this through Discounts, which isn’t the prettiest by any means. But does what we need it to.

Here’s a snapshot from our UI that hopefully gives a good idea.

Maybe someday, Shopify will choose to honor the quantity variable that they’ve included on the API spec for Cart Transform Merge Output.

Thanks for all the help!