PrestaShop / PrestaShop

PrestaShop is the universal open-source software platform to build your e-commerce solution.
https://www.prestashop-project.org/
Other
8.23k stars 4.81k forks source link

Cart Rules discount with reduction percent applied to Selected products calculates wrong discount voucher value #37035

Open pelechano opened 1 month ago

pelechano commented 1 month ago

Prerequisites

Describe the bug and add attachments

In Cart Rule.php when suming the price in $selected_products_reduction it takes into account the price_without_reduction so the value is greater than expected

// Discount (%) on the selection of products 
 if ((float) $this->reduction_percent && $this->reduction_product == -2) {
                $selected_products_reduction = 0;
                $selected_products = $this->checkProductRestrictionsFromCart($context->cart, true);
                if (is_array($selected_products)) {
                    foreach ($package_products as $product) {
                        if ((in_array($product['id_product'] . '-' . $product['id_product_attribute'], $selected_products)
                                || in_array($product['id_product'] . '-0', $selected_products))
                            && (($this->reduction_exclude_special && !$product['reduction_applies']) || !$this->reduction_exclude_special)) {
                            $price = $product['price'];
                            if ($use_tax) {
                                $price = $product['price_without_reduction'];
                            }

                            $selected_products_reduction += $price * $product['cart_quantity'];
                        }
                    }
                }
                $reduction_value += $selected_products_reduction * $this->reduction_percent / 100;
            }

image

Expected behavior

If you use $price = $product['price_with_reduction']; the sum is correct so the reduction percentage is calculated with respect the real price of the selected product/s

Steps to reproduce

Create a discount (cart rule) with selection of products. Use a Percentage discount and apply them to Selected products Some of the Selected products have a specific price discount. The discount is greater than expected because uses the price_without_reduction in the sum

PrestaShop version(s) where the bug happened

1.7.8 and 8.1

PHP version(s) where the bug happened

7.4

If your bug is related to a module, specify its name and its version

No response

Your company or customer's name goes here (if applicable).

No response

florine2623 commented 1 month ago

Hello @pelechano ,

I can't reproduce your issue.

Could you share the whole configuration of the product, the discount and send a screenshot of the result you have in your cart ?

Waiting for your feedback. Thanks!