Unexpected discounted_total_set values for Line Items in GraphQL

Highlighted
Tourist
7 0 0

I am switching some logic over from the REST API to the GraphQL API for processing Line Items, and I am seeing what for me are unexpected “discounted totals” in the GraphQL API. In my current logic using the REST API, I calculate the discounted line item total by subtracting the sum of the discount allocation amounts from the quantity * price of the line item.

 

In GraphQL, I thought I could skip that calculation and just use the “discounted_total_set” field on the Line Items since the docs state that this field is “The total line price after discounts are applied in shop and presentment currencies.”

 

However, in testing with sample orders, the “discounted_total_set” in GraphQL always seems to be the same as the “original_total_set,” even when there are discounts applied on the line item. These discounts do appear in the “discount_allocations” field in the GraphQL response.

 

What I am seeing in the GraphQL response:

discounted_total_set: <original undiscounted price

original_total_set: <same as discounted_total_set>

discounted_allocations: <does describe the discount amount I’m expecting, but this is not reflected in discounted_total_set>

 

Could someone help explain why discounted_total_set doesn’t seem to be reflecting the line item discount in the GraphQL Line Item response?

0 Likes
Shopify Staff
Shopify Staff
382 51 62

Hey @JeffTalbot,

 

This appears to be a line item discount vs order discount thing. I was able to replicate by applying a 10% off discount. discountedTotalSet and originalTotalSet were the same.

 

However, when I used a script to discount a specific line item, the discountedTotalSet and originalTotalSet were as expected (different).

 

This behaviour seems to be consistent with the REST API, except total_discounts_set (REST) is the total discount applied to the line item whereas discountedTotalSet (GraphQL) is the total line price after discounts are applied.

 

Try using LineItem.discountAllocations instead which returns the total discount regardless.

 

lineItems {
  edges {
    node {
      id
      title
      discountAllocations {
        allocatedAmountSet {
          shopMoney {
            amount
          }
        }
      }
    }
  }
}

 

0 Likes
Tourist
7 0 0

Thanks, @scottydont. So discountedTotalSet will only differ from originalTotalSet if a discount is applied directly to a line item and not via an order-level discount.

 

If that is the case, then in order to reliably calculate the cost of line items to the customer, should we always use discountAllocations to subtract from originalTotalSet in GraphQL and just ignore discountedTotalSet?

 

 

 

0 Likes
Shopify Staff
Shopify Staff
382 51 62

Hey @JeffTalbot,

 

That seems like the way to go. Let me know if you hit any issues.

0 Likes