Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong cart rule amount in FO when "Exclude discounted products" is enabled #19090

Closed
Tracked by #13823
kenlog opened this issue May 12, 2020 · 19 comments
Closed
Tracked by #13823
Labels
1.7.6.5 Affects versions 1.7.7.0 Affects versions BO Category: Back Office Bug Type: Bug Cart rules Label: Which BO under menu is concerned Discounts Label: Which BO under menu is concerned Fixed Resolution: issue closed because fixed FO Category: Front Office Major Severity: major bug > https://build.prestashop.com/news/severity-classification

Comments

@kenlog
Copy link

kenlog commented May 12, 2020

Describe the bug

When applying a cart rule with "exclude discounted products" enabled, the amount of the cart rule line isn't ok
It takes into account all products instead of only not discounted products
But the total and the discount line are OK

Steps to Reproduce

  1. I created a cart rule of 10% and enabled "exclude discounted products"
  2. I added two products in my cart: Hummingbird printed sweater, Size S (discounted) and Mug The best is yet to come (not discounted)
  3. See the discount line is OK, the total is OK but the cart rule line isn't OK

capture d'écran_2866

Expected behavior

If you activate the rule "Exclude discounted products" I expect that discount will not be applied to products that are discounted, but only to products without discount.

Additional information

  • PrestaShop version: 1.7.6.4
  • PHP version: 7.2
@prestashop-issue-bot
Copy link

Thanks for opening this issue! We will help you to keep its state consistent

@florine2623
Copy link
Contributor

Hi @kenlog ,
Thanks for reporting this issue.
I managed to reproduce the issue on both PS 1.7.6.5 and PS 1.7.7.
I'll let our dev team know about it.
Please stay tuned, thanks !

@florine2623 florine2623 added 1.6.1.x 1.7.6.5 Affects versions 1.7.7.0 Affects versions BO Category: Back Office Bug Type: Bug Cart rules Label: Which BO under menu is concerned Discounts Label: Which BO under menu is concerned FO Category: Front Office Ready Status: Issue is ready to be worked on Major Severity: major bug > https://build.prestashop.com/news/severity-classification and removed 1.6.1.x labels May 12, 2020
@arouiadib
Copy link
Contributor

Hello guys,

In 1.7.7.x, the calculation is correct.
image

Thanks

@sarahdib
Copy link
Contributor

@kenlog Thank you for the report I manage to reproduce the issue
You can see in my screenshot the value of the cart rule is not the same that the one in the cart. The total is correct only the display is not correct

Capture d’écran 2020-05-26 à 10 50 45

@arouiadib
Copy link
Contributor

arouiadib commented May 26, 2020

@sarahdib , thank you for your time.
About the second part (your second red rectangle), the problem should theoretically be fixed today after the merge of #17502 (Although it is not the problem originally mentioned by @kenlog; as you can see from his original picture when still voucher were displayed as percent). I will test with current 1.7.7.x state and feedback.

I think @kenlog is talking about the first part (your first red rectangle). Then, there is no problem as you see :) in your picture:

3.48 is 10% of 34.80, then the product which already discounted (Pull imprime colibri) is not included in the overall discount calculcation.

I am of course talking about 1.7.7.x, so IMHO it is just a question of upgrading.
Thanks.

@sarahdib
Copy link
Contributor

sarahdib commented Jun 1, 2020

@arouiadib Thank you for those detail :)

@kenlog can you confirm ?

@kenlog
Copy link
Author

kenlog commented Jun 1, 2020

Hi @sarahdib I confirm the bug as I have exposed it. In addition, this is also reflected in the PayPal payment method which correctly charges the right price excluding the already discounted products. This obviously involves a difference in the total cart and the order total. 😲

carrello
Ordine

P.S. Other payment methods such as Stripe charges based on the total cart.

@colinegin colinegin changed the title Cart rules "Exclude discounted products" Cart rules "Exclude discounted products" does not work Jun 10, 2020
@marionf marionf mentioned this issue Jun 10, 2020
73 tasks
@ComonSoft
Copy link
Contributor

Hi,
This is a big issue, because invoices are false, and customer can complain. Is any fix available ?
To reproduce, add rule 10% all cart exclude products in promotion. The reduction is applied on all products. See screen shot enclosed.
PS 1.7.6.5 PHP 7.2
screenshot

Regards

@Damian-Rutkowski
Copy link

Damian-Rutkowski commented Jun 30, 2020

Good afternoon,

is there an official patch that can also be imported for older versions (e.g. v1.7.6.5)? We have some customers and unfortunately we cannot update all of them.

@marionf marionf added this to Not ready in PrestaShop 1.7.8.0 via automation Aug 14, 2020
@marionf marionf moved this from Not ready to Backlog in PrestaShop 1.7.8.0 Aug 14, 2020
@LouiseBonnard LouiseBonnard moved this from Backlog to To do in PrestaShop 1.7.8.0 Aug 24, 2020
@khouloudbelguith
Copy link
Contributor

Hi!

As commented here, I have the same issue with PS1.7.7.0beta2build1
image
image

Thanks!

@hibatallahAouadni hibatallahAouadni added this to the 1.7.7.0 milestone Nov 23, 2020
@marionf
Copy link
Contributor

marionf commented Nov 23, 2020

@hibatallahAouadni

