Prestashop: Cart discount applied to reduced items (although disabled)

Created on 23 Nov 2020  路  4Comments  路  Source: PrestaShop/PrestaShop

Describe the bug

Creating a voucher applicable only on products belongs to selected category and doesn't apply on products on sale. if we add the voucher in cart whose contain only the product sale, an error message popup (That's OK) but if the cart contain another product doesn't belong to the selected category, we can apply the voucher (NOK) instead the value of discount is 0 (OK).

Expected behavior

An error message pop up saying "you cannot use this voucher on products on sale"

Steps to Reproduce

Steps to reproduce the behavior:

  1. BO > SELL > Catalog > Discounts
  2. Create Cart Rules > Conditions tab
  3. In the Restrictions block, select Product Selection
  4. Select Categories for Add a rule concerning (see the attached screenshot below) (ex: Accessoires)

image

  1. In Actions tab, choose Selected product(s) and enable Exclude discounted products (see the attached screenshot below)

image

  1. Save
  2. Go to Products > edit a product belong to the selected catalog (ex: Mug Today Is A Good Day whose belong to Accessoires)
  3. FO > Add the discounted product to cart (in our ex Mug Today Is A Good Day)
  4. Proceed to checkout > try to add the voucher to the cart
  5. An error message is displayed => OK (see the attached screenshot below)

image

  1. Add another a product doesn't belong to the selected category (ex: BROWN BEAR - VECTOR GRAPHICS whose belong to ART category)
  2. Proceed to checkout > try to add the voucher to the cart => NOK (see the attached screenshot below)

image

Screenshots

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

Additional information

  • PrestaShop version: develop & 1.7.7.0-rc.1
  • PHP version: 7.2
1.7.7.0 Bug Cart rules Discounts FO Minor To Do develop good first issue

All 4 comments

Hi,

i was investigating this issue and found the problem in CartRule.php method checkValidity.
There is a loop that already skips the error message when there is another product in the cart where the reduction does not apply.

`if ($this->reduction_exclude_special) {
$products = $cart->getProducts();
$is_ok = false;
$has_already_reduced_product = false;

        foreach ($products as $product) {
            if (!$product['reduction_applies']) {
                $is_ok = true;

                break;
            }
        }
        if (!$is_ok) {
            return (!$display_error) ? false : $this->trans('You cannot use this voucher on products on sale', [], 'Shop.Notifications.Error');
        }
    }`

Not sure if this is the right place to fix this issue but i would think that it should check if there is already any product in the cart where the reduction is applied

Hello @kevin0x90

If you have already fixed it on your end, please do send us a pull request!

Thank you

@hibatallahAouadni i didn鈥檛 fixed it yet, first I wanted to make sure I identified the correct location a fix would be appropriate at. For example one could argue this is not the right place and it should be fixed way earlier in the location reduction_applies is set. I would prefer this approach but I鈥檓 not that familiar with the architecture of the codebase yet. How about your opinion / view on this?

Hello @kevin0x90

Well this issue is in the Backlog, so let's wait for the developers to try to fix it.
Cause I'm not an expert :wink: and I don't want to give you a false statement :slightly_smiling_face:

Thanks!

Was this page helpful?
0 / 5 - 0 ratings