How do I show the percentage of discounts in view products in categories and also in detail product?
Which files and how do I adjust? I use VM3.0.9 and J3.4.3.
Thank you for your reply.
You need a price layout change
templates/yourtemplate/html/com_virtuemart/sublayouts/prices.php
//quorvia created discount percentage calculation and display to replace the discount value
if (round($product->prices['discountAmount'] != 0 )) {
// quorvia used a simpler method below $discount_percent = round(($product->prices['basePriceWithTax'] - $product->prices['salesPrice']) * 100 / $product->prices['basePriceWithTax']);
$discount_percent = round(($product->prices['discountAmount'] / $product->prices['basePriceVariant']) * 100);
?>
<div class="discountAmount">
Save <?php echo $discount_percent; ?>%
</div>
<?php
}
Hi Hutson,
thank you, code is OK.
If we need the option of Percent or Amount at the backend, then what do we do to have that.
Sometimes we offer discount as % and some times as fixed amount (flat 200 off).
Easy to select using calculation rules. http://docs.virtuemart.net/manual/general-concepts/204-tax-and-calculation-rules-overview.html
http://docs.virtuemart.net/manual/products-menu/taxes-and-calculation-rules.html
@AH
I have past your code to "prices.php" with total success.
Is there a way to use the the value of variable $discount_percent as a ribbon in picture of product.
I have already the css code in my template, I create the div as follow:
<div class="ribbon"><span>-<?php echo $discount_percent; ?>%</span></div>
in templates/my template/html/com_virtuemart/productdetails/default_images.php, but something qoing wrong with PHP code.
Please take a look at attachment pic.
(https://i.imgur.com/gG8j4Fx.jpg)
Thank you in advance.
I use VirtueMart 3.2.12 and Joomla 3.8.3.
You can't use data from prices.php in default_images.php. So you have to paste the same code in default_images.php (or default.php) and replace every instance of $product with $this->product.