News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

show original price, discounted price and discount percentage

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

Previous topic - Next topic

inopia

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.

cipakidsshop

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

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

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

I couldn't get it to work either, simply got:

$0.00

Is this code valid for latest stable version of VM?

CMYKreative

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

tobisagt

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

david_a


iniels

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

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 :)

hajo804

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>";

}
}


CMYKreative

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

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]

szeor

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

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);