VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: arie on January 10, 2012, 14:24:45 PM

Title: show original price, discounted price and discount percentage
Post by: arie on January 10, 2012, 14:24:45 PM
Hi,

I've read quite some posts on the forum, but none of them seems to do what I want it do show. Basically, what I want it to show is like it is on the enclosed picture. Anyone an idea on how to get that?

greetings

Arie

[attachment cleanup by admin]
Title: Re: show original price, discounted price and discount percentage
Post by: tobisagt on January 10, 2012, 17:16:10 PM
Thats exacly what i've done!

But you need a little bit Corehack! So backup your file!

Open: currencydisplay.php in administrator/components/com_virtuemart/helpers/

Search for the line:  vmdebug('createPriceDiv $name '.$name.' '.$product_price[$name]);

Copy and paste the following code after the line above

// ==
// START MODIFICATION
// ==

// Checks if there is a discount.
if ($name == "discountAmount" && $vis == "none")
{
// If discount is empty (discountAmount) (display: none) it gives you an empty string instead of <div>
return "";
}

// If you have an discount and want to show the Price with Tax
if ($name == "basePriceWithTax")
{
// Checks if there is a discount.
if(!empty($product_price['discountAmount']))
{
// Discount exist: Show Price with Tax and with an extended CSS class
$css = "red";
return '<div class="Price'.$name.'" style="display : '.$vis.';" >'.$descr.'<span class="Price'.$name.' '.$css.'" >'.$product_price[$name].'</span></div>';
}
}

// ==
// END MODIFICATION
// ==


Next step:

Open your template file: default.php in your template folder /com_virtuemart/category/

Search for the line: echo $this->currency->createPriceDiv ( 'basePriceWithTax', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX', $this->product->prices );

Replace it with the following code: So the Price with Tax (old price) only show up if there is a discount.

if ($this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices)) {
    echo $this->currency->createPriceDiv('basePriceWithTax','COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX',$product->prices); }


Thats all. Maybe you need to change the order of your pricelist in your template to show it as you want.

Hope that was helpful!
Title: Re: show original price, discounted price and discount percentage
Post by: arie on January 11, 2012, 15:42:10 PM
Hi,

thanks a lot for this, it is a lot in the right direction. Just two other steps:
1. if there is a discount, create a line through the original base price (1225) a diagonal line would even be better, but I know how to get the css line-through as long as an identifier is added when there is a discount
2. show the discount in a percentage

Any clue on that?

Arie
Title: Re: show original price, discounted price and discount percentage
Post by: tobisagt on January 11, 2012, 16:14:04 PM
I tell you how i get this (if i understand you right)

First go into your virtuemart configuration -> Pricing.

Here you need to check the "show Price" button for:

- Baseprice with Tax, but without discounts
- Final salesprice
- Discount amount

If you dont need the others disable it.

What i want is to show the "Final Salesprice" as standard. Nothing more.
But if there is a discount he should show the Discound amount below and the Baseprice with Tax above with a line through.

Now follow the steps in my first post. He put an extra css class to your Baseprice "red".

To make a line through it copy this to your css:

.PricebasePriceWithTax .red {
text-decoration: line-through; }

That should work. You can change the css class "red" in the code as you want. "red" was just my opinion.

I dont know how to show the discount in a percentage, maybe you can try to play with "calculation rules"

EDIT: I add a attachment to show you how it looks like.

[attachment cleanup by admin]
Title: Re: show original price, discounted price and discount percentage
Post by: arie on January 11, 2012, 16:38:57 PM
perfect!

I changed that, and since I want the reduction to draw attention, I made that red.

Last problem is with the discount amount in a percentage. VM seems to calculate the discount from the priceWithTax, but, since I sell business only, that is not nice. How can I get the amount in a percentage or, if that is too difficult, calculate the discount from the priceWithoutTax

Thankx a lot so far

Arie

[attachment cleanup by admin]
Title: Re: show original price, discounted price and discount percentage
Post by: arie on January 14, 2012, 13:42:36 PM
Hi,

I've done some changing so in order to have it do what I want: show a line-through on the basePrice if there is one. Reduction, of shown, is always red. I have the reduction working (rather easily) but it does not show the linethrough on the baseprice if there is a reduction. Could you point me my mistake, please?

This is my/your edited code:
currencydisplay.php:
// Checks if there is a discount.
if ($name == "discountAmount" && $vis == "none")
{
// If discount is empty (discountAmount) (display: none) it gives you an empty string instead of <div>
return "";
}

// If you have an discount and want to show the Price without Tax
if ($name == "PricediscountAmount")
{
// Checks if there is a discount.
if(!empty($product_price['discountAmount']))
{
// Discount exist: Show Price without Tax and with an extended CSS class
$css = "line";
return '<div class="Price'.$name.'" style="display : '.$vis.';" >'.$descr.'<span class="Price'.$name.' '.$css.'" >'.$product_price[$name].'</span></div>';
}


category default.php
echo $this->currency->createPriceDiv('basePrice','COM_VIRTUEMART_PRODUCT_BASEPRICE',$product->prices);
if ($this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices)) {
     echo $this->currency->createPriceDiv('priceWithoutTax','COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX',$product->prices); }
echo $this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices);


CSS
.browse-view .row .product .spacer .PricebasePrice .line
{font-size:12px; color: #a0a0a0; font-weight: normal; display: inline;text-decoration:line-through;}


looking forward to your reply

Arie
Title: Re: show original price, discounted price and discount percentage
Post by: tobisagt on January 15, 2012, 00:35:46 AM
For better understanding tell me how it should look with and without discount and mark which price is Baseprice etc.
Title: Re: show original price, discounted price and discount percentage
Post by: arie on January 16, 2012, 09:08:19 AM
thanks for the reply. Basically, it should look like the picture as enclosed. The baseprice is the price with a 'linethrough'.  If there is no discount, the baseprice should be like the price in blue, in the picture that is the 'discounted price without tax'. In the enclosed picture I made the css in such a way that the baseprice is always displayed with a linethrough. Since that did not work out well for other products, it should be that way depending on whether there is a discount or not.

BTW any thought on discount as a percentage?

Greetz

Arie

[attachment cleanup by admin]
Title: Re: show original price, discounted price and discount percentage
Post by: notanothernumber on January 22, 2012, 22:42:20 PM
followed these instructions to the word but getting following error:

Parse error: parse error in C:\xampp\htdocs\costumeglitz.com.au\administrator\components\com_virtuemart\helpers\currencydisplay.php on line 447

Anyone any ideas??
Title: Re: show original price, discounted price and discount percentage
Post by: arie on January 23, 2012, 08:17:01 AM
had something like that myself. I made a mistake in copy-pasting the code so a '{' or '}' was in the wrong place or missing so that an if / loop.... statement ended too soon/late or that php code went on longer/shorter than expected. Anything like that?

otherwise, post the code.

Arie
Title: Re: show original price, discounted price and discount percentage
Post by: notanothernumber on January 25, 2012, 02:25:20 AM
Arie you were right I missed copying the end bit of the code. Got it working now but unfortunately still not perfect. Basically it has hidden the base price on every page now even when there is a discount and I want to show it just so people can see their saving!! I altered as follows:


In administrator/components/com_virtuemart/helpers/currencydisplay.php I added following code after -  //          vmdebug('createPriceDiv $name '.$name.' '.$product_price[$name]);

// ==
// START MODIFICATION
// ==

// Checks if there is a discount.
if ($name == "discountAmount" && $vis == "none")
{
// If discount is empty (discountAmount) (display: none) it gives you an empty string instead of <div>
return "";
}

// If you have an discount and want to show the Price with Tax
if ($name == "basePrice")
{
// Checks if there is a discount.
if(!empty($product_price['discountAmount']))
{
// Discount exist: Show Price with Tax and with an extended CSS class
$css = "red";
return '<div class="Price'.$name.'" style="display : '.$vis.';" >'.$descr.'<span class="Price'.$name.' '.$css.'" >'.$product_price[$name].'</span></div>';
}
}

// ==
// END MODIFICATION
// ==

In components/com_virtuemart/views/productdetails/tmpl/default.php from line 166 I changed code to:

echo $this->currency->createPriceDiv ( 'variantModification', 'COM_VIRTUEMART_PRODUCT_VARIANT_MOD', $this->product->prices );
echo $this->currency->createPriceDiv ( 'basePriceWithTax', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX', $this->product->prices );
echo $this->currency->createPriceDiv ( 'discountedPriceWithoutTax', 'COM_VIRTUEMART_PRODUCT_DISCOUNTED_PRICE', $this->product->prices );
echo $this->currency->createPriceDiv ( 'salesPriceWithDiscount', 'COM_VIRTUEMART_PRODUCT_SALESPRICE_WITH_DISCOUNT', $this->product->prices );
echo $this->currency->createPriceDiv ( 'priceWithoutTax', 'COM_VIRTUEMART_PRODUCT_SALESPRICE_WITHOUT_TAX', $this->product->prices );
if ($this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices)) {
echo $this->currency->createPriceDiv ( 'basePrice', 'COM_VIRTUEMART_PRODUCT_BASEPRICE', $this->product->prices ); }
echo $this->currency->createPriceDiv ( 'discountAmount', 'COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT', $this->product->prices );
echo $this->currency->createPriceDiv ( 'salesPrice', 'COM_VIRTUEMART_PRODUCT_SALESPRICE', $this->product->prices );
echo $this->currency->createPriceDiv ( 'taxAmount', 'COM_VIRTUEMART_PRODUCT_TAX_AMOUNT', $this->product->prices ); ?>


Any help appreciated!!
Title: Re: show original price, discounted price and discount percentage
Post by: arie on January 25, 2012, 16:24:55 PM
Hi,

I'm not an expert in php, but, did you turn it on in the administrator back-end? otherwise, does it show up anyway? It could also be that the output is hidden: you could check that by looking at the source of your page. There seem to be more trouble with displaying the baseprice; a difference between an RC and this stable version.

greetz Arie
Title: Re: show original price, discounted price and discount percentage
Post by: tobisagt on January 25, 2012, 16:28:13 PM
sry for my late response!

A friend helped me out with this modification. Im not a php expert.

I cant display the baseprice at all. I also tried a fresh joomla/virtuemart installation, it doesnt helped.
Title: Re: show original price, discounted price and discount percentage
Post by: Stamos on February 24, 2012, 15:04:11 PM
Nothing for me :(

That's my code in currencydisplay.php

if($this->_priceConfig[$name][2]) $descr = JText::_($description);
// vmdebug('createPriceDiv $name '.$name.' '.$product_price[$name]);
// ==
// START MODIFICATION
// ==

// Checks if there is a discount.
if ($name == "discountAmount" && $vis == "none")
{
// If discount is empty (discountAmount) (display: none) it gives you an empty string instead of <div>
return "";
}

// If you have an discount and want to show the Price with Tax
if ($name == "basePrice")
{
// Checks if there is a discount.
if(!empty($product_price['discountAmount']))
{
// Discount exist: Show Price with Tax and with an extended CSS class
$css = "red";
return '<div class="Price'.$name.'" style="display : '.$vis.';" >'.$descr.'<span class="Price'.$name.' '.$css.'" >'.$product_price[$name].'</span></div>';
}
}

// ==
// END MODIFICATION
// ==


return '<div class="Price'.$name.'" style="display : '.$vis.';" >'.$descr.'<span class="Price'.$name.'" ><b>:&nbsp '.$product_price[$name].'</b></span></div>';

}
}


