solidus icon indicating copy to clipboard operation
solidus copied to clipboard

Automatic promotions are applied when we delete line_items from order

Open sebfie opened this issue 8 years ago • 3 comments

Steps to reproduce

  1. Create an automatic free_shipping promotion when cart price > 50
  2. Create a cart
  3. Add one product x times for a total price < 50
  4. Add a second product x times for a total order > 50 => The free shipping code should be applied
  5. 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.

sebfie avatar Nov 10 '17 15:11 sebfie

I can't reproduce this on Solidus 2.7.

jacobherrington avatar Sep 27 '18 11:09 jacobherrington

Did you reproduce this on previous version? :)

sebfie avatar Sep 28 '18 07:09 sebfie

@sebfie I haven't are you still seeing the issue? If you have a solution, we'd love a PR! 😄

jacobherrington avatar Nov 21 '18 22:11 jacobherrington