News:

Support the VirtueMart project and become a member

Main Menu

show original price, discounted price and discount percentage

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

Previous topic - Next topic

szeor

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

AbsoluteVM

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

Alberto87

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


?>

nerfmarius

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

johnknit

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

nerfmarius

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.

karuppiah

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

karuppiah

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

Marttyn

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?

zakgr

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

Marttyn

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

burnego

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

veradantas

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

admiss

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]

lewwi

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