Thats my code in default.php

// Product Price
if ($this->show_prices) { ?>
<div class="product-price" id="productPrice<?php echo $this->product->virtuemart_product_id ?>">
<?php
if ($this->product->product_unit && VmConfig::get 'price_show_packaging_pricelabel' )) {
echo "<p style='color: #D18949; font-size:14px'><strong>" JText::'COM_VIRTUEMART_CART_PRICE_PER_UNIT' ) . ' (' $this->product->product_unit "):</strong></p>";
} else {
echo "<p style='color: #D18949; font-size:14px'><strong>" JText::'COM_VIRTUEMART_CART_PRICE' ) . "</strong></p>";
}

if ($this->showBasePrice) {
echo $this->currency->createPriceDiv 'basePrice''COM_VIRTUEMART_PRODUCT_BASEPRICE'$this->product->prices );
echo $this->currency->createPriceDiv 'basePriceVariant''COM_VIRTUEMART_PRODUCT_BASEPRICE_VARIANT'$this->product->prices );
}

echo $this->currency->createPriceDiv 'variantModification''COM_VIRTUEMART_PRODUCT_VARIANT_MOD'$this->product->prices );
echo 
$this->currency->createPriceDiv 'basePriceWithTax''COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX'$this->product->prices );
echo 
$this->currency->createPriceDiv 'discountedPriceWithoutTax''COM_VIRTUEMART_PRODUCT_DISCOUNTED_PRICE'$this->product->prices );
echo 
$this->currency->createPriceDiv 'salesPriceWithDiscount''COM_VIRTUEMART_PRODUCT_SALESPRICE_WITH_DISCOUNT'$this->product->prices );
echo 
$this->currency->createPriceDiv 'priceWithoutTax''COM_VIRTUEMART_PRODUCT_SALESPRICE_WITHOUT_TAX'$this->product->prices );
if (
$this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices)) {
echo 
$this->currency->createPriceDiv 'basePrice''COM_VIRTUEMART_PRODUCT_BASEPRICE'$this->product->prices ); }
echo 
$this->currency->createPriceDiv 'discountAmount''COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT'$this->product->prices );
echo 
$this->currency->createPriceDiv 'salesPrice''COM_VIRTUEMART_PRODUCT_SALESPRICE'$this->product->prices );
echo 
$this->currency->createPriceDiv 'taxAmount''COM_VIRTUEMART_PRODUCT_TAX_AMOUNT'$this->product->prices ); ?>

</div>
<?php ?>
Title: Re: show original price, discounted price and discount percentage
Post by: soniamesotek10 on March 21, 2012, 11:35:16 AM
hi, i m new to Joomla & Virtue Mart, i installed 1.5 Joomla & Virtuemart version 2.0.0

1) i want  the same, show original price, discounted price and discount percentage but its showing only Sales price & Discount in my website

2) Also i want to change the font color as below:
a) original price--i want font with strike with line-through
b) discounted price --- red & bold font
c) discount---------green font

do i need to change any CSS for this,

thanks, please help
Title: Re: show original price, discounted price and discount percentage
Post by: tichor on April 03, 2012, 12:12:44 PM
Hello.

I was trying to do all steps to to see original price and and discount price. But in my default.php in  template folder html/com_virtuemart/category/ there is no line
echo $this->currency->createPriceDiv ( 'basePriceWithTax', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX', $this->product->prices );

I found that line in html/com_virtuemart/productdetails.

This is my code for file default.php in  template folder html/com_virtuemart/category/
<?php
/**
*
* Show the products in a category
*
* @package VirtueMart
* @subpackage
* @author RolandD
* @author Max Milbers
* @todo add pagination
* @link http://www.virtuemart.net
* @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* @version $Id: default.php 5120 2011-12-18 18:29:26Z electrocity $
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
JHTML::_'behavior.modal' );
/* javascript for list Slide
  Only here for the order list
  can be changed by the template maker
*/
$js "
jQuery(document).ready(function () {
jQuery('.orderlistcontainer').hover(
function() { jQuery(this).find('.orderlist').stop().show()},
function() { jQuery(this).find('.orderlist').stop().hide()}
)
});
"
;

$document JFactory::getDocument();
$document->addScriptDeclaration($js);
?>


<div class="category_description">
<?php echo $this->category->category_description ?>
</div>
<?php
/* Show child categories */

if ( VmConfig::get('showCategory',1) ) {
if ($this->category->haschildren) {

// Category and Columns Counter
$iCol 1;
$iCategory 1;

// Calculating Categories Per Row
$categories_per_row VmConfig::get 'categories_per_row');
$category_cellwidth ' width'.floor 100 $categories_per_row );

// Separator
$verticalseparator " vertical-separator";
?>

<div class="category-view">
<?php // Start the Output
if(!empty($this->category->children)){
foreach ( $this->category->children as $category ) {

// Show the horizontal seperator
if ($iCol == && $iCategory $categories_per_row) : ?>

<div class="horizontal-separator"></div>
<?php endif; ?>
<?php 
// this is an indicator wether a row needs to be opened or not
if ($iCol == 1) : 
?>

<div class="row">
<?php endif; ?>
<?php
// Show the vertical seperator
if ($iCategory == $categories_per_row or $iCategory $categories_per_row == 0) {
$show_vertical_separator ' ';
} else {
$show_vertical_separator $verticalseparator;
}

// Category Link
$caturl JRoute::'index.php?option=com_virtuemart&view=category&virtuemart_category_id=' $category->virtuemart_category_id );

// Show Category ?>

<div class="category floatleft<?php echo $category_cellwidth $show_vertical_separator ?>">
<div class="spacer">
<h2 class="catSub">
<a href="<?php echo $caturl ?>" title="<?php echo $category->category_name ?>">
<?php echo $category->category_name ?>


</a>
</h2>
<?php // if ($category->ids) {
echo $category->images[0]->displayMediaThumb("",false);
//} ?>

</div>
</div>
<?php
$iCategory ++;

// Do we need to close the current row now?
if ($iCol == $categories_per_row) { ?>

<div class="clear"></div>
</div>
<?php
$iCol 1;
} else {
$iCol ++;
}
}
}
// Do we need a final closing row tag?
if ($iCol != 1) { ?>

<div class="clear"></div>
</div>
<?php ?>
</div>
<?php }
}

// Show child categories
if (!empty($this->products)) {
if (!empty($this->keyword)) {
?>

<h3><?php echo $this->keyword?></h3>
<?php
}
?>

<?php // Category and Columns Counter
$iBrowseCol 1;
$iBrowseProduct 1;

// Calculating Products Per Row
$BrowseProducts_per_row $this->perRow;
$Browsecellwidth ' width'.floor 100 $BrowseProducts_per_row );

// Separator
$verticalseparator " vertical-separator";
?>

