VirtueMart Forum

VirtueMart 2 + 3 + 4 => Product pricing => Topic started by: pm4698 on July 12, 2014, 12:01:00 PM

Title: Round discount price
Post by: pm4698 on July 12, 2014, 12:01:00 PM
Hello there,

I am trying to make decimals disappear from discount price with no success. I also tried round function with no success also. (when i try round function the discount value is set to zero).

Any ideas?

Thank you in advance
Title: Re: Round discount price
Post by: jenkinhill on July 12, 2014, 12:35:35 PM
Only the discount price? What VM version? Are you using template overrides?
Title: Re: Round discount price
Post by: pm4698 on July 12, 2014, 12:53:18 PM
Yes only discount price.

I use joomla 2.5.x and VirtueMart 2.6.2.

I have modified administrator/components/com_virtuemart/helpers/calculationh.php in order to show discount as percentage and not value

I use template override and in there i use this code to display discount price:

$varsmine=$this->currency->createPriceDiv ('discountAmount', '', $product->prices);
$newcurr= str_replace(chr(0xE2).chr(0x82).chr(0xAC), '', $varsmine);
$newcurr2=str_replace(',00','%',$newcurr);?>
                    <div style="width:70px;">
<?php echo  $newcurr;
?>

                        </div>


As you can see I echo discount after i have replaced Euro sign (chr(0xE2).chr(0x82).chr(0xAC)) with blank. Then with $newcurr2 i try to remove the decimals and replace with % value. If i do this and i echo newcurr2 then nothing happens. I see the same thing as echoing $newcurr
Title: Re: Round discount price
Post by: GJC Web Design on July 12, 2014, 15:06:46 PM
works fine here

$newcurr='200,00';
print 'Debug Line '.__LINE__.' $newcurr <pre>'; print_r ($newcurr); print "</pre><br />\n";
$newcurr2=str_replace(',00','%',$newcurr);
print 'Debug Line '.__LINE__.' $newcurr2 <pre>'; print_r ($newcurr2); print "</pre><br />\n";


Debug Line 30 $newcurr

200,00


Debug Line 32 $newcurr2

200%

are you using a comma as a decimal  - I would assume within calculationh.php  a point is being used as that is normal

try


$newcurr2=str_replace('.00','%',$newcurr);
Title: Re: Round discount price
Post by: pm4698 on July 12, 2014, 16:30:13 PM
I tried with . and not comma but still if i echo newcurr2 its the same as newcurr.

Actually, my discount values are not rounded. I have for example: 12,01 or 15,09 etc. So, maybe thats why str_replace doesn't work because i have no .00 at my string. So, how could i round up my discount price and then try again the str_string?