Author Topic: Custom rounding rules to product prices as a new type of calculation rule  (Read 2426 times)

Genius WebDesign

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 175
    • 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

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10094
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Custom rounding rules to product prices as a new type of calculation rule
« Reply #1 on: February 02, 2013, 10:28:04 am »
There is no other way, then to change the function doing this in calculationh.php
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Genius WebDesign

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 175
    • Genius WebDesign
Re: Custom rounding rules to product prices as a new type of calculation rule
« Reply #2 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.

liquid.ideas

  • Jr. Member
  • **
  • Posts: 90
Hi Fabelmik,

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

Genius WebDesign

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 175
    • 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 :

Code: [Select]
$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:

Code: [Select]
// 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

  • Jr. Member
  • **
  • Posts: 90
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

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 175
    • 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

  • Jr. Member
  • **
  • Posts: 90
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

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 175
    • 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.