Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I have a Scripts running at checkout that reduces the price of products based on customer and product tag. There is a strange issue with rounding though at times... So, a product listed at £7.49 with 20% discount reduces it to £5.99 (£5.992 technically). HOWEVER, if the customer increases the quantity to 3 units, the priceshows as £6 per unit. I think this is because 7.49 x 3 x 0.8 = 17.976 which is rounded to 17.98 then divided by 3 = 5.9933333, so it rounds to £6.
I am looking for a way to modify this code so that the price per unit is £5.99, irrelevant of units and rounding. It should just ignore any digits after the 2nd decimal (so 3 units would be £17.97)
The bit of code that I think is doing this is....
def apply(line_item)
new_line_price = if @discount_type == :percent
line_item.line_price * @discount_amount
else
[line_item.line_price - (@discount_amount * line_item.quantity), Money.zero].max
end
line_item.change_line_price(new_line_price, message: @discount_message)
end
end
The full code was taken from here
As 2024 wraps up, the dropshipping landscape is already shifting towards 2025's trends....
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024