FROM CACHE - en_header

Compare at price required for graphql 2020-04 Admin api

Solved
abdullah_amin
Shopify Partner
3 0 2

Hello, the api version before 2020-04 allows price to be updated while keeping compare at price less than price.

So for example if I have a product whose price is 2400 then I can set the compare at price for that product to be 0.

This helps me to check if compare at price is greater than price then I consider that product is on sale and vice versa.

But in 2020-04 graphql api for updating product variant price we cannot update compare at price less than or equal to price, if this condition is met then all products on my website would be set on SALE. 

Can you please help me with this query, thank you!

Accepted Solution (1)

Accepted Solutions
timd_mackey
Shopify Partner
52 1 25

This is an accepted solution.

I've changed all my compare_at_price's from to null with no ill effects.

You may want to go through your code and make sure that you don't have any logic that depends on the compare_at_price equalling zero. Unless you've customized your code though, the default logic is to do a greater than comparison between compare_at_price and price, and null values automatically get converted to zero when doing a math comparison in liquid or javascript.

View solution in original post

Replies 10 (10)
TomaszRunowicz
New Member
1 0 0

Hi @abdullah_amin we have got same problem with API 2020-04 - so far we switched back to API 2020-01 but we don't know how long this API will be available so @Shopify please advice.

Greg_Kujawa
Shopify Partner
1023 84 269

Why not just set the "compare at" value the exact same as the price? That would also logically indicate the item isn't on sale, right? That's how we have things setup.

abdullah_amin
Shopify Partner
3 0 2

@Greg_Kujawa One cannot set price and compare at price same. If one does so then response sent from api is 

 "userErrors": [
        {
          "field": [
            "compareAtPrice"
          ],
          "message": "Compare at price needs to be higher than Price."
        }
      ]
Greg_Kujawa
Shopify Partner
1023 84 269

Hmm, seems like a breaking change in the new API versions for sure.

timd_mackey
Shopify Partner
52 1 25

Just ran into this today with some scripts I run. Looks like it's a breaking change listed in the update for API 2020-04.

I have a vague recollection of relying on the ability to set the compare_at_price to zero for some reason, but I can't recall why. I'm going to start setting the value to null instead and cross my fingers! A greater than/less than comparison should still work on a null value when comparing price with compare_at_price (used to detect if an item is on sale), so I don't think it will break anything.

timd_mackey
Shopify Partner
52 1 25

This is an accepted solution.

I've changed all my compare_at_price's from to null with no ill effects.

You may want to go through your code and make sure that you don't have any logic that depends on the compare_at_price equalling zero. Unless you've customized your code though, the default logic is to do a greater than comparison between compare_at_price and price, and null values automatically get converted to zero when doing a math comparison in liquid or javascript.

Laurentiu_Gheor
Shopify Partner
9 0 3

Hi

I have the same issue: I need compare_at_price to be set as 0 becaouse I have a collection with products NOT on sale defined as "compare at price = 0" because I don't have an alternative to compare to "null"

Any suggestions how to create such a collection to include only products without discount?

 

sam12341
Tourist
13 0 3

did you ever find a work around? I've been using the exact same business logic RE not on sale and have yet to find a solution. 

 

abdullah_amin
Shopify Partner
3 0 2

@sam12341 See the accepted answer.

In short, what you can do is to change compare_at_price from to null 

sam12341
Tourist
13 0 3

Yeah, but you can't use Null as a filter in a Smart Collection.