VirtueMart Forum

VirtueMart 2 + 3 => Templating & Layouts => Topic started by: edmaxsk on July 30, 2015, 15:27:22 pm

Title: Discount as a percentage
Post by: edmaxsk on July 30, 2015, 15:27:22 pm
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.
Title: Re: Discount as a percentage
Post by: AH on July 30, 2015, 18:07:45 pm
You need a price layout change

templates/yourtemplate/html/com_virtuemart/sublayouts/prices.php


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

Title: Re: Discount as a percentage
Post by: edmaxsk on July 31, 2015, 01:37:50 am
Hi Hutson,

thank you, code is OK.
Title: Re: Discount as a percentage
Post by: raunhar on November 09, 2015, 08:20:13 am
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).
Title: Re: Discount as a percentage
Post by: jenkinhill on November 09, 2015, 09:56:25 am
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
Title: Re: Discount as a percentage
Post by: artonweb on January 21, 2018, 10:15:29 am
@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.
Title: Re: Discount as a percentage
Post by: Ghost on January 22, 2018, 07:59:30 am
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.