<div class="browse-view">
<h1><?php echo $this->category->category_name?></h1>
<form action="<?php echo JRoute::_('index.php?option=com_virtuemart&view=category&limitstart=0&virtuemart_category_id='.$this->category->virtuemart_category_id ); ?>" method="get">
<?php if ($this->search) { ?>
<!--BEGIN Search Box -->
<div class="virtuemart_search">
<?php echo $this->searchcustom ?>
<br />
<?php echo $this->searchcustomvalues ?>
<input style="height:16px;vertical-align :middle;" name="keyword" class="inputbox" type="text" size="20" value="<?php echo $this->keyword ?>" />
<input type="submit" value="<?php echo JText::_('COM_VIRTUEMART_SEARCH'?>" class="button" onclick="this.form.keyword.focus();"/>
</div>
<input type="hidden" name="search" value="true" />
<input type="hidden" name="view" value="category" />

<!-- End Search Box -->
<?php ?>
<div class="orderby-displaynumber">
<?php echo $this->orderByList['orderby']; ?>
<div class="display-number"><?php echo $this->vmPagination->getResultsCounter();?> <?php echo $this->vmPagination->getLimitBox(); ?></div>
</div>
</form>
<?php // Start the Output
foreach ( $this->products as $product ) {

// Show the horizontal seperator
if ($iBrowseCol == && $iBrowseProduct $BrowseProducts_per_row) { ?>

<div class="horizontal-separator"></div>
<?php }

// this is an indicator wether a row needs to be opened or not
if ($iBrowseCol == 1) { ?>

<div class="row">
<?php }

// Show the vertical seperator
if ($iBrowseProduct == $BrowseProducts_per_row or $iBrowseProduct $BrowseProducts_per_row == 0) {
$show_vertical_separator ' ';
} else {
$show_vertical_separator $verticalseparator;
}

// Show Products ?>

<div class="product floatleft<?php echo $Browsecellwidth $show_vertical_separator ?>">
<div class="spacer">
<div>
<?php /** @todo make image popup */
echo $product->images[0]->displayMediaThumb('class="browseProductImage" border="0" title="'.$product->product_name.'" ',true,'class="modal"');
?>


<!-- The "Average Customer Rating" Part -->
<?php if (VmConfig::get('pshop_allow_reviews') == 1) { ?>
<span class="contentpagetitle"><?php echo JText::_('COM_VIRTUEMART_CUSTOMER_RATING'?>:</span>
<br />
<?php
// $img_url = JURI::root().VmConfig::get('assets_general_path').'/reviews/'.$product->votes->rating.'.gif';
// echo JHTML::image($img_url, $product->votes->rating.' '.JText::_('COM_VIRTUEMART_REVIEW_STARS'));
// echo JText::_('COM_VIRTUEMART_TOTAL_VOTES').": ". $product->votes->allvotes; ?>

<?php ?>
</div>
<div>
<h3 class="catProductTitle"><?php echo JHTML::link($product->link$product->product_name); ?></h3>
<?php // Product Short Description
if(!empty($product->product_s_desc)) { ?>

<p class="product_s_desc">
<?php echo shopFunctionsF::limitStringByWord($product->product_s_desc40'...'?>
</p>
<?php ?>
<?php if (!VmConfig::get('use_as_catalog')){?>
<div class="stockLavel">
<span class="vmicon vm2-<?php echo $product->stock->stock_level ?>" title="<?php echo $product->stock->stock_tip ?>"></span>
<span class="stock-level"><?php echo JText::_('COM_VIRTUEMART_STOCK_LEVEL_DISPLAY_TITLE_TIP'?></span>
</div>
<?php }?>
<div class="catProductPrice" id="productPrice<?php echo $product->virtuemart_product_id ?>">
<?php
if ($this->show_prices == '1') {
if( $product->product_unit && VmConfig::get('vm_price_show_packaging_pricelabel')) {
echo "<strong>"JText::_('COM_VIRTUEMART_CART_PRICE_PER_UNIT').' ('.$product->product_unit."):</strong>";
}


echo $this->currency->createPriceDiv('salesPrice','',$product->prices);
echo $this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices);
echo $this->currency->createPriceDiv('taxAmount','COM_VIRTUEMART_PRODUCT_TAX_AMOUNT',$product->prices);

?>

</div>
<?php // Product Details Button
echo JHTML::link($product->linkJText::_('COM_VIRTUEMART_PRODUCT_DETAILS'), array('title' => $product->product_name,'class' => 'catProductDetails'));
?>

</div>
</div>
</div>
<?php
$iBrowseProduct ++;

// Do we need to close the current row now?
if ($iBrowseCol == $BrowseProducts_per_row) { ?>

</div>
<?php
$iBrowseCol 1;
} else {
$iBrowseCol ++;
}
}
// Do we need a final closing row tag?
if ($iBrowseCol != 1) { ?>

<div class="clear"></div>
</div>
<?php
}
?>

<div class="pagination">
<?php echo str_replace('</ul>''<li class="counter">'.$this->vmPagination->getPagesCounter().'</li></ul>'$this->vmPagination->getPagesLinks()); ?>
</div>
</div>
<?php ?>


Thx in advance for replay
Title: Re: show original price, discounted price and discount percentage
Post by: adrianpaun on April 12, 2012, 01:42:26 AM
I've finaly found a solution for productdetailed discount show with the baseprice, the new price (with discount) and the discount ammount.

First of all we need to activate in the virtuemart back-end in Configuration - > Pricing : Baseprice, Salesprice without tax, Final salesprice and Discount amount

What we will do is to create two pages for displaying the product detailet view, so first thing first:

1. Copy from component/com_virtuemart/views/productdetails/tmpl/default.php to  your template to make an override template for vm2: templates/your_template/html/com_virtuemart/productdetails/default.php

2. Edit this page

3. Find this code:


// Product Price

if ($this->show_prices and (empty($this->product->images[0]) or $this->product->images[0]->file_is_downloadable == 0)) {

    echo $this->loadTemplate('showprices');

}

?>


4. Replace it with this one wich  (you will find the full form in component/com_virtuemart/views/productdetails/tmpl/default_showprices.php if you need other strings)


// Product Price

if ($this->show_prices and (empty($this->product->images[0]) or $this->product->images[0]->file_is_downloadable == 0)) {

    ?>

//mod
//the standard line was <div class="product-price" id="productPrice<?php echo $this->product->virtuemart_product_id ?>">
//i've change the <?php echo $this->product->virtuemart_product_id ?> to class insead of id and create a unique id for this one calld productPriceDiscount (for css ussage)

<div class="product-price-detailed<?php echo $this->product->virtuemart_product_id ?>" id="productPriceDiscount">

//END mod

    <?php

    
if ($this->product->product_unit && VmConfig::get('price_show_packaging_pricelabel')) {

echo "<strong>" JText::_('COM_VIRTUEMART_CART_PRICE_PER_UNIT') . ' (' $this->product->product_unit "):</strong>";

    } else {

echo "<strong>" JText::_('COM_VIRTUEMART_CART_PRICE') . "</strong>";

    }

    if (empty(
$this->product->prices) and VmConfig::get('askprice'1)) {

?>


        <a class="ask-a-question bold" href="<?php echo $url ?>" ><?php echo JText::_('COM_VIRTUEMART_PRODUCT_ASKPRICE'?></a>

    <?php

    
}

//mod
// i've put baseprice, salesprice and discountamount to be shown.

    
echo $this->currency->createPriceDiv('basePrice''COM_VIRTUEMART_PRODUCT_BASEPRICE'$this->product->prices);

    echo 
$this->currency->createPriceDiv('salesPrice''COM_VIRTUEMART_PRODUCT_SALESPRICE'$this->product->prices);

    echo 
$this->currency->createPriceDiv('discountAmount''COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT'$this->product->prices);

//END mod
    
?>


               

</div>

<?php }

?>




6. We need to modify the css file so we have to add:


.PricediscountAmount{color:#FF0000;}
#productPriceDiscount { font-size:48px; letter-spacing:-2px; line-height:42px;border: 1px solid #E9E8E8;border-radius: 12px 12px 12px 12px; text-align:center; padding:10px 0; font-weight:700; color:#0066FF; }
#productPriceDiscount .PricebasePrice {text-decoration:line-through;color:#666;}


7. After we did this we will save this page with the name default_discount.php

8. now edit again the new page default_discount.php:

Find


    echo $this->currency->createPriceDiv('basePrice', 'COM_VIRTUEMART_PRODUCT_BASEPRICE', $this->product->prices);

    echo $this->currency->createPriceDiv('salesPrice', 'COM_VIRTUEMART_PRODUCT_SALESPRICE', $this->product->prices);

    echo $this->currency->createPriceDiv('discountAmount', 'COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT', $this->product->prices);


Replace it with:


echo $this->currency->createPriceDiv('salesPrice', '', $this->product->prices);


9. Save this page under default.php

10. Go to Virtuemart Back-End -> Products -> Select a product you want to make a discount -> select on Product Details Page -> default_discount and then put your discount in product Pricing - Override and check the box.

This should be it and you cand update you're Virtuemart without losing youre modifications.



[attachment cleanup by admin]
Title: Re: show original price, discounted price and discount percentage
Post by: szeor on April 22, 2012, 12:52:32 PM
Hi,
tobisagt, your code is brilliant, thank you.. but this code work only on category page and on homepage (new products, top ten products), but doesnt work product page (one product).

I dont understand something, or this code really doesnt work on only one product page? If is really doesnt work on one product page, what is the solution?

Thank you for answer.
Title: Re: show original price, discounted price and discount percentage
Post by: tobisagt on April 22, 2012, 16:14:20 PM
Quote from: szeor on April 22, 2012, 12:52:32 PM
Hi,
tobisagt, your code is brilliant, thank you.. but this code work only on category page and on homepage (new products, top ten products), but doesnt work product page (one product).

I dont understand something, or this code really doesnt work on only one product page? If is really doesnt work on one product page, what is the solution?

Thank you for answer.

Whats your code in productdetails?

For me, it works fine!
Title: Re: show original price, discounted price and discount percentage
Post by: szeor on April 22, 2012, 19:01:39 PM
Hi, thanks for the quick answer..
I had 3 files in components/com_virtuemart/view/productdeatil folder (pdf.php, default_pdf.php, ), where is this code:
echo $this->currency->createPriceDiv ( 'basePriceWithTax', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX', $this->product->prices );
but i changed in every files this code:
if ($this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices)) {
    echo $this->currency->createPriceDiv('basePriceWithTax','COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX',$product->prices); }


and of course changed codes in currencydisplay.php and in category folder, default.php, and work, except product details.
Title: Re: show original price, discounted price and discount percentage
Post by: szeor on April 22, 2012, 19:25:49 PM
adrianpaun, i test solution of your, but wrong code, or i dont know..
image:
http://kepfeltoltes.hu/120422/wrong_code_www.kepfeltoltes.hu_.jpg (http://kepfeltoltes.hu/120422/wrong_code_www.kepfeltoltes.hu_.jpg)

code in file (+/- 2-3 line):
if (is_array($this->productDisplayPayments)) {
    foreach ($this->productDisplayPayments as $productDisplayPayment) {
echo $productDisplayPayment . '<br />';
    }
}
// Product Price

if ($this->show_prices and (empty($this->product->images[0]) or $this->product->images[0]->file_is_downloadable == 0)) {

    ?>

//mod
//the standard line was <div class="product-price" id="productPrice<?php echo $this->product->virtuemart_product_id ?>">
//i've change the <?php echo $this->product->virtuemart_product_id ?> to class insead of id and create a unique id for this one calld productPriceDiscount (for css ussage)

<div class="product-price-detailed<?php echo $this->product->virtuemart_product_id ?>" id="productPriceDiscount">

//END mod

    <?php

    
if ($this->product->product_unit && VmConfig::get('price_show_packaging_pricelabel')) {

echo "<strong>" JText::_('COM_VIRTUEMART_CART_PRICE_PER_UNIT') . ' (' $this->product->product_unit "):</strong>";

    } else {

echo "<strong>" JText::_('COM_VIRTUEMART_CART_PRICE') . "</strong>";

    }

    if (empty(
$this->product->prices) and VmConfig::get('askprice'1)) {

?>


        <a class="ask-a-question bold" href="<?php echo $url ?>" ><?php echo JText::_('COM_VIRTUEMART_PRODUCT_ASKPRICE'?></a>

    <?php

    
}

//mod
// i've put baseprice, salesprice and discountamount to be shown.

    
echo $this->currency->createPriceDiv('basePrice''COM_VIRTUEMART_PRODUCT_BASEPRICE'$this->product->prices);

    echo 
$this->currency->createPriceDiv('salesPrice''COM_VIRTUEMART_PRODUCT_SALESPRICE'$this->product->prices);

    echo 
$this->currency->createPriceDiv('discountAmount''COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT'$this->product->prices);

//END mod
    
?>


               

</div>

<?php }

?>




<?php
// Add To Cart Button
//  if (!empty($this->product->prices) and !empty($this->product->images[0]) and $this->product->images[0]->file_is_downloadable==0 ) {
if (!VmConfig::get('use_as_catalog'0) and !empty($this->product->prices)) {
    echo $this->loadTemplate('addtocart');
}  // Add To Cart Button END
?>
Title: Re: show original price, discounted price and discount percentage
Post by: tobisagt on April 22, 2012, 22:44:33 PM
Quote from: szeor on April 22, 2012, 19:01:39 PM
Hi, thanks for the quick answer..
I had 3 files in components/com_virtuemart/view/productdeatil folder (pdf.php, default_pdf.php, ), where is this code:
echo $this->currency->createPriceDiv ( 'basePriceWithTax', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX', $this->product->prices );
but i changed in every files this code:
if ($this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices)) {
    echo $this->currency->createPriceDiv('basePriceWithTax','COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX',$product->prices); }


and of course changed codes in currencydisplay.php and in category folder, default.php, and work, except product details.

Dont you have a "default.php" in product details? Or is the "default_pdf.php" the default for your template?
Title: Re: show original price, discounted price and discount percentage
Post by: szeor on April 22, 2012, 23:34:16 PM
QuoteDont you have a "default.php" in product details? Or is the "default_pdf.php" the default for your template?
of course i have default.php, and default_pdf.php, but i dont found this code in the default.php file,
echo $this->currency->createPriceDiv ( 'basePriceWithTax', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX', $this->product->prices );
i changed codes only default_pdf, pdf and default_showprices.php files.

when i say default template is default or pdf, vm do nothing (i dont see old price with promotional product), but when i say default template is default_showprices, i see old price with promotional product, but i see with non promotional product, and i see double default price (I see the same price two).
Title: Re: show original price, discounted price and discount percentage
Post by: tobisagt on April 22, 2012, 23:54:17 PM
maybe you have a "default_showprices.php" ?
Title: Re: show original price, discounted price and discount percentage
Post by: szeor on April 23, 2012, 06:55:51 AM
Quotemaybe you have a "default_showprices.php" ?
im sorry, but i dont understand..
when i say default template is default.php or pdf.php, vm do nothing (i dont see old price with promotional product), but when i say default template is default_showprices, i see old price with promotional product, but i see with non promotional product, and i see double default price (I see the same price two).

Now? default is simple default, because
default template is default_pdf: no old price, custom fields, and cart button,
pdf: no old price and cart button (custom fields yes)
default_showprice: only price (no cart button, custom fields, image), but old price see with non promotional product (i see the same price two)
Title: Re: show original price, discounted price and discount percentage
Post by: szeor on April 24, 2012, 14:44:58 PM
Anyone? Any idea? :)
Thanks for answers..
Title: Re: show original price, discounted price and discount percentage
Post by: adrianpaun on April 25, 2012, 18:33:50 PM
default_pdf ?, i think that is for the other purpose not for a default frontpage wich is: default.php and includes both default_category.php and default_products.php.

For other information read this post http://forum.virtuemart.net/index.php?topic=101110.0, and it's working, maybe you dont have the show price active (all of them) in vm backend.
Title: Re: show original price, discounted price and discount percentage
Post by: szeor on May 01, 2012, 19:58:54 PM
other forum help do nothing, the problem is same.. if is work on promotional product page, i se same price to the non promotional product page, and i see on other forum, on example page...

http://andrei.peacock.ro/produse/produse-medicale/electrocardiografe/electrocardiograful-taidoc-td-8202-4-5-detalii (http://andrei.peacock.ro/produse/produse-medicale/electrocardiografe/electrocardiograful-taidoc-td-8202-4-5-detalii)
Title: Re: show original price, discounted price and discount percentage
Post by: szeor on May 01, 2012, 20:09:05 PM
Do you share your modified files? And your vm settings (files in rapidshare or something, setting is only written, ofc :) )?
I have no idea, but this thing doesnt work, i am forced to delete new version of virtuemart  :(
Title: Re: show original price, discounted price and discount percentage
Post by: Genius WebDesign on May 22, 2012, 17:38:31 PM
Hi tobisagt,

Thx for the awesome code!

After following your instructions and altering the currencydisplay.php and the default.php in both the "category" and "productdetails" folder in my template I have a few problems..

I'm using Joomla 2.5, Virtuemart 2.0.6 and I have the "Explore" template from http://www.virtuemarttemplates.net/ installed.

My problems are:

1. The decimals in my currency settings are set to 2 digits but after applying the code the "pricewithouttaxes" is shown with 4 digits decimals. Without the code-alteration it shows with 2 decimals correctly.
2. After applying the code alteration to the "productdetails"´ default.php file the "pricewithouttaxes" dont show up at all on the product details page.. Once I remove the altered code from the default-php file the pricewithouttaxes show up again but they of course do not disappear when there is no discount.

So, the code works, almost, perfectly in the "category" file but the same code makes problems in the "productdetails" file.

Pls. advice
Title: Re: show original price, discounted price and discount percentage
Post by: Genius WebDesign on May 25, 2012, 11:06:12 AM
Update..

After a quick reinstall and re-walkthrough of this thread I finally made it work as intended.
Title: Re: show original price, discounted price and discount percentage
Post by: efi on May 26, 2012, 18:05:11 PM
Open your template file: default.php in your template folder /com_virtuemart/category/


There is no path like this one.
I am using joomla 1.5.26 and virtuemart 2.0.6

can you please help me?
Title: Re: show original price, discounted price and discount percentage
Post by: rafitalx on May 28, 2012, 16:52:19 PM
Quote from: adrianpaun on April 12, 2012, 01:42:26 AM
I've finaly found a solution for productdetailed discount show with the baseprice, the new price (with discount) and the discount ammount.

First of all we need to activate in the virtuemart back-end in Configuration - > Pricing : Baseprice, Salesprice without tax, Final salesprice and Discount amount

What we will do is to create two pages for displaying the product detailet view, so first thing first:

1. Copy from component/com_virtuemart/views/productdetails/tmpl/default.php to  your template to make an override template for vm2: templates/your_template/html/com_virtuemart/productdetails/default.php

2. Edit this page

3. Find this code:


// Product Price

if ($this->show_prices and (empty($this->product->images[0]) or $this->product->images[0]->file_is_downloadable == 0)) {

    echo $this->loadTemplate('showprices');

}

?>


4. Replace it with this one wich  (you will find the full form in component/com_virtuemart/views/productdetails/tmpl/default_showprices.php if you need other strings)


// Product Price

if ($this->show_prices and (empty($this->product->images[0]) or $this->product->images[0]->file_is_downloadable == 0)) {

    ?>

//mod
//the standard line was <div class="product-price" id="productPrice<?php echo $this->product->virtuemart_product_id ?>">
//i've change the <?php echo $this->product->virtuemart_product_id ?> to class insead of id and create a unique id for this one calld productPriceDiscount (for css ussage)

<div class="product-price-detailed<?php echo $this->product->virtuemart_product_id ?>" id="productPriceDiscount">

//END mod

    <?php

    
if ($this->product->product_unit && VmConfig::get('price_show_packaging_pricelabel')) {

echo "<strong>" JText::_('COM_VIRTUEMART_CART_PRICE_PER_UNIT') . ' (' $this->product->product_unit "):</strong>";

    } else {

echo "<strong>" JText::_('COM_VIRTUEMART_CART_PRICE') . "</strong>";

    }

    if (empty(
$this->product->prices) and VmConfig::get('askprice'1)) {

?>


        <a class="ask-a-question bold" href="<?php echo $url ?>" ><?php echo JText::_('COM_VIRTUEMART_PRODUCT_ASKPRICE'?></a>

    <?php

    
}

//mod
// i've put baseprice, salesprice and discountamount to be shown.

    
echo $this->currency->createPriceDiv('basePrice''COM_VIRTUEMART_PRODUCT_BASEPRICE'$this->product->prices);

    echo 
$this->currency->createPriceDiv('salesPrice''COM_VIRTUEMART_PRODUCT_SALESPRICE'$this->product->prices);

    echo 
$this->currency->createPriceDiv('discountAmount''COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT'$this->product->prices);

//END mod
    
?>


               

</div>

<?php }

?>




6. We need to modify the css file so we have to add:


.PricediscountAmount{color:#FF0000;}
#productPriceDiscount { font-size:48px; letter-spacing:-2px; line-height:42px;border: 1px solid #E9E8E8;border-radius: 12px 12px 12px 12px; text-align:center; padding:10px 0; font-weight:700; color:#0066FF; }
#productPriceDiscount .PricebasePrice {text-decoration:line-through;color:#666;}


7. After we did this we will save this page with the name default_discount.php

8. now edit again the new page default_discount.php:

Find


    echo $this->currency->createPriceDiv('basePrice', 'COM_VIRTUEMART_PRODUCT_BASEPRICE', $this->product->prices);

    echo $this->currency->createPriceDiv('salesPrice', 'COM_VIRTUEMART_PRODUCT_SALESPRICE', $this->product->prices);

    echo $this->currency->createPriceDiv('discountAmount', 'COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT', $this->product->prices);


Replace it with:


echo $this->currency->createPriceDiv('salesPrice', '', $this->product->prices);


9. Save this page under default.php

10. Go to Virtuemart Back-End -> Products -> Select a product you want to make a discount -> select on Product Details Page -> default_discount and then put your discount in product Pricing - Override and check the box.

This should be it and you cand update you're Virtuemart without losing youre modifications.



Hi .. is great code but do not act the custom field.
help me please
Title: Re: show original price, discounted price and discount percentage
Post by: dream3w on June 02, 2012, 10:57:52 AM
Hi,

I've tried to make modifications as explain in these post but no good issue.

Is it possible to have some help to make that?

Im on J2.5.4 and VM2.0.6 (template Allrounder J1.6)

Greetings

Stephan
Title: Re: show original price, discounted price and discount percentage
Post by: dream3w on June 02, 2012, 13:53:28 PM
When I try to put code into currencydisplay.php, I've these result:

Notice: Undefined variable: vis in /homez.141/..../currencydisplay.php on line 366

What's wrong?
Title: Re: show original price, discounted price and discount percentage
Post by: MNCZ on June 07, 2012, 17:49:55 PM
I've also wanted to do the same thing.  I've followed tobisagt's instructions and it works.  However I have some problems with the formatting.

What I get is this:

Price:10
Sales price:       Discount: $1.00
$9.00

What I would like to see is this:

Price:$10.00
Sales price: $9.00      
Discount: $1.00

Can anyone help me please?
Title: Re: show original price, discounted price and discount percentage
Post by: mushino on June 19, 2012, 16:57:58 PM
Prices in default_products.php and other are showed as string. I have try to convert them as float or integer number but it seem impossible.
How we can extract prices as number?
In this case we can calculate discount percentage and show it.
Any idea?
Title: Re: show original price, discounted price and discount percentage
Post by: Genius WebDesign on June 22, 2012, 02:54:02 AM
QuotePrices in default_products.php and other are showed as string. I have try to convert them as float or integer number but it seem impossible.
How we can extract prices as number?
In this case we can calculate discount percentage and show it.
Any idea?

Read this:  http://forum.virtuemart.net/index.php?topic=103195.msg346799#msg346799

and this:  http://forum.virtuemart.net/index.php?topic=104194.msg346625#msg346625
Title: Re: show original price, discounted price and discount percentage
Post by: giupi on June 28, 2012, 11:41:59 AM
Hello,

can someone kindly make a summing up on how to get original price (barred), new price and discount (% or even only the amount off)?

In this post are several suggestions, but for every there something I can't get:

1) In the first reply of tobisagt I did not find in default.php in template folder /com_virtuemart/category/ the line: echo $this->currency->createPriceDiv ( 'basePriceWithTax', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX', $this->product->prices ); it seems that it's nowhere...

2) adrianpaun proposed a way, but at his point number 6 I did not understand what css to modify, and at his point 7 (save this page with the name default_discount.php) I did not understand which page to save... seems the css...????

3) all questions and answers are overlapping so you don't understand who's answering who...

Since I searched over the seven seas ;-) both this forum and italian forum for a solution, without getting any success, I would be very grateful to whoever could make a summing up (and possibily definitive) for getting the solution :-D

I would be also buy a kind of module/plugin if available...

Thank you in advance.
Title: Re: show original price, discounted price and discount percentage
Post by: Genius WebDesign on June 29, 2012, 15:03:46 PM
@giupi

If you want to you can do it the easy way by just echo' ing the price-values and making your own if-statements.
Read these posts, they pretty much cover all you need to make it the way you want;

http://forum.virtuemart.net/index.php?topic=103195.msg346799#msg346799

http://forum.virtuemart.net/index.php?topic=104194.msg346625#msg346625
Title: Re: show original price, discounted price and discount percentage
Post by: jmvtotu on June 30, 2012, 06:27:59 AM
http://www.formvote.com/discuss.php?postid=722960450914746
Title: Re: show original price, discounted price and discount percentage
Post by: giupi on June 30, 2012, 10:29:50 AM
Hello fabelmilk,

thank you for your answer... that's very kind of you, but I still didn't understand  :-[

In this post http://forum.virtuemart.net/index.php?topic=104194.msg346625 I don't understand what you have to do (practically) to get the result...

In the other post http://forum.virtuemart.net/index.php?topic=103195.msg346799#msg346799 in which position of default.php file do you have to put the code? Again: in the first part of the post you say that with this solution you still get an error, and in the second part (I suppose) you explain how to get rid of it by applying a code... but where ????

Sorry to bother you, but I'm very confused and lost in the tens of posts apparently one different from the other... do you mind to make a step by step summing up as you should explain to a child? :-D

Thank you...
Title: Re: show original price, discounted price and discount percentage
Post by: vigier on July 08, 2012, 23:31:31 PM
Thnx adrianpaun for your code! I used some of it, and now my pages look a lot more attractive :)

Kind regards, Vigier
Title: Re: show original price, discounted price and discount percentage
Post by: Genius WebDesign on July 15, 2012, 22:01:44 PM
Hi giupi,

Sorry for replying this late..
If you like you can send me an email with all of your info, then I can customize everything for you the way you want it to be.

You can contact me on webmaster@traeogbyg.dk
Title: Re: show original price, discounted price and discount percentage
Post by: Genius WebDesign on July 15, 2012, 22:09:59 PM
Also you can see an example of how I have designed the product details page on one of my projects, here:

(This site is in "coming soon" phase, so you need to follow these two links)

1. http://www.traeogbyg.dk?adgang=1     - (copy/paste the entire link in your browser)
and
2. http://www.traeogbyg.dk/index.php/produkter/hytter-og-redsskabsskure/garager-carporte/jabo-dobbeltgarage-422-details
Title: Re: show original price, discounted price and discount percentage
Post by: inopia on July 17, 2012, 11:13:23 AM
Hi people,

this code works perfectly. You just modify currencydisplay.php on administrator/components/com_virtuemart/helpers and you must write this after this line:

//vmdebug('createPriceDiv $name '.$name.' '.$product_price[$name]);

I´ve modified the first version of code and i solved the issues with float numbers and the euro symbol. Them appear formated :D

  // ==
            // Añadimos código
            // ==
           
            // Comprobamos que sea un descuento
            if ($name == "discountAmount" && $vis == "none")
            {
            // Si el descuento está vacío (discountAmount) (display: none). Obtenemos una cadena vacía en lugar de un div
            return "";
            }
           
            // Si hay descuento y queremos mostrar el precio con impuestos (PriceWithTax)
            if ($name == "basePriceWithTax")
            {
            // Comprobamos que haya descuento
                if(!empty($product_price['discountAmount']))
                {
                    $vis = "block";
                    //Vamos a darle formato al precio
                    $priceFormatted = $this->priceDisplay($price,0,(float)$quantity,false,$this->_priceConfig[$name][1] );

                     // Existe descuento y mostramos el precio con impuestos (PriceWithTax) y aplicamos los nuevos estilos
                     $css = "red";
                     return '<div class="Price'.$name.'" style="display : '.$vis.';" >'.$descr.'<span class="Price'.$name.' '.$css.'" >'.$priceFormatted.'</span></div>';
                }
                else {
                    $priceFormatted = '';
                    $vis = "none";
                    return '<div class="Price'.$name.'" style="display : '.$vis.';" >'.$descr.'<span class="Price'.$name.' '.$css.'" >'.$priceFormatted.'</span></div>';
                }                   
            }
           
            // ==
            // Fin código
            // ==


In your template override folder you must find productdetails.php file on your category folder. Find this line:

echo $this->currency->createPriceDiv('basePriceWithTax','COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX',$product->prices);

and replace with this code

//Comprobamos descuento.
                        if ($this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices))
                        {
                                echo $this->currency->createPriceDiv('basePriceWithTax','COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX',$product->prices);
                        }   


It´s working fine for me.

UPDATE: % in discount

You can modify default_products.php on category view. Just replace this line:

echo $this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices)

with this instruction:


if ($this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices))
{
$discount=$this->currency->formatNumber($product->prices['discountAmount']);
$pricewithtax = $this->currency->formatNumber($product->prices['basePriceWithTax']);
$total =($discount * 100) / $pricewithtax;
echo "Descuento: ".$total."%";
}


I will depurate this code and i think i do an improvement of createPricediv or make a new function on currencydisplay.

If you want this % discount on product view you must do the same on that view.

I hope help you.
Title: Re: show original price, discounted price and discount percentage
Post by: cipakidsshop on July 23, 2012, 03:45:14 AM
Hi guys can i do this show original price, discounted price and discount percentage in virtuemart 1.1.9 and Joomla 1.5. Plis give me the link if there was a topic that discuss in vm 1.1.x
Title: Re: show original price, discounted price and discount percentage
Post by: AWu on July 30, 2012, 14:22:56 PM
Hi Everyone!

Inopia thank You for your code.
I've got a little problem. Prices look exactly that I want (base price with tax as a old price, sale price and discount amount) but base price with tax show 0,00 value:(
When I used Tobisagt code value of base price is correct but there is four numerals after coma so I lose my format price:(
Besides both codes make that price name disappear.

I'll be really grateful for any help.
Title: Re: show original price, discounted price and discount percentage
Post by: antigeek on August 15, 2012, 12:57:29 PM
Ive got the same issue as above the code seems to work perfectly but for some reason my base price is showing up as 0.00
This happened with both Tobisagt ( only no decimals displayed ) and with inopia's code.
It seems my baseprice is displaying empty? Stange as my salesprice without tax shows the correct baseprice amount......any idea's? sure im missing something pretty simple here!
Title: Re: show original price, discounted price and discount percentage
Post by: CMYKreative on August 16, 2012, 02:54:34 AM
I couldn't get it to work either, simply got:

$0.00

Is this code valid for latest stable version of VM?
Title: Re: show original price, discounted price and discount percentage
Post by: CMYKreative on August 16, 2012, 03:55:59 AM
OK, got it working (mostly) except now it's showing the discount even when there is none applied and I can't figure it out:

http://demo.cmykreative.com/berkeley/index.php?option=com_virtuemart&view=category&virtuemart_category_id=12

This is the code I have at the moment:

<div class="catProductPrice" id="productPrice<?php echo $product->virtuemart_product_id ?>">
<?php
if ($this->show_prices == '1') {
if( $product->product_unit && VmConfig::get('vm_price_show_packaging_pricelabel')) {
echo "<strong>"JText::_('COM_VIRTUEMART_CART_PRICE_PER_UNIT').' ('.$product->product_unit."):</strong>";
}


echo $this->currency->createPriceDiv('salesPrice','',$product->prices);
// echo $this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices);
if ($this->currency->createPriceDiv('basePriceWithTax','COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX',$product->prices))
echo $this->currency->createPriceDiv('basePriceWithTax','COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX',$product->prices);
if (
$this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices))
{
$discount=$this->currency->formatNumber($product->prices['discountAmount']);
$pricewithtax $this->currency->formatNumber($product->prices['basePriceWithTax']);
$total =($discount 100) / $pricewithtax;
echo "<div class='discountpercent'>Discount: ".$total."%</div>";
}
echo $this->currency->createPriceDiv('taxAmount','COM_VIRTUEMART_PRODUCT_TAX_AMOUNT',$product->prices);
?>

</div>
<div class="product-details button">
<?php // Product Details Button
echo JHTML::link($product->linkJText::_('COM_VIRTUEMART_PRODUCT_DETAILS'), array('title' => $product->product_name,'class' => 'catProductDetails button'));
?>

</div></div>


Can you figure out how to show the % discount + base price ONLY if there is a discount applied . . . ?
Title: Re: show original price, discounted price and discount percentage
Post by: tobisagt on September 18, 2012, 18:54:31 PM
Sorry guys for my late response!
I just dont have the time to give support about my code...

I dont read the all posts, but found a simple solution. Maybe someone like it.

First make sure that you marked the following price types in the backend.

Baseprice with Tax, but without discounts
Final salesprice
Discount amount

-----

Go into you your template folder and open your default.php in the category folder and copy and paste the code:



if(!empty($product->prices['discountAmount']))
{
echo $this->currency->createPriceDiv('basePriceWithTax','COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX',$product->prices);
echo $this->currency->createPriceDiv('salesPrice','COM_VIRTUEMART_PRODUCT_SALESPRICE',$product->prices);
echo $this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices);
} else {
echo $this->currency->createPriceDiv('salesPrice','COM_VIRTUEMART_PRODUCT_SALESPRICE',$product->prices);
}


Thats it.


Edit:

For articles use this code:


if(!empty($this->product->prices['discountAmount']))
{
echo $this->currency->createPriceDiv('basePriceWithTax', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX', $this->product->prices);
echo $this->currency->createPriceDiv('salesPrice', 'COM_VIRTUEMART_PRODUCT_SALESPRICE', $this->product->prices);
echo $this->currency->createPriceDiv('discountAmount', 'COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT', $this->product->prices);
} else {
echo $this->currency->createPriceDiv('salesPrice', 'COM_VIRTUEMART_PRODUCT_SALESPRICE', $this->product->prices);
}


Für alle die des deutschen mächtig sind, können auch einen Blick auf meine deutsche Anleitung werfen:

http://www.web-nut.de/webnut-blog/geschreibsel/31-virtuemart-2-preisansicht-optimieren.html#.UFixBRi5xXs
Title: Re: show original price, discounted price and discount percentage
Post by: david_a on October 08, 2012, 11:05:07 AM
That works perfectly for me, many thanks !!
Title: Re: show original price, discounted price and discount percentage
Post by: iniels on October 09, 2012, 21:28:18 PM
Can anyone help me,
I just want the code to show the discounted price in percentage. Please the code and the file where to put it.

Thanks a lot

Title: Re: show original price, discounted price and discount percentage
Post by: Setko on October 13, 2012, 16:12:23 PM
If you want to show discount in percentage on front page (featured, top ten etc.), go in components/com_virtuemart/views/virtuemart/tmpl/default_products.php.
And paste it like this:

<div class="product-price">
<?php
if (VmConfig::get 'show_prices' ) == '1') {
// if( $featProduct->product_unit && VmConfig::get('vm_price_show_packaging_pricelabel')) {
// echo "<strong>". JText::_('COM_VIRTUEMART_CART_PRICE_PER_UNIT').' ('.$featProduct->product_unit."):</strong>";
// } else echo "<strong>". JText::_('COM_VIRTUEMART_CART_PRICE'). ": </strong>";

if ($this->showBasePrice) {
echo $this->currency->createPriceDiv'basePrice''COM_VIRTUEMART_PRODUCT_BASEPRICE'$product->prices );
echo $this->currency->createPriceDiv'basePriceVariant''COM_VIRTUEMART_PRODUCT_BASEPRICE_VARIANT'$product->prices );
}
echo $this->currency->createPriceDiv'variantModification''COM_VIRTUEMART_PRODUCT_VARIANT_MOD'$product->prices );
echo $this->currency->createPriceDiv'basePriceWithTax''COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX'$product->prices );
echo $this->currency->createPriceDiv'discountedPriceWithoutTax''COM_VIRTUEMART_PRODUCT_DISCOUNTED_PRICE'$product->prices );
echo $this->currency->createPriceDiv'salesPrice''COM_VIRTUEMART_PRODUCT_SALESPRICE'$product->prices );
echo $this->currency->createPriceDiv'priceWithoutTax''COM_VIRTUEMART_PRODUCT_SALESPRICE_WITHOUT_TAX'$product->prices );
if (!empty($product->prices['discountAmount'])) {
if ($this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices))
{
$discount=$this->currency->formatNumber($product->prices['discountAmount']);
$basePrice $this->currency->formatNumber($product->prices['basePrice']);
$total =($discount 100) / $basePrice;
$total round($total0);
echo "<div class='discountpercent'>-".$total." %</div>";
} }
echo $this->currency->createPriceDiv'taxAmount''COM_VIRTUEMART_PRODUCT_TAX_AMOUNT'$product->prices );
?>

