Author Topic: Discount as a percentage  (Read 2671 times)

edmaxsk

  • Beginner
  • *
  • Posts: 3
    • EDMAX.sk
Discount as a percentage
« 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.

AH

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 2979
  • VirtueMart Version: 3.6.3
Re: Discount as a percentage
« Reply #1 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
}

regards
A

Joomla 3.9.12
php 7.2

edmaxsk

  • Beginner
  • *
  • Posts: 3
    • EDMAX.sk
Re: Discount as a percentage
« Reply #2 on: July 31, 2015, 01:37:50 am »
Hi Hutson,

thank you, code is OK.

raunhar

  • Jr. Member
  • **
  • Posts: 241
Re: Discount as a percentage
« Reply #3 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).

jenkinhill

  • UK Web Developer & Consultant
  • Global Moderator
  • Super Hero
  • *
  • Posts: 27541
  • Always on vacation
    • Jenkin Hill Internet
Kelvyn

Jenkin Hill Internet,
Lowestoft, Suffolk, UK

Unsolicited PMs/emails will be ignored.

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

Currently using VM 3.6.3.10163 on Joomla 3.9.12 PHP 7.0.33

artonweb

  • Beginner
  • *
  • Posts: 18
    • Art On web
Re: Discount as a percentage
« Reply #5 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.


Thank you in advance.

I use VirtueMart 3.2.12 and Joomla 3.8.3.

Ghost

  • Jr. Member
  • **
  • Posts: 419
Re: Discount as a percentage
« Reply #6 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.