How to merge several bundles from the same cart line?

Our app utilizes the Cart Transform Merge Operation to merge bundles in the cart.

One of our clients sells a product both as single units and in packs (e.g., 2-pack, 4-pack). When a buyer adds a quantity of 2 to the cart, it’s merged into a 2-pack. Similarly, if they add a quantity of 4, it’s merged into a 4-pack.

The client wants to allow customers to purchase 6 of the same product, and in this scenario, the cart should contain a 4-pack and a 2-pack after the merge.

However, we’re unable to achieve this functionality. According to the documentation:

Multiple merge operations targeting the same cart line: The first merge operation in the list is executed, and all other merge operations for the same cart line are discarded.

In this case, the cart has a single line with a quantity of 6. This means we can’t target the same line for two separate bundles (packs), and as a result, only one bundle is being merged.

Is there any solution or workaround for this?

Try passing unique line attributes and then aggregating them in the response based on those attributes.

1 Like

Use line item properties to distinguish these 2 different packs

We don’t have control over the items that are added to the cart, so unfortunately, we can’t use the trick of splitting lines with properties. In this case, there’s a single item line with a quantity of 6 in the cart, which needs to be merged into two different bundles.