Custom rounding rules to product prices as a new type of calculation rule

Started by Genius WebDesign, September 15, 2012, 02:54:48 AM

Previous topic - Next topic

Genius WebDesign

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?


Milbo

There is no other way, then to change the function doing this in calculationh.php
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Genius WebDesign

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.

liquid.ideas

Hi Fabelmik,

How did you manage to do this? If you wouldnt mind sharing

Genius WebDesign

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;
}

liquid.ideas

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? ???

Genius WebDesign

$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).


liquid.ideas

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!

Genius WebDesign

You are welcome to send me a copy of your calculationh.php file. then I could try and implement the rounding rules for you.