API issue: CheckoutLineItemsReplace adds a duplicate LineItem when increasing quantity beyond 1

Solved
m_i
New Member
2 1 0

We have digital and physical variants in our store. Currently, clients can only but 1 copy of digital product per checkout, but we're changing that to allow them to order more.

 

I'm experiencing an issue with the CheckoutLineItemsReplace mutation. It works perfectly fine for physical goods, but when asking to increase a quantity of a digital item beyond 1, Shopify ends up creating an extra LineItem in the checkout.

 

Here's an example.

 

1. FetchCheckout to get the current checkout, here's part of the response

 

 

{
	"node": {
		"id": "Z2lkOi8vc2hvcGlmeS9DaGVja291dExpbmVJdGVtLzQwMDI0OTgxNTY5Njk2MD9jaGVja291dD0xZDExOTY1MDg4OWExMGQ0NzFmODVjOGNhODYyMTJmMw==",
           // gid://shopify/CheckoutLineItem/400249815696960?checkout=1d119650889a10d471f85c8ca86212f3
		"quantity": 1,
		"variant": {
			"id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC80MDAyNDk4MTU2OTY5Ng==",
                   // gid://shopify/ProductVariant/40024981569696
			"product": {
				"id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzY3MTgyNjgyNzY4OTY=",
                       // gid://shopify/Product/6718268276896
}}}}

 

 

 


2. Let's increase the quantity to 2 using CheckoutLineItemsReplace  mutation

 

Query starts like

 

 

mutation CheckoutLineItemsReplace($lineItems: [CheckoutLineItemInput!]!, $checkoutId: ID!) { checkoutLineItemsReplace(lineItems: $lineItems, checkoutId: $checkoutId) {

 

 

With the lineItems variable containing

 

 

{"0": {
        "quantity": 2,
        "variantId": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC80MDAyNDk4MTU2OTY5Ng=="
        // gid://shopify/ProductVariant/40024981569696
    }}

 

 

 

3. Ask the API to return the checkout again. Suddenly, there's an extra lineitem!

 

The lineItems now look like this:

 

 

{
	"0": {
		"node": {
			"id": "Z2lkOi8vc2hvcGlmeS9DaGVja291dExpbmVJdGVtLzQwMDI0OTgxNTY5Njk2MD9jaGVja291dD0xZDExOTY1MDg4OWExMGQ0NzFmODVjOGNhODYyMTJmMw==",
                  // gid://shopify/CheckoutLineItem/400249815696960?checkout=1d119650889a10d471f85c8ca86212f3
			"quantity": 1,
			"variant": {
				"id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC80MDAyNDk4MTU2OTY5Ng==",
                     // gid://shopify/ProductVariant/40024981569696
				"product": {
					"id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzY3MTgyNjgyNzY4OTY=",
                     // gid://shopify/Product/6718268276896
        }}}},
	"1": {
		"node": {
			"id": "Z2lkOi8vc2hvcGlmeS9DaGVja291dExpbmVJdGVtLzQwMDI0OTgxNTY5Njk2MT9jaGVja291dD0xZDExOTY1MDg4OWExMGQ0NzFmODVjOGNhODYyMTJmMw==",
                  // gid://shopify/CheckoutLineItem/400249815696961?checkout=1d119650889a10d471f85c8ca86212f3
			"quantity": 1,
			"variant": {
				"id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC80MDAyNDk4MTU2OTY5Ng==",
                      // gid://shopify/ProductVariant/40024981569696
				"product": {
					"id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzY3MTgyNjgyNzY4OTY=",
                      // gid://shopify/Product/6718268276896
        }}}}
}

 

 

 

To sum it up, after the CheckoutLineItemsReplace we got a second LineItem, and the quantity is split between the two.

The second LineItem has the same Product ID and the same ProductVariant ID. The only difference is in the CheckoutLineItem ID, which differs in a single digit - "gid://shopify/CheckoutLineItem/400249815696960?..." vs ""gid://shopify/CheckoutLineItem/400249815696961?...". Notice the 0 and 1 at the end of the ID?

 

In fact, if I change the quantity to 5, and issue a similar CheckoutLineItemsReplace mutation, with same variant ID but quantity being 5, the result would be:

 

CheckoutLineItem/400249815696960 - 4 qty

CheckoutLineItem/400249815696961 - 1 qty

 

In other words, 1 piece is always split out into a different checkout line item.

 

My questions are:
1. Why is this happening?

2. How can I disable this if it can be disabled?

 

Any help would be much appreciated, thanks in advance. If no one knows the answer, maybe you have a guess as to how to get to the bottom of it?

 

 

Accepted Solution (1)
m_i
New Member
2 1 0

This is an accepted solution.

Turns out this happened because of a multibuy promotion. Buy 1 get 50% off another one.

This means that if quantity > 1, then one of the items was with a discount applied to it, which then results in an extra CheckoutLineItem.

Leaving this here in hopes of saving someone a few hours of time.

View solution in original post

Reply 1 (1)
m_i
New Member
2 1 0

This is an accepted solution.

Turns out this happened because of a multibuy promotion. Buy 1 get 50% off another one.

This means that if quantity > 1, then one of the items was with a discount applied to it, which then results in an extra CheckoutLineItem.

Leaving this here in hopes of saving someone a few hours of time.