</div>


If you want to change it in product details view you have to change $product->prices in $this->product->prices
For product details go to components/com_virtuemart/views/productdetails/tmpl/default_showprices.php

For browse view go to components/com_virtuemart/views/category/tmpl/default.php

And i recommend that you make override in your own template.

This code works for me.

Edit: I found out that if you make a discount with € or $ and not with %, discount percentage will look like "13.89435 %". So i added this line in "$total = round($total, 0);" which round a number. Maybe it helps someone :)
Title: Re: show original price, discounted price and discount percentage
Post by: hajo804 on October 18, 2012, 17:56:36 PM
Quote from: Setko on October 13, 2012, 16:12:23 PM
If you want to show discount in percentage on front page (featured, top ten etc.), go in components/com_virtuemart/views/virtuemart/tmpl/default_products.php.
And paste it like this:

<div class="product-price">
<?php
if (VmConfig::get 'show_prices' ) == '1') {
// if( $featProduct->product_unit && VmConfig::get('vm_price_show_packaging_pricelabel')) {
// echo "<strong>". JText::_('COM_VIRTUEMART_CART_PRICE_PER_UNIT').' ('.$featProduct->product_unit."):</strong>";
// } else echo "<strong>". JText::_('COM_VIRTUEMART_CART_PRICE'). ": </strong>";

if ($this->showBasePrice) {
echo $this->currency->createPriceDiv'basePrice''COM_VIRTUEMART_PRODUCT_BASEPRICE'$product->prices );
echo $this->currency->createPriceDiv'basePriceVariant''COM_VIRTUEMART_PRODUCT_BASEPRICE_VARIANT'$product->prices );
}
echo $this->currency->createPriceDiv'variantModification''COM_VIRTUEMART_PRODUCT_VARIANT_MOD'$product->prices );
echo $this->currency->createPriceDiv'basePriceWithTax''COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX'$product->prices );
echo $this->currency->createPriceDiv'discountedPriceWithoutTax''COM_VIRTUEMART_PRODUCT_DISCOUNTED_PRICE'$product->prices );
echo $this->currency->createPriceDiv'salesPrice''COM_VIRTUEMART_PRODUCT_SALESPRICE'$product->prices );
echo $this->currency->createPriceDiv'priceWithoutTax''COM_VIRTUEMART_PRODUCT_SALESPRICE_WITHOUT_TAX'$product->prices );
if (!empty($product->prices['discountAmount'])) {
if ($this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices))
{
$discount=$this->currency->formatNumber($product->prices['discountAmount']);
$basePrice $this->currency->formatNumber($product->prices['basePrice']);
$total =($discount 100) / $basePrice;
$total round($total0);
echo "<div class='discountpercent'>-".$total." %</div>";
} }
echo $this->currency->createPriceDiv'taxAmount''COM_VIRTUEMART_PRODUCT_TAX_AMOUNT'$product->prices );
?>

