Jump to content
cleoni

Disabling discounts (cart rules) to items already on sale

Recommended Posts

Hello,

one of my customers has presented me a problem laying in PS 1.5 and I found no solution to this apart from open requests left unresolved on the forum and issuetracker. 

 

Suppose you have a shop with a number of items on sale with reduced prices.

Say you are placing these on sale items in a specific category (named, say, "on sale") or that you are ticking the "sale" flag to active the "on sale" icon, or even both things.

 

Now suppose you create a new cart rule (voucher) to give a discount of 25% to all products... of course you do not want to apply this discount on items already on sale.

 

Well, it seems there is absolutely no way to avoid this. 

If one gets the voucher, she will get the 25% off discount even on items on sale.

 

I think that an option on cart rules saying:

 

"exclude items on this category: ----"

or

"exclude items marked 'on sale' "

 

would do the job, but it's not there.

 

I think this is a very common case.

 

Perhaps I am tackling the issue in the wrong way?

Hope to get a few suggestions, thanks in advance

 

Share this post


Link to post
Share on other sites

This is really important to get implemented in the next verison of prestashop as most other shopping carts have a facility to not appy discounts to items already on sale.

I hope Prestashop are looking at it.

Regards

Breda.

Share this post


Link to post
Share on other sites

We needed to apply Discount to only products that were not in the "on sale"

 

We achieved this by

 

Editing the file: classes/CartRule.php

After this code:

// Do not give a reduction on free products!

$order_total = $context->cart->getOrderTotal($use_tax, Cart::ONLY_PRODUCTS, $package_products);

          foreach ($context->cart->getCartRules(CartRule::FILTER_ACTION_GIFT) as $cart_rule)

                       $order_total -= Tools::ps_round($cart_rule['obj']->getContextualValue($use_tax, $context, CartRule::FILTER_ACTION_G    IFT, $package), 2);

Add these lines:

foreach ($package_products as $product)
          if($product['on_sale'])
                       $order_total -= $use_tax ? $product['total_wt'] : $product['total'];
  • Like 3

Share this post


Link to post
Share on other sites

 

We needed to apply Discount to only products that were not in the "on sale"

 

We achieved this by

 

Editing the file: classes/CartRule.php

After this code:

// Do not give a reduction on free products!

$order_total = $context->cart->getOrderTotal($use_tax, Cart::ONLY_PRODUCTS, $package_products);

          foreach ($context->cart->getCartRules(CartRule::FILTER_ACTION_GIFT) as $cart_rule)

                       $order_total -= Tools::ps_round($cart_rule['obj']->getContextualValue($use_tax, $context, CartRule::FILTER_ACTION_G    IFT, $package), 2);

Add these lines:

foreach ($package_products as $product)
          if($product['on_sale'])
                       $order_total -= $use_tax ? $product['total_wt'] : $product['total'];

 

Hmm. Did not work for me. Still gets discount on products that are on sale.

Share this post


Link to post
Share on other sites

Didn't work for me too on PS 1.5.1

 

Any suggestion?

 

Worked perfectly for me on PS 1.5. I didn't change original files. I copied CartRule.php to override/clases directory and edited it right there. Then I cleared theme cache in BO and turned off CCC for a while. Then it started working.

  • Like 1

Share this post


Link to post
Share on other sites

Hello,

 

I did put this code into CartRules.php and then tried to shop...

 

What works is that there's no reduction given in a % voucher on the products in sale... But the strange thing is that when I try to apply this code to a sales product, in the cart the prices is changed to the normal (not on sale) price...

 

So something is not going the right way...

 

What can be wrong?

 

Thanks...

Share this post


Link to post
Share on other sites

Hi everyone. Solution from post #4 does not work for me either on 1.5.4.0 :-(

Share this post


Link to post
Share on other sites

Worked for me too, 1.5.6.2

Just don't forget to clear your cache on Performance settings.

Share this post


Link to post
Share on other sites

its work (ps 1.5.6.2) but... you must 'checked' ON SALE option in your products.

  • Like 1

Share this post


Link to post
Share on other sites

