Get an order's discount amount using Storefront API

AbdallahAbis
Tourist
5 1 0

I'm working on a JamStack eCommerce website using gatsby and Shopify. I have been able to fetch a customer's orders using storefront API, the issue I'm facing is that I couldn't get the discount amount on the order. (Custom discount) or any other discount.

Screen Shot 2021-08-20 at 17.05.52.png

I'm using this query to get orders

query GetCustomerPastOrders($customerAccessToken: String!){
    customer(customerAccessToken:$customerAccessToken) {
      orders(first: 100) {
        edges {
          node {
            ...
          }
        }
      }
    }
  }

 

But  I couldn't find a field on the storefront API that returns the discount amount. am I missing something?

 

Thanks in advance.

Replies 3 (3)
csam
Shopify Staff
Shopify Staff
267 40 43

Hi @AbdallahAbis 

I was able to find the discount amount as part of the line item in discountAllocations. Here's an example - 

 

{
  customer(customerAccessToken: "973532e1af12ceef4da6f614004340ff") {
    orders(first: 100) {
      edges {
        node {
          id
          lineItems(first: 20) {
            edges {
              node {
                discountAllocations {
                  allocatedAmount {
                    amount
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

 

CS | API Support @ Shopify 
 - Was my reply helpful? Click Like to let me 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

AbdallahAbis
Tourist
5 1 0

Thank you for your response @csam,

unfortunately, I was looking to get the order-level discount.

I was able to do so by doing

 

{
  customer {
    orders {
      edges {
        node {
          discountApplications {
            edges {
              node {
                value {
                  ... on MoneyV2 {
                    amount
                  }
                  ... on PricingPercentageValue {
                    percentage
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

 

 

That does return the discount applied either if it's a percentage or an amount, but the issue again is I can't get the subtotal before any discounts/duties are applied. I used

 

currentSubtotalPrice => $36,540.00

 

it still includes the custom order-level discount in it even though the docs say :

Order.currentSubtotalPrice: MoneyV2!

The subtotal of line items and their discounts, excluding line items that have been removed. Does not contain order-level discounts, duties, shipping costs, or shipping discounts. Taxes are not included unless the order is a taxes-included order.

, normally it should return

 

$36,540.00 + $24,360.00 // should exclude the custom order-level discount

 

 

adamatronix
Shopify Partner
10 0 0

Raising this, since I don't think you can get the discount code applied, just the value.