Jump to content

Discount of total price


Recommended Posts

  • 2 weeks later...

modify the file: /classes/cart.php

line 663 in version 1.3.0 and 631 in version 1.2.5

change:

if ($type == 5) return $shipping_fees;
       if ($type == 6) return $wrapping_fees;
       if ($type == 3) $order_total += $shipping_fees + $wrapping_fees;
       if ($order_total < 0 AND $type != 2) return 0;



for:

if ($order_total >= 100 AND $order_total < 200) $order_total *= 95/100; /* For a purchase between 100 and 200, 5% discount */
       if ($order_total >= 200 AND $order_total < 400) $order_total *= 10/100; /* For a purchase between 200 and 400, 10% discount */
       if ($order_total >= 400) $order_total *= 85/100; /*Over 400, 15% discount */
       if ($type == 5) return $shipping_fees;
       if ($type == 6) return $wrapping_fees;
       if ($type == 3) $order_total += $shipping_fees + $wrapping_fees;
       if ($order_total < 0 AND $type != 2) return 0;




;-)

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

Thanks Anão de Jardim,

your solution is simple and looks that it works.

I do have additional quastion:
Is it possible to do similar (giving discount on total) but based on number of total items in cart.

Like:

- buy 2 items from our shop (can be different) and you will get 5 % discount on total price;
- buy 3 items from our shop (can be different) and you will get 10 % discount on total price




If anyone would know a solution please let us know.


Tomaz.

Link to comment
Share on other sites

  • 2 weeks later...

I have 3 criterias I would like to resolve for a discount. Maybe the voucher system would work if I can do the following

1. The customer has to live outside of USA and it's territories
2. The customer has to spend $100.00 or above.
3. If he/she meets the two above criterias, they will get 25% discount off of SHIPPING.

How can I work something like that into my shop?

Thank you!

Link to comment
Share on other sites

  • 4 months later...

thanks Anão de Jardim for this code! it appears to work perfectly*

We wanted to offer 3 products for a specific price, and this allows you to add a percentage discount to orders between a certain value. You can just work out the percentage discount and then add that to the code. Works well if all your products are the same price.

It would be good if there was any way to add additional text to the "total products" display of the cart summary once the discount has been applied - Anyone have any suggestions if this is possible?

This contribution also carries the discounts over to Paypal, the Better Together module currently doesn't do this, or even work properly it seems, didn't work for us anyway.

*UPDATE - SORRY - THIS CODE DOESN'T PASS THE DISCOUNT ONTO PAYPAL

Link to comment
Share on other sites


It would be good if there was any way to add additional text to the "total products" display of the cart summary once the discount has been applied - Anyone have any suggestions if this is possible?


I have same issue. Is there any way to implement this?
Link to comment
Share on other sites

This change will give the discount on the same amount allways, allso when changing Currencies?

A fix / change that added a voucher / discount instead would be nice. This would allso allow users to know why the sum of the cart is different that what the calculated.

Nice work anyways :)

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

Im still on the look for a module / change that allows the user a discount on the totalorder above X, but somehow adds a discount to the cart instead of just changing the ordertotal. Users might find this confuseing and leave!?

I was think about a version where a voucher is avalible for users, to use when ordertotal comes above x. But there are issue's to this:
- (voucher set to 1 use pr costumer) 2. time user want to add to the cart and get the discount it fails.
- (voucher can be used many time pr costumer) the user adds the same voucher 10 times and gets way to much discount!

Link to comment
Share on other sites

  • 1 month later...
  • 4 months later...

If i change the code, function perfectly, the total is changing how i put in cart.php....but i wanna show on shopping cart the total of discount ....not only the total discounted .......customers must see the discount.

Maybe u find it solution ...and maybe u can help me ..

Link to comment
Share on other sites

  • 1 month later...

Hi i put code like this in my cart.php

if ($order_total >= 50 AND $order_total < 100) $order_total *= 95/100; /* For a purchase between 50 and 100, 5% discount */
f ($order_total >= 101 AND $order_total < 1000) $order_total *= 10/100; /* For a purchase between 101 and 1000, 10% discount */
if ($type == 5) return $shipping_fees;
if ($type == 6) return $wrapping_fees;
if ($type == 3) $order_total += $shipping_fees + $wrapping_fees;
if ($order_total < 0 AND $type != 2) return 0;

then i did a test order which normally would of come to £54 but when i clicked on cart it is coming up at total of £7.90 how is this happening?

I want it so that orders between £50 - £100 get 5% off
an orders between £101- and £1000 get 10% off

can you help with coding please?

Link to comment
Share on other sites

Correct code is :

