Hello,
I am using Virtuemart to make a pharmacy shop. What I am trying to do is ...
When I see all products of a category or when I am on homepage showing Featured Products, New Products, Best Sellers etc.
I want to show the discount in percentage on every product, only if it has a discount. If not, then I want nothing to appear.
The template I use now, instead of the discount, shows a "SALE" label.
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 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]
Hi Victoria,
the files you must modify should be found here:
Category view
templates\reviver\html\com_virtuemart\category\default.php
Front page
templates\reviver\html\com_virtuemart\virtuemart\default_products.php
I use a simple solution for the templates i develop that works also if you dont apply taxes to your products.
Just put the attached file in templates\reviver\html\com_virtuemart and include it in the files that you wish to display the label with the percentage like this
include JPATH_THEMES.'/reviver/html/com_virtuemart/vt_percentage.php';
then style it with css.
This will also work in product details page.
Here is the code of the attached file
<?php
// Check to ensure this file is included in Joomla!
defined ('_JEXEC') or die('Restricted access');
JFactory::getApplication();
$view = JRequest::getCmd('view');
if ($view == 'productdetails') {
if (!empty($this->product->prices['salesPrice'])) {
if ($this->product->prices['basePriceWithTax'] > 0){
$percentage = round($this->product->prices['discountAmount'] / $this->product->prices['basePriceWithTax'] * 100, 0) ;
} elseif ($product->prices['basePriceWithTax'] == 0) {
$percentage = round($this->product->prices['discountAmount'] / $this->product->prices['basePrice'] * 100, 0) ;
}
} else {
$percentage = 0;
}
if ($percentage < 0) {
echo '<span class="percentage">'.$percentage.'&#37;</span>';
}
} else {
if (!empty($product->prices['salesPrice'])) {
if ($product->prices['basePriceWithTax'] > 0){
$percentage = round($product->prices['discountAmount'] / $product->prices['basePriceWithTax'] * 100, 0) ;
} elseif ($product->prices['basePriceWithTax'] == 0) {
$percentage = round($product->prices['discountAmount'] / $product->prices['basePrice'] * 100, 0) ;
}
} else {
$percentage = 0;
}
if ($percentage < 0) {
echo '<span class="percentage">'.$percentage.'&#37;</span>';
}
}
?>
I hope this will help.
[attachment cleanup by admin]
Thank you very much for the reply.
I am working on this..
I'll let you know for the results, soon!!!
My method
//quorvia created discount percentage calculation and display to replace the discount value
if (round($product->prices['discountAmount'] != 0 )) {
$discount_percent = round(($product->prices['basePriceWithTax'] - $product->prices['salesPrice']) * 100 / $product->prices['basePriceWithTax']);
// $discount_amount_net = round(($product->prices['basePrice'] - $product->prices['priceBeforeTax']));
?>
<div class="discountAmount">
Save <?php echo $discount_percent; ?>%
</div>