Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
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!
For some reason, today the editor was showing me an error which helped track it down!
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