Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

No able to get calculatedLineItem of specific item in order to update order.

No able to get calculatedLineItem of specific item in order to update order.

vikasranjan
Shopify Partner
12 0 1

Hi I am trying to update an item in the order. So I am using this mutation

 

mutation ($id: ID!) {
                orderEditBegin(id: $id){
                    calculatedOrder{
                        id
                        lineItems(first:10) {
                            edges {
                              node {
                                id
                                quantity
                              }
                            }
                        }
                    }
                    userErrors {
                      field
                      message
                    }
                }
            }

Is there a way to pass itemID to get the calculatedLineItemID of a specific line item?

 

Replies 3 (3)

ShopifyDevSup
Shopify Staff
1453 239 535

Hey @vikasranjan - you should be able to do this using the OrderEditAddVariant mutation - once you add a new item to the order, it should automatically re-calculate the order. The orderEditBegin mutation is just used to trigger the order editing process - sort of like a failsafe so that orders aren't edited by mistake, if that makes sense. The only variable that is supported by that mutation is the order ID.

If you needed to remove an item from an order in addition to adding a new item, you can use the OrderEditSetQuantity mutation. Once the edits are complete you can then use the OrderEditCommit mutation to finalize the edit. 

Hope this helps - let us know if we can clarify anything further for you. 

 

Al | Shopify Developer Support.

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

ChrisNguyen
Shopify Partner
15 0 1

I know the OrderEditSetQuantity mutation but it needs a "ID of the calculated line item to edit" but I am confused about how to get this ID?

Shopicial - Community forum.
Xenforum - Customer Support forum.

AlexMinza
Shopify Partner
16 0 9

Agree, this is really confusing and poorly documented on the Shopify side. Took some time and experimenting to figure it out.

 

Use the original order line items IDs - they will look like gid://shopify/LineItem/12345678901234 and change to gid://shopify/CalculatedLineItem/12345678901234

 

Get original order line items:

 

query Order {
    order(id: "gid://shopify/Order/1234567890123") {
        fulfillmentOrders(first: 250) {
            nodes {
                lineItems(first: 250) {
                    nodes {
                        id
                        totalQuantity
                        sku
                        productTitle
                        lineItem {
                            id
                        }
                    }
                }
            }
        }
    }
}
{
    "data": {
        "order": {
            "fulfillmentOrders": {
                "nodes": [
                    {
                        "lineItems": {
                            "nodes": [
                                {
                                    "id": "gid://shopify/FulfillmentOrderLineItem/12345678901234",
                                    "totalQuantity": 2,
                                    "sku": "1234567890",
                                    "productTitle": "Product Title",
                                    "lineItem": {
                                        "id": "gid://shopify/LineItem/12345678901234"
                                    }
                                }
                            ]
                        }
                    }
                ]
            }
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost": 278,
            "actualQueryCost": 6,
            "throttleStatus": {
                "maximumAvailable": 2000,
                "currentlyAvailable": 1994,
                "restoreRate": 100
            }
        }
    }
}

 

Use returned lineItem id as CalculatedLineItem id to set new quantity:

 

mutation OrderEditSetQuantity {
    orderEditSetQuantity(
        id: "gid://shopify/CalculatedOrder/123456789012"
        lineItemId: "gid://shopify/CalculatedLineItem/12345678901234"
        quantity: 2
    ) {
        calculatedLineItem {
            id
            quantity
        }
        calculatedOrder {
            id
        }
        userErrors {
            field
            message
        }
    }
}