If I do not have the 'On sale' marked however is the reduced price. I think thet is problem all us.

Any help?

 

ps. sorry to my english
 

Share this post


Link to post
Share on other sites

SOLVED

Ok I have the solution:

 

CartRule.php line ~796 after: $order_total -= Tools::ps_round($cart_rule['obj']->getContextualValue($use_tax, $context, CartRule::FILTER_ACTION_GIFT, $package), 2);

 
foreach ($package_products as $product)
 //        if($product['on_sale'])
if (Product::isDiscounted((int)$product['id_product'])) 

                       $order_total -= $use_tax ? $product['total_wt'] : $product['total'];
  • Like 2

Share this post


Link to post
Share on other sites

OK, and then when a client has a 'oney' voucher, they still can buy the sale products?

 

Or then also not?

 

Thanks...

 

______

 

EDIT:

 

I see that if I use a 'money' voucher, the price of the sales article is going back to the normal price... How can this be changed? Anyone a clue over here?

Edited by dekarperboer

Share this post


Link to post
Share on other sites

you can order "on sale" products with voucher code, 

why not?

Share this post


Link to post
Share on other sites

you can order "on sale" products with voucher code, 

why not?

 

Yes but the problem is when you have products on sale presta shouldn't add discount coupons because it doesn't make sense:)   

Edited by blackflow

Share this post


Link to post
Share on other sites

yeap i understand, unfortunately, this option was disabled in prestashop 1.5.x i have no idea why, in 1.4 and oldest releases it was a default feature :(

Share this post


Link to post
Share on other sites

you can order "on sale" products with voucher code, 

why not?

 

Hello Vekia, sorry for the late reaction, but I was on holidays...

 

What I mean is following:

 

For % vouchers/rules:

 

When I order some products which are in sale, with this code the price of the product will get back to the normal price and then is calculating the discount (%), after that the order price is reduced with the discount calculated... This is OK...

 

For money vouchers/rules: 

 

When I order some products which are in sale, with this code the price of the product will get back to the normal price and after that the total order price is reduced with the value of the money voucher... This is NOT OK... Because a money voucher should have the possibilities of enjoying the sales prices. If you know what I mean...

 

Thanks,

 

Marco

Share this post


Link to post
Share on other sites

 

SOLVED

Ok I have the solution:

 

CartRule.php line ~796 after: $order_total -= Tools::ps_round($cart_rule['obj']->getContextualValue($use_tax, $context, CartRule::FILTER_ACTION_GIFT, $package), 2);

 
foreach ($package_products as $product)
 //        if($product['on_sale'])
if (Product::isDiscounted((int)$product['id_product'])) 

                       $order_total -= $use_tax ? $product['total_wt'] : $product['total'];

 

 

 

Yep, it's working. But still there's a small problem. When you add a product that is not on sale and use a coupon it adds a discount for the whole cart. A finishing touch from Vekia and we will have a perfect solution;)

Share this post


Link to post
Share on other sites

Yep, it's working. But still there's a small problem. When you add a product that is not on sale and use a coupon it adds a discount for the whole cart. A finishing touch from Vekia and we will have a perfect solution;)

 

hello

you have to define target of code in "actions" section, if you selected that code is for whole cart, it will be included for whole cart\

there is also available solution as a module for PrestaShop 1.5 and 1.6: disble vouchers for items on sale

Share this post


Link to post
Share on other sites

hello

you have to define target of code in "actions" section, if you selected that code is for whole cart, it will be included for whole cart

Can you explain what you mean Vekia?

 

We really need some coding for this... Let me try what I'm looking for again:

 

At this moment, when a customer adds a product to the cart that is in SALE and they use a %

cart rule the SALE price is removed and the original price shows up. That’s not what we want,

what we want is that % cart rules can never be used on products that are in SALE.

When a customer uses an € amount cart rule they should be able to also buy SALE products.

 

Now, what we want is that the % sales vouchers keep working as they do now, when a customer fills in a % voucher the sales price returns to the normal / original price and then calculates the discount over the normal / original price.

 

