Jump to content

Recommended Posts

Hello,

I have noticed an issue on PrestaShop's coupon system: as you know, using the native feature, you can create discount codes and exclude some specific categories from the discount.

The problem comes when I want to create a coupon with a fixed value discount. I make an example to explain:

------------------

To simplify, let's say that on my shop I have a catalogue with 2 categories: "clothes" and "shoes".

Now, I want to create a discount code worth €10 valid only for orders of at least €20, excluding the category "clothes" (the discount code is not valid for the products in the category "clothes").

The problem is that, if I add to the shopping cart a product from the category "shoes" worth €15 and a product from the category "clothes" worth €5, the coupon code is considered valid.

But the coupon should NOT be valid, because the customer needs to reach at least €20, but only with product belonging to "shoes" category!

------------------

So, when I create a coupon specifying a minimum order value ("valid only for orders of at least €20") and I exclude a specific category, that minimum order value should not be reached considering also the products from the excluded categories!

I know that this thing can be done setting up a % discount instead of a fixed value (€10 just like in the example above).

In fact, when I set up a % discount valid only for a minimum order value and I exclude the category "clothes" from the discount, the minimum order value is calculated only considering the products belonging to the category "shoes".

I think that PrestaShop should fix this issue as soon as possible.

Has anyone noticed this problem and maybe knows how to resolve?

Thank you for the support. 

Share this post


Link to post
Share on other sites

The minimum amount required is for the total cart amount and you can't exclude products/categories. You need a module to do so.

Share this post


Link to post
Share on other sites

Hello joseantgv, thank you for your answer.

What you say is not correct: I can exclude categories with a minimum amount, because if I put in my shopping cart only products belonging to the "clothes" category (the excluded category), even if I reach €20 total, the coupon in considered NOT valid.

The problem is when in my shopping cart there are products belonging to excluded categories.

Example 1: €15 "shoes" + €5 "clothes" = coupon WRONGLY considered valid;

Example 2: €25 "clothes" = coupon CORRECTLY considered not valid;

Share this post


Link to post
Share on other sites

If you check checkProductRestrictionsFromCart function from CartRule class it just checks the number of products from the selected categories:

...
case 'categories':
    $cart_categories = Db::getInstance()->executeS('
    SELECT cp.quantity, cp.`id_product`, cp.`id_product_attribute`, catp.`id_category`
    FROM `' . _DB_PREFIX_ . 'cart_product` cp
    LEFT JOIN `' . _DB_PREFIX_ . 'category_product` catp ON cp.id_product = catp.id_product
    WHERE cp.`id_cart` = ' . (int) $cart->id . '
    AND cp.`id_product` IN (' . implode(',', array_map('intval', $eligible_products_list)) . ')
    AND cp.`id_product` <> ' . (int) $this->gift_product);
    $count_matching_products = 0;
    $matching_products_list = array();
    foreach ($cart_categories as $cart_category) {
        if (in_array($cart_category['id_category'], $product_rule['values'])
            /*
             * We also check that the product is not already in the matching product list,
             * because there are doubles in the query results (when the product is in multiple categories)
             */
            && !in_array($cart_category['id_product'] . '-' . $cart_category['id_product_attribute'], $matching_products_list)) {
            $count_matching_products += $cart_category['quantity'];
            $matching_products_list[] = $cart_category['id_product'] . '-' . $cart_category['id_product_attribute'];
        }
    }
    if ($count_matching_products < $product_rule_group['quantity']) {
        if ($countRulesProduct === 1) {
            return (!$displayError) ? false : $this->trans('You cannot use this voucher with these products', array(), 'Shop.Notifications.Error');
        } else {
            ++$condition;

            break;
        }
    }
    // Attribute id is not important for this filter in the global list, so the ids are replaced by 0
    foreach ($matching_products_list as &$matching_product) {
        $matching_product = preg_replace('/^([0-9]+)-[0-9]+$/', '$1-0', $matching_product);
    }
    $eligible_products_list = $this->filterProducts($eligible_products_list, $matching_products_list, $product_rule['type']);

    break;
...

As far as I know/see, product amount from selected categories is not considered anywhere.

Share this post


Link to post
Share on other sites

Thanks again for the time that you are dedicating to me.

Honestly, I need to say that I don't have deep knowledge in PHP and programming in general, so I can deduct only something from the code above.

As I said in the first post, I think that this issue is to be considered as a lack of PrestaShop software, because the problem is only related to the fixed amount coupons.

In fact, as I said before, if you apply a % amount coupon and you exclude some categories, the discount is correctly applied only to the products belonging to the categories eligible for the discount.

So, why PrestaShop has this feature only for the % coupons and not for the fixed amount coupons?

It seems to me that this is an error to be corrected in PrestaShop code.

It's not like a special feature that I'm requiring. This is like a bug that makes the fixed coupons not working correctly. 

Share this post


Link to post
Share on other sites

Could you paste a screenshot of the rule configuration that is working for you? And which PS version are you running?

Share this post


Link to post
Share on other sites

Sorry, I need to clarify: if you set up a % discount, the coupon is considered valid even if in the shopping cart are present products belonging to excluded categories, but the difference is that the discount is applied only on eligible products.

Example of shopping cart: clothes €10 + shoes €10 / discount coupon -10% for an order minimum of €20 = coupon anyway applied but the discount is not calculated on the order total value, but only on eligible products (shoes). So, in this example, the coupon would result in a discount of €1 (10% of 10€, instead of 10% of 20€).

With a fixed discount this cannot be done, because it is always a fixed value, independently from the products.

However, I keep on thinking that there is a lack in the coupon system, because if I specify an order minimum and I exclude some categories, it's obvious that I don't want to apply discounts on that categories. So, it's also obvious that the minimum order value has to be reached only considering the eligible products.

How can this be fixed?

Share this post


Link to post
Share on other sites
Posted (edited)

You mean that if you define a fixed amount discount and you don't have this amount in products from the selected categories, the discount is not applied?

 

Cart rule:

Minimum amount -> 20€

Fixed discount -> 15€ 

Eligible categories -> Category A

Cart:

Products from Category A -> 10€

Products from Category B -> 20€

Total cart amount -> 30€

 

The problem is that discount is not applied because there are not at least 15€ in products from Category A

Edited by joseantgv (see edit history)

Share this post


Link to post
Share on other sites
Posted (edited)

The problem is when I specify a minimum amount of the order and I exclude from the coupon some categories.

When you set up a coupon like this, the only parameter that Prestashop considers is the minimum amount, even if that minimum amount is reached with products from excluded categories.

Let's take your example: the cart amount is 30€, but the minimum amount of 20€ should not be considered as reached, because the total of eligible products in the cart is only 10€.

The products from category B should not be counted, because they are excluded from the coupon.

This is the issue that I was talking about: considering the cart in the example you made, the coupon is considered valid when instead should not be valid.

 

Edited by Gianluca-Lorenz (see edit history)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More