Author Topic: show original price, discounted price and discount percentage  (Read 112579 times)

inopia

  • Beginner
  • *
  • Posts: 12
Re: show original price, discounted price and discount percentage
« Reply #45 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:

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

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

Code: [Select]
echo $this->currency->createPriceDiv('basePriceWithTax','COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX',$product->prices);
and replace with this code

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

Code: [Select]
echo $this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices)
with this instruction:

Code: [Select]

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.

cipakidsshop

  • Beginner
  • *
  • Posts: 3
  • Cipa Kids Shop Toko Perlengkapan Bayi Dan Anak
    • Cipa Kids Shop Toko Perlengkapan Bayi Dan Anak
Re: show original price, discounted price and discount percentage
« Reply #46 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
Cipa Kids Shop Toko Perlengkapan Bayi Dan Anak
http://www.cipakidsshop.com

AWu

  • Beginner
  • *
  • Posts: 1
Re: show original price, discounted price and discount percentage
« Reply #47 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.

antigeek

  • Beginner
  • *
  • Posts: 13
Re: show original price, discounted price and discount percentage
« Reply #48 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!

CMYKreative

  • Jr. Member
  • **
  • Posts: 71
    • CMYKreative - Bangkok-based Advertising, Marketing, Graphic Design, Website Design & Development, Brand Identity, Logo Design, Search Engine Optimization (SEO), Hosting, Programming, Photography and Powerpoint Presentations from Bangkok, Thailand
Re: show original price, discounted price and discount percentage
« Reply #49 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?

CMYKreative

  • Jr. Member
  • **
  • Posts: 71
    • CMYKreative - Bangkok-based Advertising, Marketing, Graphic Design, Website Design & Development, Brand Identity, Logo Design, Search Engine Optimization (SEO), Hosting, Programming, Photography and Powerpoint Presentations from Bangkok, Thailand
Re: show original price, discounted price and discount percentage
« Reply #50 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:

Code: [Select]
<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 . . . ?

tobisagt

  • Jr. Member
  • **
  • Posts: 106
Re: show original price, discounted price and discount percentage
« Reply #51 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:

Code: [Select]

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:

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

david_a

  • Beginner
  • *
  • Posts: 7
Re: show original price, discounted price and discount percentage
« Reply #52 on: October 08, 2012, 11:05:07 am »
That works perfectly for me, many thanks !!

iniels

  • Beginner
  • *
  • Posts: 3
Re: show original price, discounted price and discount percentage
« Reply #53 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


Setko

  • Beginner
  • *
  • Posts: 22
Re: show original price, discounted price and discount percentage
« Reply #54 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:

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

hajo804

  • Beginner
  • *
  • Posts: 2
Re: show original price, discounted price and discount percentage
« Reply #55 on: October 18, 2012, 17:56:36 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:

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

Code: [Select]
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>";

}
}

CMYKreative

  • Jr. Member
  • **
  • Posts: 71
    • CMYKreative - Bangkok-based Advertising, Marketing, Graphic Design, Website Design & Development, Brand Identity, Logo Design, Search Engine Optimization (SEO), Hosting, Programming, Photography and Powerpoint Presentations from Bangkok, Thailand
Re: show original price, discounted price and discount percentage
« Reply #56 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 . . .

toad78

  • Jr. Member
  • **
  • Posts: 202
Re: show original price, discounted price and discount percentage
« Reply #57 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):
Code: [Select]
<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:
Code: [Select]
<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]

szeor

  • Beginner
  • *
  • Posts: 22
Re: show original price, discounted price and discount percentage
« Reply #58 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?

AbsoluteVM

  • Jr. Member
  • **
  • Posts: 85
Re: show original price, discounted price and discount percentage
« Reply #59 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);