But when a customer fills in an € amount voucher, then the sales price has to stay. As we sell these vouchers to our customers, it’s a bit strange that the price of Sales products will change.

From what we understand, you want to sell vouchers with a specific € amount. Is that right? Please also confirm if we can add these vouchers as products.

 

This means that an adjustment needs to be made to how the cart will handle different cart rules (% rule and € rule).

 

See Cart Image #1

Here you van see the cart without a cart rule applied and you can see the sales price is calculated on some products.

See Cart Image #2

Here you can see the cart with a % cart rule applied and you can see the sales prices are removed and the % cart rule is then calculated over the normal / standard price giving the customer the discount of 15% over the total of the cart. THIS IS WORKING GOOD!

See Cart Image #3

Here you see the cart with a € cart rule applied and you can also see here the sales prices are set back to normal / original price and after that the customer get’s the € discount price. THIS IS NOT WORKING GOOD! As we want the € cart rule applied to the cart WITH the sales prices as I tried to make clear in See Cart Image #4.

 

Is this possible you think?

 

Thanks...

post-412833-0-73974200-1404563613_thumb.jpg

post-412833-0-92988400-1404563617_thumb.jpg

post-412833-0-08372800-1404563621_thumb.jpg

post-412833-0-14172200-1404563624_thumb.jpg

Share this post


Link to post
Share on other sites

I've got to work this somehow on a Prestashop 1.5.2.

I've used the code with the "if($product['on_sale'])" clause instead of the call to Product::isDiscounted funtion.

I don't think it's the optimal way of resolving this issue as each time we want to have a discounted price we need to mark the product with the "on sale" mark.  :(

 

Anyone having problem with the Product::isDiscounted function?

Even thought the product had a discount (catalogue rule o price rule) the function returned false and the whole discount to the order was applyed.

 

I'll keep on investigating this and if I find a solution I'll post it here.

 

Thanks to all the contributors.

Share this post


Link to post
Share on other sites

I haven't used 1.5, but in the process of upgrading from 1.4 to 1.6. I was happy to see that there are further possibilities to configure the cart rules, but it's a pity that one can't exclude already discounted products/categories/specific products. I'm regularly running special offers like 10% or 15% off the whole store, but I need to be able to exclude certain product categories/products such as e-gift certificates and additional shipping charges. Is there a way to do this? Thanks

Share this post


Link to post
Share on other sites

I was having trouble disabling the group discount if a product is already on sale. This thread has helped me quite a lot, but I still had to look through a lot of code. So this is how I did it, I hope it helps someone! :)

 

In GroupReduction.php

In the function "getValueForProduct", after

if (!Group::isFeatureActive())
			return 0;

i added:

if (Product::isDiscounted($id_product))
			return 0;

Note: I'm running 1.6.0.6

 

Cheers!

Edited by sirDonald

Share this post


Link to post
Share on other sites

Why cant they add a product level "disable cart rule" feature. Would solve everyones problems. 

Share this post


Link to post
Share on other sites

I was having trouble disabling the group discount if a product is already on sale. This thread has helped me quite a lot, but I still had to look through a lot of code. So this is how I did it, I hope it helps someone! :)

 

In GroupReduction.php

In the function "getValueForProduct", after

if (!Group::isFeatureActive())
			return 0;

i added:

if (Product::isDiscounted($id_product))
			return 0;

Note: I'm running 1.6.0.6

 

Cheers!

 

 

SirDonald,

I have recently downloaded the latest version of 1.6.0.9 and I am also trying to exclude sale items on a store wide voucher (though I think it would be nice to have the option per cart rule). Is the code you posted above the extent of the changes you made or did you use any of the code previously posted in this thread or other wise?

Tks,

Share this post


Link to post
Share on other sites

 

We needed to apply Discount to only products that were not in the "on sale"

 

We achieved this by

 

Editing the file: classes/CartRule.php

After this code:

// Do not give a reduction on free products!

$order_total = $context->cart->getOrderTotal($use_tax, Cart::ONLY_PRODUCTS, $package_products);

          foreach ($context->cart->getCartRules(CartRule::FILTER_ACTION_GIFT) as $cart_rule)

                       $order_total -= Tools::ps_round($cart_rule['obj']->getContextualValue($use_tax, $context, CartRule::FILTER_ACTION_G    IFT, $package), 2);

