If the shop admin removes products from an order after it is created, the Orders API returns an empty array for the products.
Is there a way to view the product details as they were when the order was placed?
Hi Yoonsoo,
Looking into this one - can you confirm that you’re using the lineItems
field to try to get the product details after an order is edited? Also, can you share a query and a return where there’s an empty array for products (removing any sensitive data)?
Hi Liam,
Yes, I used the lineItems
field.
But, I need to correct myself. it’s not an empty array, actually null
.
Here are the query and the returned data with all fields masked as something
except for product
and a few others.
thank you.
Query - node.js, using @shopify/admin-api-client
export const getOrdersQuery = `#graphql
query getOrders($first: Int = 250, $after: String, $updatedFrom: String!) {
orders(first: $first, after:$after, query: $updatedFrom, sortKey: UPDATED_AT, reverse:true) {
nodes {
id
name
note
createdAt
currencyCode
returnStatus
displayFulfillmentStatus
displayFinancialStatus
cancelledAt
paymentTerms {
paymentSchedules {
nodes {
completedAt
}
}
}
returns(first: $first) {
nodes {
id
}
}
refunds {
id
createdAt
refundLineItems(first: $first) {
nodes {
quantity
lineItem {
id
}
}
}
}
customer {
email
}
fulfillments {
id
status
displayStatus
name
trackingInfo {
company
number
}
createdAt
deliveredAt
}
customAttributes {
key
value
}
lineItems(first: $first) {
nodes {
id
quantity
title
vendor
product {
tags
metafield(key: "product_id", namespace: "custom") {
key
value
}
}
variantTitle
discountedTotalSet {
shopMoney {
amount
currencyCode
}
}
}
}
subtotalPriceSet {
presentmentMoney {
amount
currencyCode
}
}
totalTaxSet {
presentmentMoney {
amount
currencyCode
}
}
totalPriceSet {
shopMoney {
amount
currencyCode
}
}
billingAddress {
address1
address2
city
province
countryCodeV2
name
phone
zip
}
shippingAddress {
address1
address2
city
province
countryCodeV2
name
phone
zip
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
`
Returned data
{
"id": "gid://shopify/Order/something",
"name": "something",
"note": null,
"createdAt": "something",
"currencyCode": "something",
"returnStatus": "something",
"displayFulfillmentStatus": "something",
"displayFinancialStatus": "something",
"cancelledAt": null,
"paymentTerms": null,
"returns": {
"nodes": [
{
"id": "gid://shopify/Return/something"
}
]
},
"refunds": [
{
"id": "gid://shopify/Refund/something",
"createdAt": "something",
"refundLineItems": {
"nodes": [
{
"quantity": 1,
"lineItem": {
"id": "gid://shopify/LineItem/something"
}
}
]
}
},
{
"id": "gid://shopify/Refund/something",
"createdAt": "something",
"refundLineItems": {
"nodes": [
{
"quantity": 1,
"lineItem": {
"id": "gid://shopify/LineItem/something"
}
},
{
"quantity": 2,
"lineItem": {
"id": "gid://shopify/LineItem/something"
}
}
]
}
}
],
"customer": {
"email": "something"
},
"fulfillments": [
{
"id": "gid://shopify/Fulfillment/something",
"status": "something",
"displayStatus": "something",
"name": "something",
"trackingInfo": [
{
"company": "something",
"number": "something"
}
],
"createdAt": "something",
"deliveredAt": null
}
],
"customAttributes": [],
"lineItems": {
"nodes": [
{
"id": "gid://shopify/LineItem/something",
"quantity": 2,
"title": "something",
"vendor": "something",
"product": null,
"variantTitle": "something",
"discountedTotalSet": {
"shopMoney": {
"amount": "something",
"currencyCode": "something"
}
}
},
{
"id": "gid://shopify/LineItem/something",
"quantity": 2,
"title": "something",
"vendor": "something",
"product": null,
"variantTitle": "something",
"discountedTotalSet": {
"shopMoney": {
"amount": "something",
"currencyCode": "something"
}
}
}
]
},
"subtotalPriceSet": {
"presentmentMoney": {
"amount": "something",
"currencyCode": "something"
}
},
"totalTaxSet": {
"presentmentMoney": {
"amount": "something",
"currencyCode": "something"
}
},
"totalPriceSet": {
"shopMoney": {
"amount": "something",
"currencyCode": "something"
}
},
"billingAddress": {
"address1": "something",
"address2": "something",
"city": "something",
"province": "something",
"countryCodeV2": "something",
"name": "something",
"phone": "something",
"zip": "something"
},
"shippingAddress": {
"address1": "something",
"address2": "something",
"city": "something",
"province": "something",
"countryCodeV2": "something",
"name": "something",
"phone": "something",
"zip": "something"
}
}
Hi again, from looking into this more, it does seem that once a product is deleted, its reference in the order’s line items becomes null.
To handle this situation, you can rely on the other fields available in the lineItems
object to gather information about the product as it was when the order was placed. These fields include:
- title: The title of the product at the time of order.
- quantity: The quantity of the product ordered.
- variantTitle: The title of the variant, if applicable.
- vendor: The vendor of the product.
- discountedTotalSet: The discounted total price for the line item.
Would these fields work for you as they contain the relevant information even if the product itself is not viewable?
Hi Liam,
Actually, I needed the product’s metafields and I wanted to check if the product being null
is correct.
But I found an alternative way.
I really appreciate your help!