App reviews, troubleshooting, and recommendations
I have a discount that applied in a order and it showing this details in the order detail in admin panel
I was trying to retrieve this detail from the graphql, the following is the approach I made
query ($numProducts: Int!, $cursor: String, $query: String!) { orders(first: $numProducts, after: $cursor, query: $query) { edges { node { createdAt lineItems(first: 20) { nodes { id } } } } pageInfo { hasNextPage endCursor } } }
I not sure how do I get it from graphql, do anyone have idea?
The `order` object includes connections to (order-level) `discountApplications` and `lineItems`. I'm not sure where the information you highlighted in the screen capture came from, but the following query shows how you can retrieve both the order-level and lineitem-level discount allocations.
{
"query": "
query getOrder($orderId: ID!) {
order(id: $orderId) {
id customer { id } discountCodes
discountApplications(first: 5) { edges { node {
...discountApplicationFields
} } }
lineItems(first: 50) { edges { node {
id quantity currentQuantity name sku
discountAllocations {
allocatedAmountSet { shopMoney { amount currencyCode } }
discountApplication { ...discountApplicationFields }
}
} } }
}
}
fragment discountApplicationFields on DiscountApplication {
index
allocationMethod
targetType
value {
__typename
... on MoneyV2 { amount currencyCode }
... on PricingPercentageValue { percentage }
}
}
",
"variables":{"orderId":"gid://shopify/Order/12345"}
}
The response will be like:
{
"data": {
"order": {
"id": "gid://shopify/Order/12345",
"customer": {"id": "gid://shopify/Customer/67890"},
"discountCodes": ["rwdlxjx9ak42l"],
"discountApplications": {
"edges": [
{
"node": {
"index": 0,
"allocationMethod": "ACROSS",
"targetType": "LINE_ITEM",
"value": { "__typename": "MoneyV2", "amount" : "20.0", "currencyCode": "USD" }
}
}
]
},
"lineItems": {
"edges": [
{
"node": {
"id": "gid://shopify/LineItem/111111",
"quantity": 2,
"currentQuantity": 1,
"name": "Widget - Deluxe",
"sku": "fbot-widget-002",
"discountAllocations": [
{
"allocatedAmountSet": {
"shopMoney": {"amount": "16.0", "currencyCode": "USD"}
},
"discountApplication": {
"index": 0,
"allocationMethod": "ACROSS",
"targetType": "LINE_ITEM",
"value": { "__typename": "MoneyV2", "amount" : "20.0", "currencyCode": "USD" }
}
}
]
}
},
{
"node": {
"id": "gid://shopify/LineItem/222222",
"quantity": 1,
"currentQuantity": 0,
"name": "Widget - Standard",
"sku": "fbot-widget-001",
"discountAllocations": [
{
"allocatedAmountSet": {
"shopMoney": {"amount": "4.0", "currencyCode": "USD"}
},
"discountApplication": {
"index": 0,
"allocationMethod": "ACROSS",
"targetType": "LINE_ITEM",
"value": { "__typename": "MoneyV2", "amount": "20.0", "currencyCode": "USD" }
}
}
]
}
}
]
}
}
}
}
We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024The Hydrogen Visual Editor is now available to merchants in Shopify Editions | Summer '...
By JasonH Sep 2, 2024