Add these lines:

foreach ($package_products as $product)
          if($product['on_sale'])
                       $order_total -= $use_tax ? $product['total_wt'] : $product['total'];

 

I must say big thanks! Real life saver.

Makes the job!

 

1) I have put into basket some sale product

2) I want to apply voucher code and nothing happend (no alert no voucher in shopping cart) yay!

3) I add non sale product to basket and before applied voucher is available and the voucher reduce price only to non discounted product! Superb!

 

1.5.6.2

  • Like 1

Share this post


Link to post
Share on other sites

Wow! Same nightmare problem, but i have found a workaround and I must share.

 

I am using 1.5.6.2

I did not want to make a coding change.

I tried everything, almost...

 

Then I tried this and it works perfectly!!!.  Presta-tricks!!!

 

  1. Create a new manufacturer called On Sale (or whatever you like)
  2. go to each Product that is on sale and go to the Associations tab
  3. change the Manufacturer to On Sale
  4. go to your cart rule that is providing a discount for all regular priced merchandise only
  5. go to Product Selection and add a rule concerning all manufacturers except the On Sale manufacturer 
  6. under Actions choose to apply discount to all selected products

 

So happy that this works.  Please tell me if it does or does not work for you!!!

 

Remember also to also uncombine the other cart rules if necessary.

Cheers!

Edited by PrestaToys
  • Like 2

Share this post


Link to post
Share on other sites

Thank you all for a great help!! Post #13 works perfectly for me. Plus I added a piece of code that disables my two products from the whole cart discount (gift vouchers). This is my code: 

 foreach ($package_products as $product)
 //        if($product['on_sale'])
if (Product::isDiscounted((int)$product['id_product']))
 
                       $order_total -= $use_tax ? $product['total_wt'] : $product['total'];
                   
                   foreach ($package_products as $product)    
                       	if ($product['id_product'] == 45 || $product['id_product'] == 46) 
                       
                        $order_total -= $use_tax ? $product['total_wt'] : $product['total'];

Share this post


Link to post
Share on other sites

Wow! Same nightmare problem, but i have found a workaround and I must share.

 

I am using 1.5.6.2

I did not want to make a coding change.

I tried everything, almost...

 

Then I tried this and it works perfectly!!!.  Presta-tricks!!!

 

  1. Create a new manufacturer called On Sale (or whatever you like)
  2. go to each Product that is on sale and go to the Associations tab
  3. change the Manufacturer to On Sale
  4. go to your cart rule that is providing a discount for all regular priced merchandise only
  5. go to Product Selection and add a rule concerning all manufacturers except the On Sale manufacturer 
  6. under Actions choose to apply discount to all selected products

 

So happy that this works.  Please tell me if it does or does not work for you!!!

 

Remember also to also uncombine the other cart rules if necessary.

Cheers!

 

Creative solution! Unfortunately this requires all products to have a manufacturer set, right? So if you're not using Manufacturers you would have to set all regular priced products to a manufacturer called "Not On Sale".

Share this post


Link to post
Share on other sites

Hey Yay,

 

I do not have manufacturers set and it works for me... I think it should work for you too.  

 

Not sure if version matters (I am using 1.5.6.2) Try it and see!

 

Good luck.

Share this post


Link to post
Share on other sites

Hey Yay,

 

I do not have manufacturers set and it works for me... I think it should work for you too.  

 

Not sure if version matters (I am using 1.5.6.2) Try it and see!

 

Good luck.

 

 

Thanks for the reply! :)

 

Don't know if I'm just slow today but I can't get it to work completely. If I keep the On sale manufacturer in the Unselected box, I don't get a discount for On Sale products. So far so good. But what doesn't work is discounts for other products. Since my regular priced products don't have a Manufacturer they are not affected by the cart rule and should therefore not work. Right?

 

Using 1.5.6.2 as well.

Edited by yay

Share this post


Link to post
Share on other sites