</div>


If you want to change it in product details view you have to change $product->prices in $this->product->prices
For product details go to components/com_virtuemart/views/productdetails/tmpl/default_showprices.php

For browse view go to components/com_virtuemart/views/category/tmpl/default.php

And i recommend that you make override in your own template.

This code works for me.

Edit: I found out that if you make a discount with € or $ and not with %, discount percentage will look like "13.89435 %". So i added this line in "$total = round($total, 0);" which round a number. Maybe it helps someone :)


if (!empty($product->prices['discountAmount']) ) {
    echo $this->currency->createPriceDiv('basePriceWithTax','COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX',$product->prices);
if ($this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices))
{

$discount = $product->prices['discountAmount'];
$pricewithtax = $product->prices['basePriceWithTax'];
$total = ($discount * 100) / $pricewithtax;
$discountAmount = JText::sprintf ('COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT', $product->prices);
echo "<div class='discountpercent'>".$discountAmount.round($total)."%</div>";

}
}

Title: Re: show original price, discounted price and discount percentage
Post by: CMYKreative on October 19, 2012, 02:16:12 AM
Anyone know how to NOT make the percentage discount/coupon apply to any custom fields? only the main prices? at the moment it affects everything throughout . . .
Title: Re: show original price, discounted price and discount percentage
Post by: toad78 on October 31, 2012, 20:00:10 PM
I appreciate your time you put into this, tobisagt.

