How to get all products with discount with GraphQL or REST

mtonev
Tourist
7 0 2

Hi,

I'm trying to retrieve all shop products having a discount(I think that 'compare_at_price' should be bigger than 'price') using GraphQL or REST. How to do that?

 

Milen

SBD_
Shopify Staff
Shopify Staff
1071 143 189

Hey @mtonev 

 

I'm not sure there's a simple query for this. One approach would be to pull all the products and then compare them. Another approach would be to create an automatic collection with the condition "compare at price greater than 0", and then pull products in that collection (you'd also need to confirm compare_at was > price, but the collection should reduce the amount of work/calls).

0 Likes
mtonev
Tourist
7 0 2

Thank you for your answer!

I think that I kind of found some solution. I'm making the following query:

 

  products(first: 5, query:"is_price_reduced:true") { 
    edges{
      cursor
      node
      {
        id
        title
        description
	totalVariants
        tags
        variants(first:10)
        {
          edges
          {
            node
            {
              availableForSale
              id
              compareAtPrice
              price
              title
            }
          }
        }
      }
    }
  }

The problem is that "is_price_reduced" is not actually checking if "compareAtPrice" is greater than "price". So if I save "compareAtPrice" with any value, even with "0.00" the query will still return a result.

If there is no "compareAtPrice" value query works fine.

Is this a bug?  

SBD_
Shopify Staff
Shopify Staff
1071 143 189

Didn't realise you could filter by is_price_reduced - nice find!

 

I looked into this column, is returns true if any of the product's variants have a compare_at price set. So I guess you'll still need to double check compare at price is < price.

0 Likes
mtonev
Tourist
7 0 2

Than the filter naming "is_price_reduced" is wrong OR you can easily fix it if you don't allow "price" field to be greater than "compareAtPrice"  which will comply with the "Compare at price" field tooltip:

"To show a reduced price, move the product's original price into Compare at price. Enter a lower value into Price."

 

How can I submit a bug?

0 Likes
SBD_
Shopify Staff
Shopify Staff
1071 143 189
Thanks I've reported this - the team plans to implement the validation for compare_at_price to be always greater than price.

mtonev
Tourist
7 0 2

Thank you!

0 Likes