hi Yay,

 

I checked further.

 

Of course, it's a bit strange.

 

When i look at the Manufacturers tab, i see a whole list of manufacturers.

 

But when i go to a Product's Association Tab, the Manufacturer is blank.

 

I created a new manufacturer called "On Sale" and select.  My other products still have a blank for manufacturer.

 

When i set up the cart rule, I add all the manufacturers for the condition and then remove the "On Sale" manufacturer.

 

Then it works.

 

Check to see if you have any Manufacturers on the Catalog > Manufacturers tab.  If so, they should appear in the cart rules, and you can make this work.

 

If not, maybe you will have to create them... my list of manufacturers simply corresponds to the Brand name of the product.

 

I will keep investigating on my end, but it seems to have worked for the Cyber Monday Deal that I set up.

 

Worst case, you will have to create a list of manufacturers (or maybe just the on sale and not on sale).

Share this post


Link to post
Share on other sites

Seems I have 73 Manufacturers listed but they are all disabled except "On Sale"

 

Starting to seem kinda strange that this works, but it does. 

Share this post


Link to post
Share on other sites

Ok checked the database.

 

My ps_products table shows id_manufacturer from 1 to 73.

 

The ones that I put "On Sale" are #73.

Check your table.  If they are all #1, make "Not on Sale" #1 then create the "On Sale" as #2 (or whatever the system generates)

 

If they are all zero, then create #1 and change them to #1, then change the On Sale ones to #2 (or whatever the system generates)

 

Good luck!

Share this post


Link to post
Share on other sites

Thanks again for taking the time. Might look into automating this solution. Editing all id_manufacturer to a "Not on sale" manufacturer in the database is done in a jiffy but then again it's easy to forget to add the "Not on sale" manufacturer to all new products. 

 

Maybe it would be easiest to add some SQL trigger that adds the "Not on sale" manufacturer to all new products and then adds the "On sale" manufacturer to all products that get a specific price or has the On sale checkbox active.

Share this post


Link to post
Share on other sites

Hi,

 

i'm using 1.6.0.14 and I cant' get this to work. Has anyone has some solution for this.

I don't use vouchers, coupons etc... I'm using customer group discount for every customer with his own customer group.

All I need is to don't get group discount for products marked ON SALE.

 

Is this possible somehow? Please; I need help ASAP!!!

 

thnx

Edited by Danijelp

Share this post


Link to post
Share on other sites

It's working for me fine, it does not include discount to the products what are already on sale. 

But i have another issue a bit different.

I would need to apply the same price rule / discount to all products (which are on sale and which are not) and to apply a discount from a base price.

So let say: one product i have with 10 %, 2nd 15%discount  and i want now 30% to all.

Normally would take 30% from already 10%/15% discounted product, with above mentioned code it does not take at all. 

Any ideas?

Many thanks in advance..

Share this post


Link to post
Share on other sites

Why PS team removed this feature? Now that I'm using PS1.6.0.9 and I can't make anymore a voucher that add discount only to products without any price reduction.

Share this post


Link to post
Share on other sites

try this I'm using prestashop 1.6.0.9 it will remove the sale items from the discount computation

 

In CartRule.php find this if statement code 

 

// Discount (%) on the selection of products
if ($this->reduction_percent && $this->reduction_product == -2)

 and replace it with this code

 

// Discount (%) on the selection of products
if ($this->reduction_percent && $this->reduction_product == -2)
{
$selected_products_reduction = 0;
$selected_products = $this->checkProductRestrictions($context, 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))
{
if (!(Product::isDiscounted((int)$product['id_product']))){
$price = ($use_tax ? $product['price_wt'] : $product['price']);
$selected_products_reduction += $price * $product['cart_quantity'];
}
}
$reduction_value += $selected_products_reduction * $this->reduction_percent / 100;
}
 
  • Like 2

Share this post


Link to post
Share on other sites

Hi all

I'm using 1.6.1.1