if ($order_total >= 50 AND $order_total < 100) $order_total = 95/100; / For a purchase between 50 and 100, 5% discount */
f ($order_total >= 101 AND $order_total < 1000) $order_total = 90/100; / For a purchase between 101 and 1000, 10% discount */
if ($type 5) return $shipping_fees; if ($type 6) return $wrapping_fees;
if ($type == 3) $order_total += $shipping_fees + $wrapping_fees;
if ($order_total < 0 AND $type != 2) return 0;

Link to comment
Share on other sites

Correct code is :

if ($order_total >= 50 AND $order_total < 100) $order_total = 95/100; / For a purchase between 50 and 100, 5% discount */
f ($order_total >= 101 AND $order_total < 1000) $order_total = 90/100; / For a purchase between 101 and 1000, 10% discount */
if ($type 5) return $shipping_fees; if ($type 6) return $wrapping_fees;
if ($type == 3) $order_total += $shipping_fees + $wrapping_fees;
if ($order_total < 0 AND $type != 2) return 0;


Just copied and pasted this code and it crashed website, was getting message say server error 500.

good job i backed up original file
Link to comment
Share on other sites

  • 2 months later...
  • 4 weeks later...

Hi and thanks for this solution, works like a charm :D - I'm looking for a way to add a message that - if you have a reached the discoutn amount of 500,- € in my case - there should be a message in the shopping cart / shopping cart template that customers can actually see that they have a discount. Otherwise it just reduces the total amount and everybody is wondering why he/she is paying less :P

Where do I have to change what? shopping-cart.tpl? cart.php?

Any help is highly appreciated :D Thx.

Link to comment
Share on other sites

  • 4 weeks later...

Hi and thanks for this solution, works like a charm :D - I'm looking for a way to add a message that - if you have a reached the discoutn amount of 500,- € in my case - there should be a message in the shopping cart / shopping cart template that customers can actually see that they have a discount. Otherwise it just reduces the total amount and everybody is wondering why he/she is paying less :P<br/><br/>Where do I have to change what? shopping-cart.tpl? cart.php? <br/><br/>Any help is highly appreciated :D Thx.

 

Anyone can help me on this?

Link to comment
Share on other sites

  • 4 weeks later...

modify the file: /classes/cart.php

line 663 in version 1.3.0 and 631 in version 1.2.5

change:

if ($type == 5) return $shipping_fees;
	if ($type == 6) return $wrapping_fees;
	if ($type == 3) $order_total += $shipping_fees + $wrapping_fees;
	if ($order_total < 0 AND $type != 2) return 0;

for:

if ($order_total >= 100 AND $order_total < 200) $order_total *= 95/100; /* For a purchase between 100 and 200, 5% discount */
	if ($order_total >= 200 AND $order_total < 400) $order_total *= 10/100; /* For a purchase between 200 and 400, 10% discount */
	if ($order_total >= 400) $order_total *= 85/100; /*Over 400, 15% discount */
	if ($type == 5) return $shipping_fees;
	if ($type == 6) return $wrapping_fees;
	if ($type == 3) $order_total += $shipping_fees + $wrapping_fees;
	if ($order_total < 0 AND $type != 2) return 0;

;-)

 

How is this discount visible on invoice?

Link to comment
Share on other sites

Hi all,

only to understand....

Why are you trying to edit a core class like "/classes/cart.php"? After each update you'll lose your changes and maybe they could not be applicable to the new release.

Since Prestashop gives us to solution to change its behavior, modules and overriding (the last one only from 1.4.x), we should apply those ones. And remember that core classes are protected by a specific license.

To make the wished thing in my opinion it should be necessary to write a module handling the "New order" hook. When a new order is posted in the system, a specific voucher is created and added to it. In this way all will works: the back office, the emails sent to the customer, the invoices etc etc..

 

What do you think?

Regards,

Jacky75

Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...

Hi

 

I am using 1.3.1.1, This is an old project and one of our developers implemented this hack to give a discount of 5% for orders between 250 and 500 and 7% between 500 and 1000 and 15% for orders over 1000.

 

The amount taken off the total price is correct but we are displaying the discount amount separately in the cart and this amount is not correct even though the total price shown is! Therefore the discount amount is being altered somewhere else in the code and Iv no idea where?

 

You can see the problem yourself if you go to http://www.easyspacedesign.com/craig/isle-of-bute2/ and add products to cart at a value between 250 and 500.

You will see in the cart total price at the top then the discount amount then the Total products (tax incl.). If you take 5% off the total price you will see that Total products (tax incl.) is the correct value however the value shown in the discount amount is approximately 20% less than what it should.

 

Here is the code of our hack:

