Author Topic: show discount percentage  (Read 4204 times)

jportiyo

  • Beginner
  • *
  • Posts: 3
show discount percentage
« on: February 21, 2013, 21:18:01 pm »
Hello.
I need to show my discount percentages.
Now shown as follows:

Discount: € XXX

I need:

Discount: XX%

Can anyone help?
thanks

jportiyo

  • Beginner
  • *
  • Posts: 3
Re: show discount percentage
« Reply #1 on: February 22, 2013, 02:26:43 am »
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.
Code: [Select]
<?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
Code: [Select]
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

  • Beginner
  • *
  • Posts: 3
Re: show discount percentage
« Reply #2 on: February 22, 2013, 06:20:24 am »
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:

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

  • Beginner
  • *
  • Posts: 38
Re: show discount percentage
« Reply #3 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.
karuppiah

zakgr

  • Beginner
  • *
  • Posts: 8
Re: show discount percentage
« Reply #4 on: August 19, 2013, 18:02:45 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

  • Beginner
  • *
  • Posts: 7
Re: show discount percentage
« Reply #5 on: November 03, 2014, 14:17:01 pm »
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

  • Beginner
  • *
  • Posts: 18
  • A beginner
Re: show discount percentage
« Reply #6 on: November 13, 2017, 15:40:51 pm »
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.