Automatic promotions are applied when we delete line_items from order
Steps to reproduce
- Create an automatic free_shipping promotion when cart price > 50
- Create a cart
- Add one product x times for a total price < 50
- Add a second product x times for a total order > 50 => The free shipping code should be applied
- Remove the second product added on step 4 => The free shipping is still applied and the total_order < 50
Expected behavior
The free shipping promotion should not be applied
Actual behavior
An automatic promotion is not removed when the cart is not eligible
System configuration
Solidus Version: 2.2
We only use solidus with API
Potential issue
Looking to the code I see that :
We can see here : https://github.com/solidusio/solidus/blob/v2.2/core/app/models/spree/order_contents.rb#L77 which after each add/remove on cart, call PromotionHandler::Cart.new(order, line_item).activate so, this code :
https://github.com/solidusio/solidus/blob/v2.4/core/app/models/spree/promotion_handler/cart.rb#L23 will run this :
promotion.eligible?(line_item, promotion_code: promotion_code(promotion))
So, it means that, if we remove a line_item which is eligible by the promotion, the promotion will be applied to the cart. I think PromotionHandler::Cart.new(order, line_item).activate should not be called when removing a product
To finish :
This line https://github.com/solidusio/solidus/blob/v2.2/core/app/models/spree/promotion.rb#L123 will return true for an automatic free shipping rule for every line_item because promotion.rules.for(line_item) = [] in this case.
I can't reproduce this on Solidus 2.7.
Did you reproduce this on previous version? :)
@sebfie I haven't are you still seeing the issue? If you have a solution, we'd love a PR! 😄