if ($order_total >= 250 AND $order_total < 500){
  $order_total2 = 0.95 * $order_total; /* For a purchase between 250 and 500, 5% discount */
			    $discount_total = $order_total - $order_total2;
			    $order_total = $order_total2;
			    echo $discount_total;

  }
 if ($order_total >= 500 AND $order_total < 1000){
  $order_total = 0.93 * $order_total; /* For a purchase between 500 and 1000, 7% discount */
  $discount_total = 0.07 * $order_total;
  }
 if ($order_total >= 1000){
  $order_total = 0.85 * $order_total; /* For a purchase over 1000, 15% discount */
  $discount_total = 0.15 * $order_total;
  }
 if ($type == 5) return $shipping_fees;
 if ($type == 6) return $wrapping_fees;
 if ($type == 3) $order_total += $shipping_fees + $wrapping_fees;
 if ($order_total < 0 AND $type != 2) return 0;


	    if($type==8){ return Tools::ps_round(floatval($discount_total), 2); }

 return Tools::ps_round(floatval($order_total), 2);

 

The calculations in the above code is correct and I have echo'd out $discount_total; and it shows the correct discount amount yet when it is shown in the cart the amount has been altered.

 

Anybody got any ideas on this? Its driving me nuts. I am an intermediate level php developer but Iv never used prestashop and don't really no how the system works. I have feeling that it has something to do with the smartly template and the VAT being taken off the discount amount but I just cant find where this is happening!

Link to comment
Share on other sites

  • 3 weeks later...

Hey, This is just what Im looking for, How do I go about adding this is version v1.4?

Thanks

 

For me the same problem. I have version 1.4. The code is different from 1.4 cart.php

 

Can I paste the code mentioned above? If so, where should it be?

If not, what is the new code

 

I also searched for modules, but there are no modules for this ''problem''. If more people want this fixed too would still be there?

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 months later...
  • 9 months later...
  • 1 month later...
  • 1 month later...
  • 1 year later...

modify the file: /classes/cart.php

 

line 663 in version 1.3.0 and 631 in version 1.2.5

 

change:

 

if ($type == 5) return $shipping_fees;        if ($type == 6) return $wrapping_fees;        if ($type == 3) $order_total += $shipping_fees + $wrapping_fees;        if ($order_total < 0 AND $type != 2) return 0;

for:

 

if ($order_total >= 100 AND $order_total < 200) $order_total *= 95/100; /* For a purchase between 100 and 200, 5% discount */        if ($order_total >= 200 AND $order_total < 400) $order_total *= 10/100; /* For a purchase between 200 and 400, 10% discount */        if ($order_total >= 400) $order_total *= 85/100; /*Over 400, 15% discount */        if ($type == 5) return $shipping_fees;        if ($type == 6) return $wrapping_fees;        if ($type == 3) $order_total += $shipping_fees + $wrapping_fees;        if ($order_total < 0 AND $type != 2) return 0;

 

;-)

 

Hi, There

 

Nice job.

How can i do same thing on Prestashop 1.4.x  ???

Becouse cart.php is different.

 

Thanks,

Andrew

Link to comment
Share on other sites

  • 2 years later...

In my front page. There are 3 products available.

 

The first and second product discount value is getting correctly.

 

Third product discount value is wrong.

 

How to resolve this problem.

 

I attached my image url .

 

https://ibb.co/kAr3sF

 

Please give me any idea to resolve this problem.

Edited by kirubanidhi (see edit history)
Link to comment
Share on other sites

  • 1 year later...

Any idea how to disabling this discount price for products who are allready "on sale"?

if ($order_total >= 1000) $order_total = $order_total_discount + (($order_total - $order_total_discount) * 95/100);

will no work of course because $order_total_discount does not return the value of all products in the other promotion.

In higher versions then 1.4 in classes/CartRule.php there is some code like this:

// 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);

and there is simple, need to add after this some code like this:

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'];

The "//" comment coz in lower versions eg, 1.5 there is no declaration 'on_sale'

but in 1.4 Cart.php there is no such thing like that :(

To explain idea. I need some variable or function  to return allready discounted products in Cart

to not give them 5% discounts but calculate them to >=1000 .

in 1.4 Cart.php there is some above like this:

				/* Secondly applying all vouchers to the correct amount */
				$shrunk = false;
				foreach ($discounts AS $discount)
					if ($discount->id_discount_type != 3)
					{
						$order_total -= Tools::ps_round((float)($discount->getValue(sizeof($discounts), $order_total_products, $shipping_fees, $this->id, (int)($withTaxes))), 2);
						if ($discount->id_discount_type == 2)
							if (in_array($discount->behavior_not_exhausted, array(1,2)))
								$shrunk = true;
					}

but im not pretty sure what return: Tools::ps_round((float)($discount->getValue(sizeof($discounts)

 

Anybody help?

greedzz

SAJ

Edited by Spider A.J. (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...