A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hello, I've made the next test order where I order 4 products, each 120€ with a total discount of 48€ (so each product costs 108€). Afterwards I've made a return, but in the field "withCodeDiscountedTotalPriceSet" I get the value of 120€ instead of 108€:
The definition of that field is:
The total line price after all discounts on the line item, including both line item level discounts and code-based line item discounts, are applied
I know the discount I've applied is not to the line but to the whole order, but if I wanna see how much should I return the customer for each line, it should have in mind the discounts of the whole order.
On the other hand, if I make the query to get the SuggestedRefund I get 324 (108€* 3 returned products), which is correct, but I don't get how much it is for each line.
Am I doing something wrong? Should I check another field? Or is the API not working as intended?
Thanks.
Solved! Go to the solution
This is an accepted solution.
Hi @SergioB2X - for discounts that are applied on a whole order (including custom discounts applied in Draft orders that are then converted into "real orders"), they won't be reflected in line item's pricing. Since the discount price applies across the whole order (even if there is only one line item in the order), it's considered to be an " across"-type discount allocation. This means that with the way our discount feature currently works, the discount isn't applied to the discountedUnitPriceSet field on each line item or on the withCodeDiscountedTotalPriceSet field under the returnlineitem object. (A bit more info on the different types of discount allocation methods here)
For cases like this, you can find the discounted amount for a line item on an order by using GraphQL. This is done by querying the discountAllocations field under the lineitems object. An example query might look like this:
{
order(id:"gid://shopify/Order/12345") {
id
lineItems(first: 10) {
edges {
node {
id
discountAllocations {
allocatedAmountSet {
shopMoney {
amount
currencyCode
}
}
}
}
}
}
}
}
This doesn't show the full discounted cost of the line item, but does show the value of the discount applied to original price of the line item. The original price of the line item can be queried through the returnlineitem object like you had shared in your initial post or by adding something like this to your query under the standard lineitems resource:
originalUnitPriceSet {
shopMoney {
amount
currencyCode
}
That said, I'm going to pass along your feedback on this along to our product team. I can't guarantee anything, but it would be helpful to include a field for the discounted price of a line item out of the box, rather than just the value of the discount applied to the line item in cases like this. Hope this helps - let us know if we can clarify anything on our end.
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
This is an accepted solution.
Hi @SergioB2X - for discounts that are applied on a whole order (including custom discounts applied in Draft orders that are then converted into "real orders"), they won't be reflected in line item's pricing. Since the discount price applies across the whole order (even if there is only one line item in the order), it's considered to be an " across"-type discount allocation. This means that with the way our discount feature currently works, the discount isn't applied to the discountedUnitPriceSet field on each line item or on the withCodeDiscountedTotalPriceSet field under the returnlineitem object. (A bit more info on the different types of discount allocation methods here)
For cases like this, you can find the discounted amount for a line item on an order by using GraphQL. This is done by querying the discountAllocations field under the lineitems object. An example query might look like this:
{
order(id:"gid://shopify/Order/12345") {
id
lineItems(first: 10) {
edges {
node {
id
discountAllocations {
allocatedAmountSet {
shopMoney {
amount
currencyCode
}
}
}
}
}
}
}
}
This doesn't show the full discounted cost of the line item, but does show the value of the discount applied to original price of the line item. The original price of the line item can be queried through the returnlineitem object like you had shared in your initial post or by adding something like this to your query under the standard lineitems resource:
originalUnitPriceSet {
shopMoney {
amount
currencyCode
}
That said, I'm going to pass along your feedback on this along to our product team. I can't guarantee anything, but it would be helpful to include a field for the discounted price of a line item out of the box, rather than just the value of the discount applied to the line item in cases like this. Hope this helps - let us know if we can clarify anything on our end.
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