VirtueMart Forum

VirtueMart 2 + 3 + 4 => Administration & Configuration => Topic started by: Genius WebDesign on September 15, 2012, 02:54:48 AM

Title: Custom rounding rules to product prices as a new type of calculation rule
Post by: Genius WebDesign on September 15, 2012, 02:54:48 AM
Hi,

I have made some rounding rules that I want to apply to all the product prices (price after tax and discounts).
The rounding rules follow these examples:

If price after taxes and discounts > 99.99 then 100.50 = 100.95, 110.49 = 110.95, 345.00 = 344.95 and so on..

I want to make these rounding rules work the same way the build in calculation rules do, so that when the "override sales price" checkbox is checked then the rounding rules do not apply to the final sales price.

Does anyone know a good way to do this?

Title: Re: Custom rounding rules to product prices as a new type of calculation rule
Post by: Milbo on February 02, 2013, 10:28:04 AM
There is no other way, then to change the function doing this in calculationh.php
Title: Re: Custom rounding rules to product prices as a new type of calculation rule
Post by: Genius WebDesign on February 02, 2013, 13:03:22 PM
Thanks Milbo,

Meanwhile I have actually made the modifications in the calculationh.php file, so now everything is rounded the way I want it to.
Title: Re: Custom rounding rules to product prices as a new type of calculation rule
Post by: liquid.ideas on July 19, 2013, 11:13:18 AM
Hi Fabelmik,

How did you manage to do this? If you wouldnt mind sharing
Title: Re: Custom rounding rules to product prices as a new type of calculation rule
Post by: Genius WebDesign on July 19, 2013, 12:17:21 PM
Hi liquid.ideas,

It was pretty simple actually.

1. Open /administrator/components/com_virtuemart/helpers/calculationh.php

2. At line 330 (ca.) just after :

$prices['salesPriceTemp'] = $prices['salesPrice'];
//Okey, this may not the best place, but atm we handle the override price as salesPrice
if ($override) {
$prices['salesPrice'] = $product_override_price;
// $prices['discountedPriceWithoutTax'] = $this->product_override_price;
// $prices['salesPriceWithDiscount'] = $this->product_override_price;
}


add your rounding rules like this example:

// Custom Price Roundings
if ($prices['salesPrice'] <= 20 && empty($override)) {
$prices['salesPrice'] = ceil($prices['salesPrice']) - 0.05;
}
if ($prices['salesPrice'] > 20 && $prices['salesPrice'] <= 100 && empty($override)) {
$prices['salesPrice'] = round($prices['salesPrice'], 0) - 0.05;
}
if ($prices['salesPrice'] > 100 && $prices['salesPrice'] < 995 && empty($override)) {
$prices['salesPrice'] = round($prices['salesPrice'], -1) - 0.05;
}
if ($prices['salesPrice'] >= 995 && $prices['salesPrice'] < 100000 && empty($override)) {
$prices['salesPrice'] = round($prices['salesPrice'], -1) - 1;
}
Title: Re: Custom rounding rules to product prices as a new type of calculation rule
Post by: liquid.ideas on July 23, 2013, 12:35:51 PM
Hmmm, I cant figure this out. Maybe this is modifying the price before tax? All I want to do is round the price after tax to .95 any ideas? ???
Title: Re: Custom rounding rules to product prices as a new type of calculation rule
Post by: Genius WebDesign on July 23, 2013, 16:54:02 PM
$prices['salesPrice'] is for the final sales price, so it should work.
It is important that $prices['salesPrice'] is not redefined later in your code (after the rounding code).

Title: Re: Custom rounding rules to product prices as a new type of calculation rule
Post by: liquid.ideas on July 26, 2013, 09:05:43 AM
Thanks fabelmik, Ill stuff around today and let you know what I come up with! Your code looked slightly different to mine, maybe we are on different versions and the code is redefined after that!
Title: Re: Custom rounding rules to product prices as a new type of calculation rule
Post by: Genius WebDesign on July 26, 2013, 14:56:55 PM
You are welcome to send me a copy of your calculationh.php file. then I could try and implement the rounding rules for you.