Expand Operations Multiplying original Cart Quantities

I want to expand a cart line when I have only one eligible entry cart line (tag matches, quantity is odd), to add the cart line at the original price and another at a discounted price.

My original cart had only one entry with quantity of three.

This is what I am getting in my checkout:

And here is part of the function:

function optionallyAddExpandOperation(
  { id: cartLineId, merchandise, cost }
) {
  

  
    return {
      cartLineId,
      title: `${merchandise.title} added`,
      // Optionally override the image for line item
      // image: { url: "https://cdn.shopify.com/.../something.png" },
      expandedCartItems: [
        {
          merchandiseId: "gid://shopify/ProductVariant/1234",
          quantity: 1,
          price: {
            adjustment: {
              fixedPricePerUnit: {
                amount: "48.99"
              }
            }
          }
        },
        {
          merchandiseId: "gid://shopify/ProductVariant/1234",
          quantity: 2,
          price: {
            adjustment: {
              fixedPricePerUnit: {
                amount: "12.50"
              }
            }
          }
        }

        
      ]
    };
  

  return null;
}

And here is where it is called:

 const operations = input.cart.lines.reduce(
              /** @param {CartOperation[]} acc */
              (acc, cartLine) => {
                const plusOperation = optionallyAddExpandOperation(
                  cartLine
                );

                if (plusOperation) {
                  return [...acc, { expand: plusOperation }];
                }

                return acc;
              },
              []
            );

            return operations.length > 0 ? { operations } : NO_CHANGES;

I’ve looked at https://shopify.dev/docs/api/functions/reference/cart-transform/graphql#extension-targets

And it would seem to imply I can add quantities, not have them multiplied by the original cart line as show in the checkout screenshot.

Can someone help me out on this one?

1 Like

Did you ever find a solution for this? I’m running into the same issue where in some cases I don’t want the quantity to multiply by the base quantity.