the code on CartRule.php is:

            // Discount (%) on a specific product
            if ($this->reduction_percent && $this->reduction_product > 0) {
                foreach ($package_products as $product) {
                    if ($product['id_product'] == $this->reduction_product) {
                        $reduction_value += ($use_tax ? $product['total_wt'] : $product['total']) * $this->reduction_percent / 100;
                    }
                }
            }

How do I edit to stop the use voucher of the products in discount?

Share this post


Link to post
Share on other sites

Hi!

First sorry for my english.

 

the code used by dhada is only when I select products in the cart rules. If we have product with discounts, the cart rules action would be 'apply in the order', and modify cartRules.php:

            // Discount (%) on the whole order
            if ($this->reduction_percent && $this->reduction_product == 0)
            {
                // Do not give a reduction on free products!
                $selected_products_reduction = 0;
                    foreach ($package_products as $product)
                      if (!(Product::isDiscounted((int)$product['id_product']))){
                                $price = ($use_tax ? $product['price_wt'] : $product['price']);
                                $selected_products_reduction += $price * $product['cart_quantity'];
                        }
                $reduction_value += $selected_products_reduction * $this->reduction_percent / 100;
            }

Share this post


Link to post
Share on other sites

Im running presta 1.6.0.14 and as everyone else on this thread im having issues with this discount and voucher thing...

 

When i replace code:

			// Discount (%) on the whole order
			if ($this->reduction_percent && $this->reduction_product == 0)
			{
				// Do not give a reduction on free products!
				$order_total = $context->cart->getOrderTotal($use_tax, Cart::ONLY_PRODUCTS, $package_products);
				foreach ($context->cart->getCartRules(CartRule::FILTER_ACTION_GIFT) as $cart_rule)
					$order_total -= Tools::ps_round($cart_rule['obj']->getContextualValue($use_tax, $context, CartRule::FILTER_ACTION_GIFT, $package), _PS_PRICE_COMPUTE_PRECISION_);

				$reduction_value += $order_total * $this->reduction_percent / 100;
			}

with code:

			// Discount (%) on the whole order
            if ($this->reduction_percent && $this->reduction_product == 0)
            {
                // Do not give a reduction on free products!
                $selected_products_reduction = 0;
                    foreach ($package_products as $product)
                      if (!(Product::isDiscounted((int)$product['id_product']))){
                                $price = ($use_tax ? $product['price_wt'] : $product['price']);
                                $selected_products_reduction += $price * $product['cart_quantity'];
                        }
                $reduction_value += $selected_products_reduction * $this->reduction_percent / 100;
            }

It gets working as far as function wise, but my theme get disorted... product image on product page and related products images get stretched somehow (actually just place for them gets stretched as you can see from following images)

 

I hope you guys have any solution to this.  :)

 

 

issue.png

 

and

issue2.png

Share this post


Link to post
Share on other sites

Hi Dex!

It's very strange, the cartRule.php code only affects the cart, not the product page. Can you send the url?

Share this post


Link to post
Share on other sites

Hi Dex!

It's very strange, the cartRule.php code only affects the cart, not the product page. Can you send the url?

 

Yeah i know that it shouldnt affect it, but somehow it does. This is random product url: http://dsbutik.si/kratke-obleke/170-modna-balonasta-obleka

 

But you wont see much there since i have returned it back to as it was while looking for solution. I couldnt leave it that way because this is live store.  :)

 

I will be gratefull for any tips and solutions.

Share this post


Link to post
Share on other sites

...

I think that an option on cart rules saying:

 

"exclude items on this category: ----"

...

 

 

Hey.

 

Dose any one have a code to make the cart rule not include a specific catagory in the order total?

 

Jacob

Share this post


Link to post
Share on other sites

I'm also running into this problem.

 

While the idea of post #28 might be a solution, it is limited. 

 

The cart rule condition 'product selection' or 'manufacturer selection' says:

The cart must contain at least  Product(s) matching the following rules: 

add.gif Add a rule concerning  -- Choose -- Products Attributes Categories Manufacturers Suppliers   

disabled.gif [Manufacturers] The product(s) are matching on of these choose.gifChoose

 

 