My situation is slightly different. I am selling items that are NOT taxed, therefore, it changes the dynamics a bit.

I tried modifying your code, except for a few minor details. If you look at attachment1.png, this was the result of using your code and making slight mods to display the 'Retail' price and the Sale Price.

#1: issue: I need the Retail price to show on all items
#2: issue: I need the Retail price striked through IF the items is actually on Sale (meaning, the price has changed)

My settings:
Show Price and Label on BasePrice, BasePrice modificator, New baseprice mod.., Discount Price without tax, salesprice without tax, tax amount, baseprice with tax but without discounts, Final salesprice, salesprice with discount, but without override, standardized price

For a product item:
Product Details Page: no override
Product Pricing: Cost price: 7.49000, Base price: 7.49, Final price: 7.49, Override 6.99, Overwrite final enabled.

Codeview of web page (prior to using your code):
<div id="productPrice2" class="product-price marginbottom12">
<div class="PricevariantModification" style="display : none;">
<span class="price-crossed">
<div class="PricebasePriceWithTax" style="display : none;">
Base price with tax:
<span class="PricebasePriceWithTax"></span>
</div>
</span>
<div class="PricesalesPriceWithDiscount" style="display : none;">
Salesprice with discount:
<span class="PricesalesPriceWithDiscount"></span>
</div>
<div class="PricepriceWithoutTax" style="display : block;">
Retail:
<span class="PricepriceWithoutTax">$7.49</span>
</div>
<div class="PricesalesPrice" style="display : block;">
Sale:
<span class="PricesalesPrice">$6.99</span>
</div>
<div class="PricetaxAmount" style="display : none;">
Tax amount:
<span class="PricetaxAmount"></span>
</div>
<div class="PriceunitPrice" style="display : none;">
Price / KG:
<span class="PriceunitPrice"></span>
</div>
</div>


