News:

Support the VirtueMart project and become a member

Main Menu

show discount percentage

Started by jportiyo, February 21, 2013, 21:18:01 PM

Previous topic - Next topic

jportiyo

Hello.
I need to show my discount percentages.
Now shown as follows:

Discount: € XXX

I need:

Discount: XX%

Can anyone help?
thanks

jportiyo

#1
Hello. I answered myself. I found the solution in this post:

http://forum.virtuemart.net/index.php?topic=96175.msg364742#msg364742

I have made some changes in some of the code and share it. I'm porgramador.
Simply follow the code and had already substituted the variables "product": "$ this-> product-> prices" within the file: components / com_virtuemart / view / ProductDetails / tmpl / default.php. In my case I alter that file but in my template purchased (http://www.flexiblewebdesign.com). It is also easy to modify in Category view or where you need it.

My modifications.

<?php
if ($this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$this->product->prices))
{
$discount=$this->currency->formatNumber($this->product->prices['discountAmount']);
$pricewithtax $this->currency->formatNumber($this->product->prices['basePriceWithTax']);
$total =($discount 100) / $pricewithtax;
echo "Descuento: ".$total."%";
}
?>



Original Code: Inopia

if ($this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices))
{
$discount=$this->currency->formatNumber($product->prices['discountAmount']);
$pricewithtax = $this->currency->formatNumber($product->prices['basePriceWithTax']);
$total =($discount * 100) / $pricewithtax;
echo "Descuento: ".$total."%";
}




It works great, the problem is the decimal but I think that's very easy to fix, I do not need to explain.


THANKS YOU VERY MUCH to Inopia and this forum.

jportiyo

Again here:

I saw that he had caught some problems.
1. Even without the percentage shown off to "0" (if the checkbox "show off" was enabled on the Admin)
2. I solved the decimals so a little dirty.

Attach the code:


<?php 
if (
$this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$this->product->prices))
{
$discount=$this->currency->formatNumber($this->product->prices['discountAmount']);
$pricewithtax $this->currency->formatNumber($this->product->prices['basePriceWithTax']);
$total =($discount 100) / $pricewithtax;
$total2 explode(".",$total); 
if($total2[0]>){echo "<div class='dto_clase'>Dto: ".$total2[0]."%</div>";}
}
?>



byebye

karuppiah

In virtuemart 2.0 We can display discount percentage in two simple steps,

Step 1:
Open,administrator/components/com_virtuemart/helpers/calculationh.php,

Around line 352,you can find this line $prices['discountAmount'] = $this->roundInternal($basePriceWithTax - $salesPrice);

Replace with,$prices['discountAmount'] = $this->roundInternal(($basePriceWithTax - $prices['salesPrice']) * 100 / $basePriceWithTax);

here i am doing simple % calculation so the percentage of product will be shown like this for ex,$20.00

Step2:

In product detailed page or category pages,

To display default discount this code is used, $this->currency->createPriceDiv('discountAmount', 'COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT', $this->product->prices);

Assign the variable for this code like,

$vars=$this->currency->createPriceDiv('discountAmount', 'COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT', $this->product->prices);

to remove the currency symbol and decinal points use string replace like below,

$cuur1= str_replace('$(your currency symbol)','',$vars);
echo $cuur2= str_replace('.00','%',$cuur1);

Now the amount will be dsipalyed as percentage.
karuppiah

zakgr

Quote from: karuppiah on July 30, 2013, 12:31:19 PM
In virtuemart 2.0 We can display discount percentage in two simple steps,

Step 1:
Open,administrator/components/com_virtuemart/helpers/calculationh.php,

Around line 352,you can find this line $prices['discountAmount'] = $this->roundInternal($basePriceWithTax - $salesPrice);

Replace with,$prices['discountAmount'] = $this->roundInternal(($basePriceWithTax - $prices['salesPrice']) * 100 / $basePriceWithTax);

here i am doing simple % calculation so the percentage of product will be shown like this for ex,$20.00

Step2:

In product detailed page or category pages,

To display default discount this code is used, $this->currency->createPriceDiv('discountAmount', 'COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT', $this->product->prices);

Assign the variable for this code like,

$vars=$this->currency->createPriceDiv('discountAmount', 'COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT', $this->product->prices);

to remove the currency symbol and decinal points use string replace like below,

$cuur1= str_replace('$(your currency symbol)','',$vars);
echo $cuur2= str_replace('.00','%',$cuur1);

Now the amount will be dsipalyed as percentage.





Hi in step 1 how you remove the % ?

victoria_b

#5
Hello,
I am using Virtuemart to make a pharmacy shop and I am trying to do something similar: I want to show the discount in percentage on every product which has a discount.
If a product does not have a discount, then I want nothing to appear.
As the the template I use is now.. instead of the discount there is a "SALE" label that appears.
So, I want, instead of this label, to show the discount in percentage only if there is one. (please see image)

I would appreciate any help on how to do that and on which *.php file I should change.

Thank you in advance,
Victoria.

NOTE: I am using   -Joomla! 2.5.24, VirtueMart 2.6.10,  Template Reviver

[attachment cleanup by admin]

titolin10

I'm looking for solution also

I use VM 3.2.4


I have created a new topic regarding to this request and I hope it is not a spam.


Thank you for help in advance.

eclipsada

Hi,
Could you please give me the link of the new topic?
Have you found out the solution?

Regards,

jenkinhill

Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum