Issue with different discount prices in graphql

Hi all,

Im having a bit of trouble with getting the discounted price of a line item of an order. By discounted price I mean the effective price the customer actually pays for each unit. There are a couple different fields available, and what I want is the real discounted per unit price after all discounts have been applied, the price that the customer would actually pay and see on the invoice.

According to the documentation

discountedUnitPriceAfterAllDiscountsSet:
The approximate unit price of the line item in shop and presentment currencies. This value includes discounts applied to refunded and removed quantities.

discountedUnitPriceSet:
The approximate unit price of the line item in shop and presentment currencies. This value includes line-level discounts and discounts applied to refunded and removed quantities. It doesn’t include order-level or code-based discounts.

So to me the discountedUnitPriceAfterAllDiscountsSet should be in all cases contain the “most” discounted value and thereby be the “real” price that is also displayed on the invoice. However this doesnt’ always appear to be the case.

"lineItem": {
                  "sku": "01.097287",
                  "discountedUnitPriceAfterAllDiscountsSet": {
                    "presentmentMoney": {
                      "amount": "10.97"
                    }
                  },
                  "discountedUnitPriceSet": {
                    "presentmentMoney": {
                      "amount": "10.96"
                    }
                  },
                  "originalUnitPriceSet": {
                    "presentmentMoney": {
                      "amount": "12.9"
                    }
                  }
                }

How can it be that in this case the discountedUnitPriceAfterAllDiscountsSet is greater than the discountedUnitPriceSet, worse still the invoice shows the 10.96 price instead of the 10.97 price?

This of course makes it a bit difficult to figure out whats going on and to ensure that in the end the two totals match.

Cheers
Gary

1 Like

Hi Gary ,

The discrepancy between discountedUnitPriceAfterAllDiscountsSet and discountedUnitPriceSet could be due to the way discounts are applied and calculated in Shopify. Here’s a breakdown:

  1. discountedUnitPriceSet: This field includes line-level discounts and discounts applied to refunded and removed quantities. It excludes order-level or code-based discounts.
  2. discountedUnitPriceAfterAllDiscountsSet: This field includes all discounts, including order-level and code-based discounts, applied to refunded and removed quantities.

The issue arises because the invoice might display the discountedUnitPriceSet value instead of the discountedUnitPriceAfterAllDiscountsSet. This could happen if the invoice generation logic prioritizes line-level discounts over order-level discounts.

Steps to Debug and Resolve

  1. Verify Discount Applications: Use the discountApplications field on the order or line item to inspect all applied discounts. This will help you understand which discounts are contributing to the final price.
  2. Check Invoice Logic: If the invoice is showing the discountedUnitPriceSet value, ensure that the logic generating the invoice is using the correct field (discountedUnitPriceAfterAllDiscountsSet) for the final discounted price.
  3. Recalculate Discounts: If you suspect that the discounts are not being applied correctly, you can use the orderEditAddLineItemDiscount mutation to adjust the discounts on the line item.
    Hope this helps!

Hi Liam,

Thanks for your post.

Its a little deeper than that unfortunately. The prices do not reflect the price that is shown in the order.

Here a screenshot of the order line from my original posting (second code block).

As you can see the original unit price is 12.90 in originalUnitPriceSet. in the image is 10.96, which I assume would be the discountedUnitPriceSet, so where does the 10.97 come from? Well if I take the original price subtract 15% then I end up with 10.965 rounded it would be 10.97 which would give me the discountedUnitPriceAfterAllDiscountsSet.

So, the question is where or how did Shopify arrive at 10.96 instead of 10.97? Does one round down and the other round up? What I want is the exact value (field) that is used on the Order page, always. If I try to calculate it myself then I will end up with a discrepancy as in this case, and I can’t explain why there is a discrepancy especially since there is only one discount being applied.

I would be very grateful if you can tell me the exact math to use to always arrive at exactly the same unit price value that is actually charged to the customer.

Cheers,
Gary

I’ve included some more information from the line item to try and figure this out, but even from the order.json its pretty much impossible to land at the same price that is shown on the orders page using any math that I know or at least remember from University.

"lineItem": {
                  "sku": "01.097287",
                  "currentQuantity": 10,
                  "discountedUnitPriceAfterAllDiscountsSet": {
                    "presentmentMoney": {
                      "amount": "10.97"
                    }
                  },
                  "discountedUnitPriceSet": {
                    "presentmentMoney": {
                      "amount": "10.96"
                    }
                  },
                  "discountedTotalSet": {
                    "presentmentMoney": {
                      "amount": "109.65"
                    }
                  },
                  "originalTotalSet": {
                    "presentmentMoney": {
                      "amount": "129.0"
                    }
                  },
                  "discountAllocations": [
                    {
                      "allocatedAmountSet": {
                        "presentmentMoney": {
                          "amount": "19.35"
                        }
                      },
                      "discountApplication": {
                        "index": 2,
                        "targetType": "LINE_ITEM",
                        "targetSelection": "EXPLICIT",
                        "allocationMethod": "ACROSS",
                        "value": {
                          "__typename": "PricingPercentageValue"
                        }
                      }
                    }
                  ]
                }

order.json

"price": "12.90",
"price_set": {
"shop_money": {
"amount": "12.90",
"currency_code": "CHF"
},
"presentment_money": {
"amount": "12.90",
"currency_code": "CHF"
}
},
"product_exists": true,
"product_id": 9046004302128,
"properties": [],
"quantity": 10,
"requires_shipping": true,
"sku": "01.097287",
"taxable": true,
"title": "Neckwear THERMO PERFORMER 0°C – 10°C, olive",
"total_discount": "19.35",
"total_discount_set": {
"shop_money": {
"amount": "19.35",
"currency_code": "CHF"
},
"presentment_money": {
"amount": "19.35",
"currency_code": "CHF"
}
},

Any way I do the math, I come out with a unit price of 10.965. Per unit discount is 1.935. 12.90 - 1.935 = 10.965 unit price, rounded to 2 decimal places is 10.97 * 10 = 109.70 not 109.60. If the discount was not rounded then we would come up to 109.65 as shown in the discounted total set, but on the order page we have 109.60.

Looking forward to hearing from you @Liam-Shopify

Cheers,
Gary

1 Like