After using your code:
<div id="productPrice2" class="product-price marginbottom12">
<div class="PricevariantModification" style="display : none;">
Variant price modifier:
<span class="PricevariantModification"></span>
</div>
<span class="price-crossed">
<div class="PricebasePriceWithTax" style="display : none;">
Base price with tax:
<span class="PricebasePriceWithTax"></span>
</div>
</span>
<div class="PricesalesPriceWithDiscount" style="display : none;">
Salesprice with discount:
<span class="PricesalesPriceWithDiscount"></span>
</div>
<div class="PricepriceWithoutTax" style="display : block;">
Base price with tax:
<span class="PricepriceWithoutTax">$7.49</span>
</div>
<div class="PricesalesPrice" style="display : block;">
Sale:
<span class="PricesalesPrice">$6.99</span>
</div>
<div class="PricesalesPrice" style="display : block;">
Sale:
<span class="PricesalesPrice">$6.99</span>
</div>
<div class="PricetaxAmount" style="display : none;">
Tax amount:
<span class="PricetaxAmount"></span>
</div>
<div class="PriceunitPrice" style="display : none;">
Price / KG:
<span class="PriceunitPrice"></span>
</div>
</div>


I noticed that there is a 'price-crossed', which I'm assuming is what's suppose to be crossing out the retail price if there is a Sale Price, so why isn't it working? Is it because it is for tax-based items?

Thank you.

[attachment cleanup by admin]
Title: Re: show original price, discounted price and discount percentage
Post by: szeor on February 12, 2013, 12:22:16 PM
So new version is 2.0.18, and developers failed... again :( Why? This thing is the default on the webshop, so i dont understand. Developers have seen the webshop?
Title: Re: show original price, discounted price and discount percentage
Post by: AbsoluteVM on February 14, 2013, 13:26:45 PM
Yeah, not nice that we can't just use it this way. I added this to my my_template/html/com_virtuemart/productdetails/default_showprices.php

   $sales_price = $this->product->prices['salesPrice'];
   $base_price = $this->product->prices['basePrice'];
   $sales_price = money_format('%.0n', $sales_price);
   $base_price = money_format('%.0n', $base_price);

   if($this->product->prices['salesPrice'] != $this->product->prices['basePrice']) {
         echo '<span class="new-price">'.$sales_price.'</span>';
         echo '<span class="old-price">'.$base_price.'</span>';
      } else {
         echo '<span class="new-price">'.$base_price.'</span>';
   }

I removed/commented out all the stuff echoing the prices.

   // echo $this->currency->createPriceDiv ('priceWithoutTax', 'COM_VIRTUEMART_PRODUCT_SALESPRICE_WITHOUT_TAX', $this->product->prices);
   // echo $this->currency->createPriceDiv ('discountAmount', 'COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT', $this->product->prices);
   // echo $this->currency->createPriceDiv ('taxAmount', 'COM_VIRTUEMART_PRODUCT_TAX_AMOUNT', $this->product->prices);
   // $unitPriceDescription = JText::sprintf ('COM_VIRTUEMART_PRODUCT_UNITPRICE', JText::_('COM_VIRTUEMART_UNIT_SYMBOL_'.$this->product->product_unit));
   // echo $this->currency->createPriceDiv ('unitPrice', $unitPriceDescription, $this->product->prices);
Title: Re: show original price, discounted price and discount percentage
Post by: szeor on February 15, 2013, 09:38:32 AM
hi AbsoluteVM, doesn't work, but ty. My problem: this bug works only top ten products, featured products (maybe aio plugins?). Don't have (works good, i can see what I need) other page (categroy, product page, default vm). Idea? Thank you
Title: Re: show original price, discounted price and discount percentage
Post by: AbsoluteVM on February 15, 2013, 15:49:07 PM
Did you use it on a category page or a product page?

On a product page, $this->product is correct.. On other pages, just use $product->..
Title: Re: show original price, discounted price and discount percentage
Post by: Alberto87 on March 25, 2013, 14:05:25 PM
Hello,

I write here, I have open a topic but nobody reply to my question, I hope you can help me.

In my e-commerce i need to display in category view the % of discount from the original price, if i apply a discount from the product page there aren't problem, all work perfect, in category view  i see 3 fields :

1- sell price with discount
2- Original price
3- percent of discount.

but if I create a rule or tax with a discount  of 15% for a category, change only the sell price and I don't see the discount % or other fields,  :-\ ... have you any clue to view the Original price and percent of discount ?

Viertumart 2.0.2 and Joomla 2.5.8

my default.php in category folder

<?php

if ($this->show_prices == '1') {

if( $product->product_unit && VmConfig::get('vm_price_show_packaging_pricelabel')) {

echo "<strong>"JText::_('COM_VIRTUEMART_CART_PRICE_PER_UNIT').' ('.$product->product_unit."):</strong>";
echo $this->currency->createPriceDiv('discountedPriceWithoutTax','COM_VIRTUEMART_PRODUCT_DISCOUNTED_PRICE',$product->prices);

}



//todo add config settings

if( $this->showBasePrice){

echo $this->currency->createPriceDiv('basePrice','COM_VIRTUEMART_PRODUCT_BASEPRICE',$product->prices);

echo $this->currency->createPriceDiv('basePriceVariant','COM_VIRTUEMART_PRODUCT_BASEPRICE_VARIANT',$product->prices);

}

echo $this->currency->createPriceDiv('variantModification','COM_VIRTUEMART_PRODUCT_VARIANT_MOD',$product->prices);



echo $this->currency->createPriceDiv('discountedPriceWithoutTax','COM_VIRTUEMART_PRODUCT_DISCOUNTED_PRICE',$product->prices);



echo $this->currency->createPriceDiv('salesPriceWithDiscount','COM_VIRTUEMART_PRODUCT_SALESPRICE_WITH_DISCOUNT',$product->prices);

echo $this->currency->createPriceDiv('salesPrice','COM_VIRTUEMART_PRODUCT_SALESPRICE',$product->prices);

                      
if (!strstr($this->currency->createPriceDiv'discountAmount',''$product->prices ), 'none')){ echo $this->currency->createPriceDiv('basePriceWithTax','COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX',$product->prices);
 

if (
$this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices))
{
$discount=$this->currency->formatNumber($product->prices['discountAmount']);
$pricewithtax $this->currency->formatNumber($product->prices['basePriceWithTax']);
$total =($discount 100) / $pricewithtax;

                                 echo 
"Save: " .number_format$total2) ."%";

}
 
}


                        
echo $this->currency->createPriceDiv('taxAmount','COM_VIRTUEMART_PRODUCT_TAX_AMOUNT',$product->prices);


?>
Title: Re: show original price, discounted price and discount percentage
Post by: nerfmarius on May 16, 2013, 11:43:57 AM
Or.. even simpler method


if ($product->prices['DATax']['2']['2'] == "-%") {

$discount = round($product->prices['DATax']['2']['1']);
echo '<div class="PricediscountAmount"><span class="PricediscountAmount">'.$discount."%".'</span></div>';
}
else {
echo $this->currency->createPriceDiv ('discountAmount', '', $product->prices);
}


$product->prices['DATax']['2']['2']  returns discount type
$product->prices['DATax']['2']['1']  discount amount

Works on VM 2.0.20b
Title: Re: show original price, discounted price and discount percentage
Post by: johnknit on May 29, 2013, 15:46:34 PM
I am looking for a way to display all quantitie prices on the productdetails page.
We have different prices for different quantities.

I tried several things on the default_showprices.php
but nothing worked.

How can that be done
Title: Re: show original price, discounted price and discount percentage
Post by: nerfmarius on May 30, 2013, 08:58:37 AM
Try printing out all product prices print_r($product->prices); and see if you have all those prices there. Then echo only what you need.
Title: Re: show original price, discounted price and discount percentage
Post by: karuppiah on July 30, 2013, 12:30:44 PM
In virtuemart 2.0 We can display discount percentage in two simple steps,

Step 1:
Open,administrator/components/com_virtuemart/helpers/calculationh.php,

Around line 352,you can find this line $prices['discountAmount'] = $this->roundInternal($basePriceWithTax - $salesPrice);

Replace with,$prices['discountAmount'] = $this->roundInternal(($basePriceWithTax - $prices['salesPrice']) * 100 / $basePriceWithTax);

here i am doing simple % calculation so the percentage of product will be shown like this for ex,$20.00

Step2:

In product detailed page or category pages,

To display default discount this code is used, $this->currency->createPriceDiv('discountAmount', 'COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT', $this->product->prices);

Assign the variable for this code like,

$vars=$this->currency->createPriceDiv('discountAmount', 'COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT', $this->product->prices);

to remove the currency symbol and decinal points use string replace like below,

$cuur1= str_replace('$(your currency symbol)','',$vars);
echo $cuur2= str_replace('.00','%',$cuur1);

