Compare at price vs Price cart script

Will_Westwood
New Member
2 0 0

Hey everyone! I'm new to this so please bear with me.

I currently have a cart script that is essentially running a bunch of rules based on customer tags. It's working well.

It gets started with this:

 def apply(line_item)
    line_item.change_line_price(line_item.line_price * @discount, message: @message)
  end

 

What I'd like to do is wrap it in an IF statement so the rules won't apply if the line item is on sale, eg compare at price is greater than price, or even better, compare at price = nil. However I cannot get it to work!

 def apply(line_item)
     if  line_item.compare_at_price = nil
       line_item.change_line_price(line_item.line_price * @discount, message: @message)
     end
  end

 

Any clues would be very much appreciated!

 

0 Likes
Will_Westwood
New Member
2 0 0

For some reason, today the editor was showing me an error which helped track it down!

script error.png

 

 

 

 

 

In the end this seemed to work:

 def apply(line_item)
      unless  line_item.variant.compare_at_price
        line_item.change_line_price(line_item.line_price * @discount, message: @message)
      end
  end
0 Likes