News:

Support the VirtueMart project and become a member

Main Menu

Discount as a percentage

Started by edmaxsk, July 30, 2015, 15:27:22 PM

Previous topic - Next topic

edmaxsk

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.

AH

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
}

Regards
A

Joomla 4.4.5
php 8.1

edmaxsk

Hi Hutson,

thank you, code is OK.

raunhar

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).

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

artonweb

#5
@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.


Thank you in advance.

I use VirtueMart 3.2.12 and Joomla 3.8.3.

Ghost

#6
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.