orderEditSetQuantity mutation doesn't allow zero quantities

Solved

orderEditSetQuantity mutation doesn't allow zero quantities

keiraarts
Shopify Partner
55 8 11

Shopify has a mutation to edit a line item quantity but it only supports increasing quantities of product.

Adjust the line item quantity to add an additional gift wrapping service to the order using the orderEditSetQuantity mutation. In the input, include the order id, lineItemId, and the new quantity value that you want to set. In the response, request the ID and quantity of the line items to verify that it was updated correctly.


https://shopify.dev/api/examples/order-editing#edit-line-item-quantity

By providing a quantity of zero when using this mutation, the calculatedOrder object returns the original order without decreasing the order quantity. The documentation for the API says any negative quantities are not a valid input, but technically inputting zero should still decrease a variant's fulfillable quantity.

The ideal use-case here is to replace one of the purchased products with a different variant.

Head of space operations on the Shopify moon-base.
Building orderediting.com, viaGlamour.com, magicsoaps.ca
Accepted Solution (1)
keiraarts
Shopify Partner
55 8 11

This is an accepted solution.

You are right. When the order is no longer in the original processing state my query won't decrease the line item count, but if the order is fulfilled or pending I can increase it. I didn't think to A/B test the order status Graham! I owe you!

Head of space operations on the Shopify moon-base.
Building orderediting.com, viaGlamour.com, magicsoaps.ca

View solution in original post

Replies 7 (7)

keiraarts
Shopify Partner
55 8 11

Can I bump this question to a Shopify engineer / staff?

Head of space operations on the Shopify moon-base.
Building orderediting.com, viaGlamour.com, magicsoaps.ca

GrahamS
Shopify Staff (Retired)
193 37 55

Hello @keiraarts ,

 

I took a look at this, but couldn't replicate what you describe in my own client. Setting the quantity of a calculatedLineItem to 0 removed the product from my order entirely:

 

08-18-k6x46-slrgy

08-20-r8g2n-u4ok9

 

I couldn't replicate a situation where my input (aside from negative values) was rejected and set to the previous default value in the returning calculatedOrder. I could take a look at an x-request-id from your headers if you are continuing to encounter this to see what might be happening, though.

To learn more visit the Shopify Help Center or the Community Blog.

keiraarts
Shopify Partner
55 8 11

I'm comparing our queries but I don't think I'm doing anything different. 

Super strange; my request ID is f536770633853481851d0a6ae9c4ff49

I'll give you my queries here too.

fragment PresentmentMoneyFields on MoneyV2 {
  amount
  currencyCode
}

fragment CalculatedOrderFields on CalculatedOrder {
  id
  committed
  totalPriceSet {
    presentmentMoney {
      ...PresentmentMoneyFields
    }
  }
  totalOutstandingSet {
    presentmentMoney {
      ...PresentmentMoneyFields
    }
  }
  lineItems(first: 10) {
    edges {
      node {
        id
        sku
        quantity
      }
    }
  }
  originalOrder {
    id
    lineItems(first: 10) {
      edges {
        node {
          id
          sku
          quantity
          originalUnitPriceSet {
            presentmentMoney {
              amount
              currencyCode
            }
          }
        }
      }
    }
  }
}

mutation decreaseLineItemQuantityDemo($id: ID!, $lineItemId: ID!, $quantity: Int!) {
  orderEditSetQuantity(id: $id, lineItemId: $lineItemId, quantity: $quantity) {
    calculatedOrder {
      ...CalculatedOrderFields
    }
    calculatedLineItem {
      id
      quantity
    }
    userErrors {
      field
      message
    }
  }
}

 

{
"id": "gid://shopify/CalculatedOrder/13634765006",
"lineItemId": "gid://shopify/CalculatedLineItem/9965111378126",
"quantity": 0
}

 
8cd2d669978da2fccbf9f00562c94d51.png

Head of space operations on the Shopify moon-base.
Building orderediting.com, viaGlamour.com, magicsoaps.ca
GrahamS
Shopify Staff (Retired)
193 37 55

@keiraarts 

 

The query looks good at a glance, so I would suppose that there's another component of the order here that's preventing the mutation from reducing the quantity of the item. Are you able to run the query against your shop on orders that have different fulfillment statuses for the line item you are trying to modify? My first assumption would be that there's a fulfillment state preventing a quantity reduction, but I'm running the logs at the moment to see what else might be happening.

To learn more visit the Shopify Help Center or the Community Blog.

keiraarts
Shopify Partner
55 8 11

This is an accepted solution.

You are right. When the order is no longer in the original processing state my query won't decrease the line item count, but if the order is fulfilled or pending I can increase it. I didn't think to A/B test the order status Graham! I owe you!

Head of space operations on the Shopify moon-base.
Building orderediting.com, viaGlamour.com, magicsoaps.ca
SrikalyanBurra
Shopify Partner
1 0 0

Hi! there is a peculiar case where its failing.

In my usecase i do 2 kinds of syncs with shopify. Orders placed on my system i upsync/create them on shopify(using 2023-07 rest api). for items placed on shopify i downsync and create corresponding orders in my system.

your solution is working for downsync but NOT upsync. 

For downsynced orders when i wish to modify quantities(including qty=0) i am smoothly able to. BUT for orders upsynced from my platform, i am unable to modify quantity to 0. FYI other than qty=0 other quantity modifications are working.

kindly let me know if you have a solution.

keiraarts
Shopify Partner
55 8 11

If you have a minute, I get periodic Shopify internal service errors when changing quantity of items. The changes go through but the request doesn't seem to return any objects. Do you get to see the cause of the internal service response? e5394c96-99de-4e3a-851b-531f8a6075f9

Head of space operations on the Shopify moon-base.
Building orderediting.com, viaGlamour.com, magicsoaps.ca