Now the amount will be dsipalyed as percentage.
Title: Re: show original price, discounted price and discount percentage
Post by: karuppiah on July 30, 2013, 12:37:40 PM
In virtuemart 2.0 We can display discount percentage in two simple steps,

Step 1:
Open,administrator/components/com_virtuemart/helpers/calculationh.php,

Around line 352,you can find this line $prices['discountAmount'] = $this->roundInternal($basePriceWithTax - $salesPrice);

Replace with,$prices['discountAmount'] = $this->roundInternal(($basePriceWithTax - $prices['salesPrice']) * 100 / $basePriceWithTax);

here i am doing simple % calculation so the percentage of product will be shown like this for ex,$20.00

Step2:

In product detailed page or category pages,

To display default discount this code is used, $this->currency->createPriceDiv('discountAmount', 'COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT', $this->product->prices);

Assign the variable for this code like,

$vars=$this->currency->createPriceDiv('discountAmount', 'COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT', $this->product->prices);

to remove the currency symbol and decinal points use string replace like below,

$cuur1= str_replace('$(your currency symbol)','',$vars);
echo $cuur2= str_replace('.00','%',$cuur1);

Now the amount will be dsipalyed as percentage.
Title: Re: show original price, discounted price and discount percentage
Post by: Marttyn on August 16, 2013, 10:33:12 AM
I have 2 customers: retail and wholesale.
As discount for wholesale is not always the same i had to make 2 prices for each product, one for retail, and other for wholesale.
Now i would like the wholesalers to see retailers price crossed and their price bellow, so they see the the benefit of being wholesaler.
How can i call the retail price when the client is loged in as wholesale?
Im guessing that is achieved in currencydisplay.php, and i should be doing an extra querry to the DB with the retail shopper group. But seems quite intrepid such a modification!
Any advise?
Title: Re: show original price, discounted price and discount percentage
Post by: zakgr on August 19, 2013, 18:22:31 PM
EDIT by Mod Maxim (reason -  Copyright Violation)

Isn't 'Yag' prefix of Yagendoo?

Read attentively that sticked thread about Commercial templates in current forum section!
Title: Re: show original price, discounted price and discount percentage
Post by: Marttyn on August 19, 2013, 20:39:37 PM
Quote from: Marttyn on August 16, 2013, 10:33:12 AM
I have 2 customers: retail and wholesale.
As discount for wholesale is not always the same i had to make 2 prices for each product, one for retail, and other for wholesale.
Now i would like the wholesalers to see retailers price crossed and their price bellow, so they see the the benefit of being wholesaler.
How can i call the retail price when the client is loged in as wholesale?
Im guessing that is achieved in currencydisplay.php, and i should be doing an extra querry to the DB with the retail shopper group. But seems quite intrepid such a modification!
Any advise?

Ive found the solution for this, and ive wrote a post explaining how to get it done  8)
https://forum.virtuemart.net/index.php?topic=118057
Title: Re: show original price, discounted price and discount percentage
Post by: burnego on December 09, 2013, 13:12:28 PM
Easier method:
just add
<?php echo $this->product->prices['salesPrice'?>
in your template where you want the price to be shown and style it the way you want
Title: Re: show original price, discounted price and discount percentage
Post by: veradantas on January 11, 2014, 11:35:05 AM
Quote from: tobisagt on January 10, 2012, 17:16:10 PM
Thats exacly what i've done!

But you need a little bit Corehack! So backup your file!

Open: currencydisplay.php in administrator/components/com_virtuemart/helpers/

Search for the line:  vmdebug('createPriceDiv $name '.$name.' '.$product_price[$name]);

Copy and paste the following code after the line above

// ==
// START MODIFICATION
// ==

// Checks if there is a discount.
if ($name == "discountAmount" && $vis == "none")
{
// If discount is empty (discountAmount) (display: none) it gives you an empty string instead of <div>
return "";
}

// If you have an discount and want to show the Price with Tax
if ($name == "basePriceWithTax")
{
// Checks if there is a discount.
if(!empty($product_price['discountAmount']))
{
// Discount exist: Show Price with Tax and with an extended CSS class
$css = "red";
return '<div class="Price'.$name.'" style="display : '.$vis.';" >'.$descr.'<span class="Price'.$name.' '.$css.'" >'.$product_price[$name].'</span></div>';
}
}

// ==
// END MODIFICATION
// ==


Next step:

Open your template file: default.php in your template folder /com_virtuemart/category/

Search for the line: echo $this->currency->createPriceDiv ( 'basePriceWithTax', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX', $this->product->prices );

Replace it with the following code: So the Price with Tax (old price) only show up if there is a discount.

if ($this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices)) {
    echo $this->currency->createPriceDiv('basePriceWithTax','COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX',$product->prices); }


Thats all. Maybe you need to change the order of your pricelist in your template to show it as you want.

Hope that was helpful!



Hello!

thank you for this post, helped me a lot.
But I wonder if you could help me on anoder question.
After placing the code you provided the value of basePriceWithTax is presented with many decimal places, how can I make the value appear rounded.

Best Regards

Vera Dantas
Title: Re: show original price, discounted price and discount percentage
Post by: admiss on February 18, 2014, 15:45:58 PM
This VM discount-ing is awful.
In admin Config - Pricing, I have thicked
Baseprice
Baseprice with Tax, but without discounts
Final salesprice
Discount amount

On product page
Cost price:2
Base price: 2 (App.no rule - I don't want to show TAXes, VATs)
Final price: 1.6 (Rule: Discount 20% - which is Price modifier before tax, -%)
Overwrite final: YES (and it is not shown)
And instead of %, you can see amount.

I've attached the result - this is how it should look??
I'm not an expert in coding,  I wouldn' t like to touch php files
Everyone writes different solution. Should I try every suggestion?
I am really sangry!  >:(

[attachment cleanup by admin]
Title: Re: show original price, discounted price and discount percentage
Post by: lewwi on May 22, 2014, 13:03:46 PM
It was help to us to create the what we want. Thank you.
I would like to give you some additional option, if somebody wanted to show the formatted price replace that row:

return '<div class="Price'.$name.'" style="display : '.$vis.';" >'.$descr.'<span class="Price'.$name.' '.$css.'" >'.$product_price[$name].'</span></div>';

to that

return '<div class="Price'.$name.'" style="display : '.$vis.';" >'.$descr.'<span class="Price'.$name.' '.$css.'" >'.$priceFormatted.'</span></div>';

Lew
Title: Re: show original price, discounted price and discount percentage
Post by: zczfwz on May 27, 2014, 01:41:32 AM
Quote from: karuppiah on July 30, 2013, 12:37:40 PM
In virtuemart 2.0 We can display discount percentage in two simple steps,

Step 1:
Open,administrator/components/com_virtuemart/helpers/calculationh.php,

Around line 352,you can find this line $prices['discountAmount'] = $this->roundInternal($basePriceWithTax - $salesPrice);

Replace with,$prices['discountAmount'] = $this->roundInternal(($basePriceWithTax - $prices['salesPrice']) * 100 / $basePriceWithTax);

here i am doing simple % calculation so the percentage of product will be shown like this for ex,$20.00

Step2:

In product detailed page or category pages,

To display default discount this code is used, $this->currency->createPriceDiv('discountAmount', 'COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT', $this->product->prices);

Assign the variable for this code like,

$vars=$this->currency->createPriceDiv('discountAmount', 'COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT', $this->product->prices);

to remove the currency symbol and decinal points use string replace like below,

$cuur1= str_replace('$(your currency symbol)','',$vars);
echo $cuur2= str_replace('.00','%',$cuur1);

Now the amount will be dsipalyed as percentage.

Hi karuppiah,

Thanks for you solution for adding discount percentage, I've tried and it works for non-children products, but I found it doesn't work with Child products (I used generic child variant).
I can see after loading the child product details page, the "%" shows in first couple of seconds but gets overwrite by "$" symbol eventually.
I guess there is some code elsewhere that load the "$" symbol again for child products.
Do you know where it is?

Thanks
Title: Re: show original price, discounted price and discount percentage
Post by: szeor on May 27, 2014, 15:17:09 PM
Quote from: soniamesotek10 on March 21, 2012, 11:35:16 AM
hi, i m new to Joomla & Virtue Mart, i installed 1.5 Joomla & Virtuemart version 2.0.0

1) i want  the same, show original price, discounted price and discount percentage but its showing only Sales price & Discount in my website

2) Also i want to change the font color as below:
a) original price--i want font with strike with line-through
b) discounted price --- red & bold font
c) discount---------green font

do i need to change any CSS for this,

thanks, please help

firefox, firebug, right click, css path?
Title: Re: show original price, discounted price and discount percentage
Post by: pm4698 on July 12, 2014, 11:26:14 AM
Hello there.

I used this method too and its not working 100%.

At the replace of currency symbol topic, if you have euro, try this:

$newcurr= str_replace(chr(0xE2).chr(0x82).chr(0xAC), '', $vars);

because otherwise Euro character is not recognized

So, if i echo $newcurr, then i can see my percentage, without % symbol and with decimals.
If i use the next line:

$newcurr2=str_replace(',00','%',$newcurr);?>

and echo $newcurr2 variable then my decimals are still there. I also tried round function with no success. Any idea of how to make decimals disappear?

Thank you in advance
Title: Re: show original price, discounted price and discount percentage
Post by: wlaagewaard on October 17, 2014, 13:03:34 PM
my price is still zero in reply to the post of inopia
Title: Re: show original price, discounted price and discount percentage
Post by: OriyanJ on February 02, 2016, 08:43:01 AM
Whenever I change quantity, crossed price disappears. Any thoughts?
Title: Re: show original price, discounted price and discount percentage
Post by: xenofon360 on March 08, 2016, 12:32:41 PM
Hi there guys,

I found this whole conversation here very  interesting and i've tested / combined almost all of the methods here in my VM e-shop but i still got a problem.
The problem is that i am using Joomla 3 with virtuemart 3 too and some of the coding lines in php files don't exist anymore, maybe they've been replaced or repealed.

I want my shop showing the price of the product like this : old price (deleted with a line)
                                                                                            base price
                                                                                            money saved

Also i want that to take action to the categories page and into the product page for each product.

If there is someone who can explain step by step the procedure for that i would be grateful !