Tags/topics: 
1
Answers
Vote up!
0
Vote down!

Round down discounted price to end with 0.99

I have used a rule to apply a discounts to prices. I now need to round the prices down to end in 0.99.

I have set up a module of "myfunctions" which includes a function called rounddownprice.

I now need to know how to call this function from a rule

function rounddownprice ($in) {
If ($in < 30.0) {
$roundprice = $in;
} Else {
$i1000 = Intval($in / 1000) * 1000;
$i100 = Intval($in / 100) * 100 - $i1000;
$i10 = Intval($in / 10) * 10 - $i100 - $i1000;
If ($i1000 == 0 and $i100 < 500) {
If ($i100 == 0) {
$i = $i10;
} Else {
$i = $i100;
If ($i10 < 30) {
} Else {
If ($i10 < 50) {
$i = $i + 30;
} Else {
If ($i10 < 80) {
$i = $i + 50;
} Else {
$i = $i + 80;
}
}
}
}
} Else {
$i = $i1000 + $i100;
If ($i10 < 50) {
} Else {
$i = $i + 50;
}
}
$roundprice = $i - 0.01;
}
return $roundprice;
}

Asked by: 1freethinker
on December 1, 2012

1 Answer

Vote up!
0
Vote down!

I have solved this.

I modified commerce.module to add another price rounding option.

So now when I choose the action "Multiply the unit price by some amount" I can now choose "Round down to 99 pricepoint" from the Price Rounding Mode list.

Email me if you want me to send you the code.

Answer by: 1freethinker
Posted: Dec 5, 2012