Which means that as soon as a product from an allowed selection/category is added to the cart, the whole cart will get the discount (in my case 15%). So even items that are already on sale, which I don't want to allow a double discount on, are treated as 'okay' since at least 1 product/category is correct under this condition.

I'm looking for a rule setup with EXCEPTIONS. A rule where you can say: all products, categories... except category/product A, B or C

Share this post


Link to post
Share on other sites

Hey.

 

Dose any one have a code to make the cart rule not include a specific catagory in the order total?

 

Jacob

 

Hey again.

 

Would somthing like

foreach ($package_products as $product) {
	if ($product['category=1']) {
		if ($use_tax) 
                      $order_total -= Tools::ps_round($product['total_wt'],2);
		else
                      $order_total -= Tools::ps_round($product['total'],2); } }

Work?

Share this post


Link to post
Share on other sites

 

Thank you all for a great help!! Post #13 works perfectly for me. Plus I added a piece of code that disables my two products from the whole cart discount (gift vouchers). This is my code: 

 foreach ($package_products as $product)
 //        if($product['on_sale'])
if (Product::isDiscounted((int)$product['id_product']))
 
                       $order_total -= $use_tax ? $product['total_wt'] : $product['total'];
                   
                   foreach ($package_products as $product)    
                       	if ($product['id_product'] == 45 || $product['id_product'] == 46) 
                       
                        $order_total -= $use_tax ? $product['total_wt'] : $product['total'];

 

Hey Mouse1

 

it seems that I cant make your last code work. What version of prestashop do you use?

Edited by ramlov

Share this post


Link to post
Share on other sites

#13 post works perfectly in my ps, but i want throw a warning massege in cart that "Coupon are not applied on special product" when user applied coupon on cart . Help me!!!

 Thanks in advance.

Share this post


Link to post
Share on other sites

For me the solution in post #13 works fine so far.  (PS v1.6.1.3)

I had just a little confusion about the position to add the code.

I looked like the solution should be in the previous foreach loop but actually is a new foreach loop --> so put the code after the ending bracket }    ;-)

foreach ($context->cart->getCartRules(CartRule::FILTER_ACTION_GIFT) as $cart_rule) {
    $order_total -= Tools::ps_round($cart_rule['obj']->getContextualValue($use_tax, $context, CartRule::FILTER_ACTION_GIFT, $package), _PS_PRICE_COMPUTE_PRECISION_);
}
// no discount for on sale products
foreach ($package_products as $product)
	if($product['on_sale'])	$order_total -= $use_tax ? $product['total_wt'] : $product['total'];
Edited by Cas

Share this post


Link to post
Share on other sites

Still can't get it to work in presta 1.6.

Is there really no way to do this without changing the code? Can someone make a simple module that insert the correct code in the right place? 

Share this post


Link to post
Share on other sites

Hi everybody,

my CartRule.php is more like this so i don't know where to insert the code or if it will work at all..

// Do not give a reduction on free products!
				$order_total = $context->cart->getOrderTotal($use_tax, Cart::ONLY_PRODUCTS, $package_products);
				foreach ($context->cart->getCartRules(CartRule::FILTER_ACTION_GIFT) as $cart_rule)
					$order_total -= Tools::ps_round($cart_rule['obj']->getContextualValue($use_tax, $context, CartRule::FILTER_ACTION_GIFT, $package), _PS_PRICE_COMPUTE_PRECISION_);

				$reduction_value += $order_total * $this->reduction_percent / 100;
			}


 

Share this post


Link to post
Share on other sites

This code

  1. foreach ($package_products as $product)
  2. if($product['on_sale']) $order_total -= $use_tax ? $product['total_wt'] : $product['total'];

 

from post #52 works on PS 1.6.1.3 (although it makes no sense)

BUT ONLY for percent discounts....

 

