FROM CACHE - nl_header

How do I get the discount that applies to a product

iO-Rotterdam
Shopify Partner
9 0 5

We use the Storefront API to get the products on our Shopify environment to render it on our headless website and we wish to render the discount value on the website itself. For example, if a product is 20% off, we wish to show "20% off" and a decreased price to our customers to make it clear there is a sale going on.

 

 

The problem is, when we get the product data from the Storefront API, it doesn't show any field which resembles any relation to an active sale. To tackle this issue, we thought about writing a query on the Admin API (as Discounts are not readable from the Storefront API) to get all active sales and then map those values to our products. For this we wrote the query below. 2 issues rise here; firstly the query to filter the status to only ACTIVE doesn't work. The other issue is that it demands a lot of points to get the sales that are going on, while a sale which involves more than 10 products won't even show all products.

 

{
  automaticDiscountNodes(first: 10, query: "status:ACTIVE") {
    nodes {
      automaticDiscount {
        __typename
        ... on DiscountAutomaticBasic {
          status
          customerGets {
            items {
              __typename
              ... on DiscountCollections {
                collections(first: 10) {
                  nodes {
                    id
                  }
                }
              }
              ... on DiscountProducts {
                products(first: 10) {
                  nodes {
                    id
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Therefor my question exists in 2 parts.

  1. Is there a way to get the discounts per product?
  2. If not, what is the most efficient workaround?
0 ANTWOORDEN 0