Prestashop: Invalid cart rules not getting removed from existing carts

Created on 24 Sep 2019  路  9Comments  路  Source: PrestaShop/PrestaShop

Describe the bug
When changing the conditions of a rule that was already applied to a cart. The cart is not updated correctly

To Reproduce
Steps to reproduce the behavior:

  1. Create 2 customer groups (e.g. b2b10%, b2b9%)
  2. Create 2 cart rules
    10% discount for customer in b2b10% group
    9% discount for customer in b2b9% group
    image
  3. Assign b2b10% group to a customer and go to cart.
  4. 10% is correctly applied to the current cart
  5. Go to the customer and change his group to b2b9%
  6. Go to cart and notice both cart rules are applied for 10% and 9%

[Edited by Khouloud]

you don't need to log out => the wrong line is removed in the last step

image

Screenshots
If applicable, add screenshots or screenrecords to help explain your problem.

Additional information
PrestaShop version: 1.7.5.2
PHP version: 7.2

Expected behaviour

Only the active rules should be applied to cart

1.7.5.2 1.7.6.1 Bug Cart rules Customer Discounts FO Minor To Do

All 9 comments

Hi @ioweb-gr,

I did not manage to reproduce the issue with PS1.7.6.1.
I attached a screen record
https://drive.google.com/file/d/1_N07c3tGzWWZjj22C0ni3-b3QuICMthH/view
Thanks to check & feedback.

Let me check also on 1.7.6.1 and get back to you

@ioweb-gr, thanks!
Waiting for your feedback.

Replicated on 1.7.6.1

2019-09-24_12-18-18

Perhaps the difference is I didn't sign out first. But that's not realistic. The customer won't know when discounts change to sign out. They would always stay signed in during their session

Noticing a bit further, the discount calculation is also wrong. 19% discount total for this customer should yield 6.7773 not 6.46. Shall I open a second issue for that problem?

To troubleshoot I traced everything and noticed that the function CartRule:autoRemoveFromCart is never executed during checkout reload. So I added temporarily these functions to FrontController:init function and FrontController:postprocess function

        CartRule::autoRemoveFromCart($this->context);
        CartRule::autoAddToCart($this->context);

And as expected my cart rules were refreshed correctly when I reloaded the page. However the solution is not this simple.

Cart rules should be a part of the validation process of the checkout page as well. Before clicking "Place order" there should be a validation to check these rules and remove them from the cart when they're invalid informing the user of this change in his cart because we're not certain there is no user in the payment step already when we alter the rules.

Discounts should be very dynamic otherwise we risk selling items with double discounts.

@ioweb-gr, thanks for your clarifications.
I manage to reproduce the issue.
In fact, after changing the Group access of a customer & return to the FO without logging out => issue reproduced.
https://drive.google.com/file/d/1EYigVCM5f0fd2VAPghcOB9Vyga3Gvs2K/view
I鈥檒l add this to the debug roadmap so that it鈥檚 fixed. If you have already fixed it on your end or if you think you can do it, please do send us a pull request!

Noticing a bit further, the discount calculation is also wrong. 19% discount total for this customer should yield 6.7773 not 6.46. Shall I open a second issue for that problem?

Yes!
Thanks!

Unfortunately this was just a workaround for me. Not a correct fix.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zuk3975 picture zuk3975  路  3Comments

PrestaShark picture PrestaShark  路  3Comments

zuk3975 picture zuk3975  路  3Comments

matks picture matks  路  3Comments

marionf picture marionf  路  3Comments