It is not working if the discount is an amount :(

Share this post


Link to post
Share on other sites

Hey guys is there any solution how to count in cart how much products is in discount and how much products from the same cart is not in discount ? 

 

I need to use my function when there are only products in discount. so i need check if there are some products which are not in discount. 

 

 

Thanks.

Share this post


Link to post
Share on other sites

Hi. I found (damn!) issue with this mod

 

When i add product that is disabled to use with Voucher and add him to cart i have correct info that voucher dont work with this product. But when i add product that is valid with this voucher the voucher works for both products (not only for the valid product but the disabled  too!!) :(

Share this post


Link to post
Share on other sites

On PS 1.6.1.9 the solution #51 (https://www.prestashop.com/forums/topic/290274-disabling-discounts-cart-rules-to-items-already-on-sale/?p=2244540) worked GREAT! :)

 

- If I put an "On sale" product in cart, voucher does not apply
- If I put a regular price product, voucher works fine
- and most importantly, if I add two products, one discounted and one with full price, the discount is applied only to the full-priced one :) yay! :)

 

If you want to test the outcome, fiddle on the website: larysa.ro

 

A great solution indeed! Maybe PS could use it for a future feature?

 

The only (small) drawback is that the client is not being notified that his voucher was not applied. It just does not appear in summary.

But all in all it works great!

 

Many thanks, guys.

Share this post


Link to post
Share on other sites

I can't get this to work in 1.6.1.11 I have tried numerous ways to get this to work and can't, even built an overide and a plugin fix based off of the plugin suggested to no avail. What's more annoying is we have tons of experience in presta shop but this seems to baffle everyone.

Share this post


Link to post
Share on other sites

 

try this I'm using prestashop 1.6.0.9 it will remove the sale items from the discount computation

 

In CartRule.php find this if statement code 

 

// Discount (%) on the selection of products
if ($this->reduction_percent && $this->reduction_product == -2)

 and replace it with this code

 

// Discount (%) on the selection of products
if ($this->reduction_percent && $this->reduction_product == -2)
{
$selected_products_reduction = 0;
$selected_products = $this->checkProductRestrictions($context, 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))
{
if (!(Product::isDiscounted((int)$product['id_product']))){
$price = ($use_tax ? $product['price_wt'] : $product['price']);
$selected_products_reduction += $price * $product['cart_quantity'];
}
}
$reduction_value += $selected_products_reduction * $this->reduction_percent / 100;
}
 

 

 

This solution works on 1.6.0.4 but does anyone know how to show information to the customer that vouchers cannot be applied for already discounted products?

Edited by hakeryk2

Share this post


Link to post
Share on other sites

 

For me the solution in post #13 works fine so far.  (PS v1.6.1.3)

I had just a little confusion about the position to add the code.

I looked like the solution should be in the previous foreach loop but actually is a new foreach loop --> so put the code after the ending bracket }    ;-)

foreach ($context->cart->getCartRules(CartRule::FILTER_ACTION_GIFT) as $cart_rule) {
    $order_total -= Tools::ps_round($cart_rule['obj']->getContextualValue($use_tax, $context, CartRule::FILTER_ACTION_GIFT, $package), _PS_PRICE_COMPUTE_PRECISION_);
}
// no discount for on sale products
foreach ($package_products as $product)
	if($product['on_sale'])	$order_total -= $use_tax ? $product['total_wt'] : $product['total'];

 

I regret to resurrect this thread but even though the solution at post #51 worked great (been using it on all my shops for a while now) it seems we have a problem :(

 

I use a special "SALE" category where I associate all my reduced products. This is because Prestashop lacks ANOTHER very basic feature, which is product filtering on the dynamically generated "prices-drop" page. So I have to use a SALE category instead :( Not nice, PS, not nice.

 

Anyhow, the problem I ran into today is that if a product is both associated with the SALE category AND it's regular category, the the (fixed amount) voucher code gets applied in cart, even if I have it set up not to.

If I deselect it's regular category and leave checked only the SALE one, the voucher gets rejected (with warning and all) on the order page.

 

Thing is, I don't want to be forced to keep all my products that are on sale ISOLATED in a specific category!

 

As far as I can understand from the mods in post #51, it checks for reduced price and not for category association, therefore it shouldn't be doing this kind of trickery :)

 

Any ideas? [Feel free to test this on the live site (condurbyalexandru.com)]

Edited by Attrexx

Share this post


Link to post
Share on other sites

×

Important Information

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