variant.compare_at_price

Shopify Partner
56 0 0
I have a variant for loop in the product template. I'm trying to display the compare_at_price for a variant IF it's different from the regular price, but this always evaluates to true: *if variant.price != variant.compare_at_price* Is this a problem with the variant variables, or my code?
0 Likes
Shopify Staff
Shopify Staff
2002 0 41

Is this in shopify directly or in vision?

Tobias Lütke - Shopify CEO // http://twitter.com/tobi
0 Likes
Shopify Partner
56 0 0

In Shopify.

0 Likes
Shopify Staff
Shopify Staff
2002 0 41

That was a bug. Fixed now.

Tobias Lütke - Shopify CEO // http://twitter.com/tobi
0 Likes
Shopify Partner
56 0 0

This still isn’t working in Shopify for me. It always evaluates to true: if variant.price != variant.compare_at_price

And this causes a Shopify error: if variant.price < variant.compare_at_price

Is there a different/better way to flag items that have a compare price set? Thanks.

0 Likes
Shopify Staff
Shopify Staff
2002 0 41

You are right as always…

The bugs should be squashed at next deploy time.

Tobias Lütke - Shopify CEO // http://twitter.com/tobi
0 Likes
Shopify Partner
56 0 0

Hate to do this again, but this bug is still occurring for me on my live Shopify site.

0 Likes
Shopify Staff
Shopify Staff
2002 0 41

Well the bug is fixed but there is still a problem. When you compare something with an empty value then its currently throwing an exception.

E.g. if you have a product with price 19.00 and compare_at price is empty it explodes right now because its difficult do find a reasonable way to handle this.

I’ll talk with some friends of mine to see how i should handle exceptional cases like this.

In the meantime wrap a {% if variant.compare_at %} around it

Tobias Lütke - Shopify CEO // http://twitter.com/tobi
0 Likes
Shopify Staff
Shopify Staff
2002 0 41

I made it so that such comparisons will now always fail if there is a NULL value involved in the operants.

Language design is hard

Tobias Lütke - Shopify CEO // http://twitter.com/tobi
0 Likes
Shopify Partner
56 0 0

{ if variant.compare_at } works. Thanks!

0 Likes