Just tested on 1.7.7.x branch and this issue doesn't seems fixed

  1. I created a cart rule of 10% and excluded discounted products
  2. I added to products in my cart: Hummingbird printed sweater, Size S (discounted) and Mug The best is yet to come (not discounted)

capture d'écran_2865

@marionf marionf reopened this Nov 23, 2020
@prestashop-issue-bot prestashop-issue-bot bot added Needs Specs Status: issue needs to be specified and removed Fixed Resolution: issue closed because fixed labels Nov 23, 2020
@prestashop-issue-bot prestashop-issue-bot bot moved this from Done to Need more specs/Blocked in PrestaShop 1.7.8.0 Nov 23, 2020
@hibatallahAouadni
Copy link
Contributor

Hello @marionf

Could you please check the screen record attached below:

https://drive.google.com/file/d/1wzBKm-ltqVdo35Cihv34lgFMQSxHR8ha/view

Please check and feedback.
Thanks!

@marionf
Copy link
Contributor

marionf commented Nov 23, 2020

That's another issue, you added a condition in the cart rule and selected a category: #22057
Here, there is still the issue described by @khouloudbelguith in this comment with a cart rule with "exclude discounted products" enabled and no conditions

@marionf marionf removed this from the 1.7.7.0 milestone Nov 23, 2020
@marionf marionf moved this from Need more specs/Blocked to To do in PrestaShop 1.7.8.0 Nov 23, 2020
@prestashop-issue-bot prestashop-issue-bot bot added Ready Status: Issue is ready to be worked on and removed Needs Specs Status: issue needs to be specified labels Nov 23, 2020
@marionf marionf changed the title Cart rules "Exclude discounted products" does not work Wrong cart rule amount in FO when "Exclude discounted products" is enabled Nov 23, 2020
@GIORGIOMARIO
Copy link

Discount voucher problem: The discount code applies to all products, even to discounted items with the version 1.7.6.5.

When I apply the discount code on 1 item, the code does "exclude discounted products".
But when I apply it on more than 1 item (1 normal and 1 disounted product per example), the code apply reduction on all products.

Problème code promo

@josearandac
Copy link

josearandac commented May 13, 2021

Hello,

This solution work for me.

  1. File /src/Core/Cart/CartRuleCalculator.php find the code block:
        if ($cartRule->reduction_percent && $cartRule->reduction_product == -2) {
            $selected_products = $cartRule->checkProductRestrictionsFromCart($cart, true);
            if (is_array($selected_products)) {
                foreach ($this->cartRows as $cartRow) {
                    $product = $cartRow->getRowData();
                    if (in_array($product['id_product'] . '-' . $product['id_product_attribute'], $selected_products)
                        || in_array($product['id_product'] . '-0', $selected_products)
                           && (($cartRule->reduction_exclude_special && !$product['reduction_applies'])
                               || !$cartRule->reduction_exclude_special)) {
                        $amount = $cartRow->applyPercentageDiscount($cartRule->reduction_percent);
                        $cartRuleData->addDiscountApplied($amount);
                    }
                }
            }
        }
  1. We add a parenthesis:
        // Discount (%) on the selection of products
        if ($cartRule->reduction_percent && $cartRule->reduction_product == -2) {
            $selected_products = $cartRule->checkProductRestrictionsFromCart($cart, true);
            if (is_array($selected_products)) {
                foreach ($this->cartRows as $cartRow) {
                    $product = $cartRow->getRowData();
                    if ((in_array($product['id_product'] . '-' . $product['id_product_attribute'], $selected_products)
                        || in_array($product['id_product'] . '-0', $selected_products))
                           && (($cartRule->reduction_exclude_special && !$product['reduction_applies'])
                               || !$cartRule->reduction_exclude_special)) {
                        $amount = $cartRow->applyPercentageDiscount($cartRule->reduction_percent);
                        $cartRuleData->addDiscountApplied($amount);
                    }
                }
            }
        }

I hope it helps

@hibatallahAouadni
Copy link
Contributor

Hello @josearandac

Could you please create a Pull Request.
Remember that the more people contribute, the better PrestaShop becomes for everyone.

Thank you

@josearandac
Copy link

josearandac commented May 17, 2021

Hello @hibatallahAouadni ,

A pull request already exists:

18144

I just found it.

Thank you!

@khouloudbelguith
Copy link
Contributor

Hi @marionf,

As commented here, the issue is fixed
image

177x (1775 => ok): https://drive.google.com/file/d/1wIIN_4lgP13CqVA0OSgcRkDS9yAXTEnH/view?usp=sharing
178x => ok

Thank you!

@prestashop-issue-bot prestashop-issue-bot bot removed the Ready Status: Issue is ready to be worked on label May 24, 2021
@khouloudbelguith khouloudbelguith added the Fixed Resolution: issue closed because fixed label May 24, 2021
@khouloudbelguith khouloudbelguith added this to the 1.7.7.5 milestone May 24, 2021
@hibatallahAouadni hibatallahAouadni removed this from For the next sprint ? in Bug classification board May 25, 2021
@marionf marionf removed this from the 1.7.7.5 milestone May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.7.6.5 Affects versions 1.7.7.0 Affects versions BO Category: Back Office Bug Type: Bug Cart rules Label: Which BO under menu is concerned Discounts Label: Which BO under menu is concerned Fixed Resolution: issue closed because fixed FO Category: Front Office Major Severity: major bug > https://build.prestashop.com/news/severity-classification
Projects
No open projects
Development

No branches or pull requests