I am looking for a way to identify the original and new items in an modified order. For example, an order is placed for a single item, [45-4-193]CFZ
. Before the item is shipped, the customer requests to change the item. Merchant swaps out the item for [45-4-092]CFZ
.
On a 1:1 swap, this is easy to identify with the following properties: currentQuantity
, refundableQuantity
, and quantity
; however, if the order contains more than one sku
, and the order is only changing one of the skus, then it becomes impossible to tease apart the original and newly added items. Here is an example of a response (1:1):
Order with single SKU
{
"data": {
"orders": {
"edges": [
{
"node": {
"edited": true,
"id": "gid://shopify/Order/5714985681074",
"name": "#9961688",
"createdAt": "2024-10-26T18:13:35Z",
},
},
"lineItems": {
"edges": [
{
"node": {
"currentQuantity": 0,
"refundableQuantity": 0,
"quantity": 1,
"sku": "[45-4-193]CFZ",
"originalUnitPriceSet": {
"shopMoney": {
"amount": "279.0"
},
"presentmentMoney": {
"amount": "279.0"
}
},
"taxLines": []
}
},
{
"node": {
"currentQuantity": 1,
"refundableQuantity": 1,
"quantity": 1,
"sku": "[45-4-092]CFZ",
"originalUnitPriceSet": {
"shopMoney": {
"amount": "199.0"
},
"presentmentMoney": {
"amount": "199.0"
}
},
"taxLines": []
}
}
]
},
"refunds": [
{
"createdAt": "2024-10-28T14:08:38Z",
"totalRefundedSet": {
"shopMoney": {
"amount": "0.0"
},
"presentmentMoney": {
"amount": "0.0"
}
},
"refundLineItems": {
"edges": [
{
"node": {
"quantity": 1,
"lineItem": {
"sku": "[45-4-193]CFZ",
"taxLines": []
}
}
}
]
},
"return": null
},
{
"createdAt": "2024-10-28T14:08:54Z",
"totalRefundedSet": {
"shopMoney": {
"amount": "80.0"
},
"presentmentMoney": {
"amount": "80.0"
}
},
"refundLineItems": {
"edges": []
},
"return": null
}
]
}
}
Order with multiple SKUs (the issue)
Here it gets complicated when there are more items in the order:
{
"data": {
"orders": {
"edges": [
{
"node": {
"id": "gid://shopify/Order/5747143278770",
"name": "#9962027",
"createdAt": "2024-11-15T18:54:15Z",
"displayAddress": {
},
"originalTotalPriceSet": {
"shopMoney": {
"amount": "959.7"
},
"presentmentMoney": {
"amount": "1349.52"
}
},
"shippingLine": null,
"lineItems": {
"edges": [
{
"node": {
"currentQuantity": 1,
"refundableQuantity": 1,
"quantity": 1,
"sku": "[45-4-060]", // THIS IS AN ORIGINAL ITEM
"originalUnitPriceSet": {
"shopMoney": {
"amount": "394.37"
},
"presentmentMoney": {
"amount": "554.56"
}
},
"taxLines": [
{
"priceSet": {
"shopMoney": {
"amount": "19.72"
},
"presentmentMoney": {
"amount": "27.73"
}
},
"title": "GST",
"ratePercentage": 5.0
},
{
"priceSet": {
"shopMoney": {
"amount": "39.34"
},
"presentmentMoney": {
"amount": "55.32"
}
},
"title": "QST",
"ratePercentage": 9.975
}
]
}
},
{
"node": {
"currentQuantity": 0,
"refundableQuantity": 0,
"quantity": 1,
"sku": "[45-4-097]CFZ", // THIS IS AN ORIGINAL ITEM, BUT IT WAS SWAPPED OUT
"originalUnitPriceSet": {
"shopMoney": {
"amount": "440.33"
},
"presentmentMoney": {
"amount": "619.19"
}
},
"taxLines": [
{
"priceSet": {
"shopMoney": {
"amount": "22.02"
},
"presentmentMoney": {
"amount": "30.96"
}
},
"title": "GST",
"ratePercentage": 5.0
},
{
"priceSet": {
"shopMoney": {
"amount": "43.92"
},
"presentmentMoney": {
"amount": "61.76"
}
},
"title": "QST",
"ratePercentage": 9.975
}
]
}
},
{
"node": {
"currentQuantity": 1,
"refundableQuantity": 1,
"quantity": 1,
"sku": "[45-4-201]RED", // THIS ITEM WAS ADDED AFTER THE ORIGINAL ORDER
"originalUnitPriceSet": {
"shopMoney": {
"amount": "114.91"
},
"presentmentMoney": {
"amount": "161.59"
}
},
"taxLines": [
{
"priceSet": {
"shopMoney": {
"amount": "5.74"
},
"presentmentMoney": {
"amount": "8.08"
}
},
"title": "GST",
"ratePercentage": 5.0
},
{
"priceSet": {
"shopMoney": {
"amount": "11.45"
},
"presentmentMoney": {
"amount": "16.12"
}
},
"title": "QST",
"ratePercentage": 9.975
}
]
}
}
]
},
"refunds": [
{
"createdAt": "2024-11-15T18:54:55Z",
"totalRefundedSet": {
"shopMoney": {
"amount": "0.0"
},
"presentmentMoney": {
"amount": "0.0"
}
},
"refundLineItems": {
"edges": [
{
"node": {
"quantity": 1,
"lineItem": {
"sku": "[45-4-097]CFZ",
"taxLines": [
{
"priceSet": {
"shopMoney": {
"amount": "22.02"
},
"presentmentMoney": {
"amount": "30.96"
}
},
"title": "GST",
"ratePercentage": 5.0
},
{
"priceSet": {
"shopMoney": {
"amount": "43.92"
},
"presentmentMoney": {
"amount": "61.76"
}
},
"title": "QST",
"ratePercentage": 9.975
}
]
}
}
}
]
},
"return": null
}
]
}
}
]
}
},
An exchange
Now, this is simple when the customer initiates an exchange (receives an item, sends it back to merchant) since we can look at the Return
object. For example:
{
"node": {
"id": "gid://shopify/Order/5677454753970",
"displayAddress": {
},
"originalTotalPriceSet": {
"shopMoney": {
"amount": "399.0"
},
"presentmentMoney": {
"amount": "399.0"
}
},
"shippingLine": {
"discountedPriceSet": {
"shopMoney": {
"amount": "0.0"
},
"presentmentMoney": {
"amount": "0.0"
}
},
"taxLines": []
},
"lineItems": {
"edges": [
{
"node": {
"currentQuantity": 0,
"refundableQuantity": 0,
"quantity": 1,
"sku": "[45-4-064|45-4-092]CFZ",
"originalUnitPriceSet": {
"shopMoney": {
"amount": "399.0"
},
"presentmentMoney": {
"amount": "399.0"
}
},
"taxLines": []
}
},
{
"node": {
"currentQuantity": 1,
"refundableQuantity": 1,
"quantity": 1,
"sku": "[45-4-197]",
"originalUnitPriceSet": {
"shopMoney": {
"amount": "119.0"
},
"presentmentMoney": {
"amount": "119.0"
}
},
"taxLines": []
}
},
{
"node": {
"currentQuantity": 1,
"refundableQuantity": 1,
"quantity": 1,
"sku": "[45-4-106]CFZ",
"originalUnitPriceSet": {
"shopMoney": {
"amount": "24.95"
},
"presentmentMoney": {
"amount": "24.95"
}
},
"taxLines": []
}
},
{
"node": {
"currentQuantity": 1,
"refundableQuantity": 1,
"quantity": 1,
"sku": "[45-4-176|45-4-237]",
"originalUnitPriceSet": {
"shopMoney": {
"amount": "139.0"
},
"presentmentMoney": {
"amount": "139.0"
}
},
"taxLines": []
}
}
]
},
"refunds": [
{
"createdAt": "2024-11-06T19:02:53Z",
"totalRefundedSet": {
"shopMoney": {
"amount": "116.05"
},
"presentmentMoney": {
"amount": "116.05"
}
},
"refundLineItems": {
"edges": [
{
"node": {
"quantity": 1,
"lineItem": {
"sku": "[45-4-064|45-4-092]CFZ",
"taxLines": []
}
}
}
]
},
"return": {
"exchangeLineItems": {
"edges": [
{
"node": {
"lineItem": {
"sku": "[45-4-197]",
"taxLines": []
}
}
},
{
"node": {
"lineItem": {
"sku": "[45-4-106]CFZ",
"taxLines": []
}
}
},
{
"node": {
"lineItem": {
"sku": "[45-4-176|45-4-237]",
"taxLines": []
}
}
}
]
}
}
}
]
}
},
Query
Here is the query I’ve been working with. Am I missing a node or another way to identify the state of the original and new order (don’t mind the double braces):
orders(first: 250") {{
edges {{
node {{
id
name
createdAt
displayAddress {{
name
address1
address2
city
country
provinceCode
zip
phone
}}
originalTotalPriceSet {{
shopMoney {{
amount
}}
presentmentMoney {{
amount
}}
}}
shippingLine {{
discountedPriceSet {{
shopMoney {{
amount
}}
presentmentMoney {{
amount
}}
}}
taxLines {{
priceSet {{
shopMoney {{
amount
}}
presentmentMoney {{
amount
}}
}}
title
ratePercentage
}}
}}
lineItems(first: 20) {{
edges {{
node {{
currentQuantity
refundableQuantity
quantity
name
sku
originalUnitPriceSet {{
shopMoney {{
amount
}}
presentmentMoney {{
amount
}}
}}
taxLines {{
priceSet {{
shopMoney {{
amount
}}
presentmentMoney {{
amount
}}
}}
title
ratePercentage
}}
}}
}}
}}
refunds(first: 20) {{
createdAt
totalRefundedSet {{
shopMoney {{
amount
}}
presentmentMoney {{
amount
}}
}}
refundLineItems(first: 20) {{
edges {{
node {{
quantity
lineItem {{
sku
taxLines(first: 20) {{
priceSet {{
shopMoney {{
amount
}}
presentmentMoney {{
amount
}}
}}
title
ratePercentage
}}
}}
}}
}}
}}
return {{
exchangeLineItems(first: 20, includeRemovedItems: true) {{
edges {{
node {{
lineItem {{
sku
taxLines(first: 20) {{
priceSet {{
shopMoney {{
amount
}}
}}
title
ratePercentage
}}
}}
}}
}}
}}
}}
}}
}}
}}
}}
}}";
Why do I need this?
I am writing invoices and need to correctly enter in the original order state, and on the refund invoice be able to reflect those changes