Compare at price required for graphql 2020-04 Admin api

Solved
Highlighted
New Member
2 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!

2 Likes
Highlighted
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.

0 Likes
Highlighted
Shopify Partner
520 38 109

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.

0 Likes
Highlighted
New Member
2 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."
        }
      ]
0 Likes
Highlighted
Shopify Partner
520 38 109

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

0 Likes
Highlighted
Shopify Partner
43 1 16

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.

0 Likes
Highlighted
Shopify Partner
43 1 16

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.

1 Like