News:

Looking for documentation? Take a look on our wiki

Main Menu

show original price, discounted price and discount percentage

Started by arie, January 10, 2012, 14:24:45 PM

Previous topic - Next topic

arie

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]

tobisagt

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!

arie

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

tobisagt

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]

arie

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]

arie

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

tobisagt

For better understanding tell me how it should look with and without discount and mark which price is Baseprice etc.

arie

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]

notanothernumber

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??

arie

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

notanothernumber

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!!

arie

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

tobisagt

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.

Stamos

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 ?>

soniamesotek10

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