We have various products in the site with different % discounts but on the front end it shows the 'actual' GBP amount of discount and we'd like to simply show the % amount applied to it instead (i.e. show Discount: 25%). Any ideas how to do this? (see attached)
http://demo.cmykreative.com/berkeley/index.php?option=com_virtuemart&view=category&virtuemart_category_id=14&Itemid=384
http://demo.cmykreative.com/berkeley/index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=213&virtuemart_category_id=14&Itemid=384
Also, we have in the product page some custom dropdowns that apply a price adjustment. These work fine on products without any additional discounts applied, but on products that also have a % discount, we need the price adjustment to be made AFTER any discount (i.e. $119 -25% = $89.25 then add the custom price adjustment so $119 -25% = $89.25 + $5 = $94.25). Currently the price adjustment is made and then the discount is applied to the price adjustment as well as the main price.
Hope that makes sense! :)
[attachment cleanup by admin]
?????
Hello,
You can find here a useful example about discounts and on the specific post how to print out % discount.
http://forum.virtuemart.net/index.php?topic=96175.msg350859#msg350859
here is the code for product details page from the above thread from user inopia:
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."%";
}
Hope it helps you out.
Regards.
Thanks . . . tried it but I couldn't get it to work, simply got:
$0.00
It's not showing any % anywhere.
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->link, JText::_('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 . . . ?
Hi,
You worked nicely :)
You just need an if statement. For example: (for category view)
if (!empty($product->prices['discountAmount']) ) {
echo $this->currency->createPriceDiv('basePriceWithTax','COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX',$product->prices);
echo "<div class='discountpercent'>Discount: ".$total."%</div>";
}
So you can calculate $total before that statement. That statement checks if discountAmount not Empty (that means if you have any discount) and if its true print out the basicpricewithtax and "Discount: total %"
Hope it helps!
Sweet! I tweaked it a little (the % wasn't showing correctly) and this seems to work fine:
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=$this->currency->formatNumber($product->prices['discountAmount']);
$pricewithtax = $this->currency->formatNumber($product->prices['basePriceWithTax']);
$total =($discount * 100) / $pricewithtax;
echo "<div class='discountpercent'>Discount: ".$total."%</div>";
}
}
Thanks!
Great! Glad i helped. You can do the same with product details page.
Take a look here that will help you edit the template files further.
https://forum.virtuemart.net/index.php?topic=97744.0
https://forum.virtuemart.net/index.php?topic=100696.0
https://forum.virtuemart.net/index.php?topic=92756.0
Best Regards,
Bytelord
For those that are interested, we got it working on the products details page using this:
if (!empty($this->product->prices['discountAmount']) ) {
echo $this->currency->createPriceDiv('basePriceWithTax','COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX',$this->product->prices);
if ($this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$this->product->prices))
{
$discount=$this->currency->formatNumber($this->product->prices['discountAmount']);
$pricewithtax = $this->currency->formatNumber($this->product->prices['basePriceWithTax']);
$total =($discount * 100) / $pricewithtax;
echo "<div class='discountpercent'>Discount: ".$total."%</div>";
}
}
No discount % on product so % doesn't display:
http://demo.cmykreative.com/berkeley/index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=40&virtuemart_category_id=12
% discount on product, so % does display:
http://demo.cmykreative.com/berkeley/index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=170&virtuemart_category_id=11&Itemid=384
Hi I followed but I only get
Discounted Price: $20
Discount Amount: $5
How to get
Was: $25
Now: $20 ?
Hello,
You will use:
Baseprice with Tax, but without discounts: $25 [basePriceWithTax]
Final Sales Price: $20 [salesPrice]
Quote from: bytelord on August 18, 2012, 07:38:31 AM
Hello,
You will use:
Baseprice with Tax, but without discounts: $25 [basePriceWithTax]
Final Sales Price: $20 [salesPrice]
Hi thanks
but i am looking for when an item is not on sale, it will display:
Price : $25
When its on discount it will display
Was: $25
Now: $20
Use the code I posted above, but just change the various pricing codes to suit what you need to show.
Quote from: CMYKreative on August 19, 2012, 13:29:13 PM
Use the code I posted above, but just change the various pricing codes to suit what you need to show.
hi sorry i m not very well versed in php but i tried this this code that you posted
<?php if (!empty($this->product->prices['discountAmount']) ) {
echo $this->currency->createPriceDiv('basePriceWithTax','COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX',$this->product->prices);
if ($this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$this->product->prices))
{
$discount=$this->currency->formatNumber($this->product->prices['discountAmount']);
$pricewithtax = $this->currency->formatNumber($this->product->prices['basePriceWithTax']);
$total =($discount * 100) / $pricewithtax;
echo "<div class='discountpercent'>Discount: ".$total."%</div>";
}
}
?>
enabled all prices at the backend and this is the output
Product with discounts:Salesprice with discount: $24.00
Sales Price Without Tax: $30.00
Discount: $6.00
Sales Price: $24.00
Base price with tax: $0.00
Discount: %
Product without discountsSales Price Without Tax: $50.00
Sales Price: $50.00
Why base price with tax it will display as 0? :-\
Hide the divs you dont want to show with css . . . easiest way.
Quote from: CMYKreative on August 20, 2012, 13:09:11 PM
Hide the divs you dont want to show with css . . . easiest way.
I understand, but I cannot achieve the way I wanted as in your Demo.
Original Price is only shown in [Sales Price Without Tax]
So even when without discounts it is also showing.
Product with discounts:
Sales Price Without Tax: $30.00
Sales Price: $24.00
Product without discounts
Sales Price Without Tax: $50.00
Sales Price: $50.00
Sorry, am not following what you want to do . . . can you clarify . . .
Quote from: CMYKreative on August 21, 2012, 07:22:55 AM
Sorry, am not following what you want to do . . . can you clarify . . .
I want to do like what you have done in your site
This is what my site shows currently
↓
↓
↓
[attachment cleanup by admin]
And you want to show what . . . ?
Hello all,
good point from CMYKreative, what you want to show exactly???
I want to show exactly what CMYKreative has done to the price
Normal Price Item:
Price: $10.00
Discount Price Item:
Price: $10.00
NOW: $5.00
Discount: 50%
--
but now I can't display price before discount
sales price without tax is showing the correct price before discount
but when there is no discount, it is showing double =
sales price without tax: $50
sales price: $50
Is explaining this way clearer? ??? :-[
Did you update your code using the sample code we posted right at the beginning of this thread?
You need to update a number of files, product page, cart page etc to make this all work correctly.
Quote from: CMYKreative on August 22, 2012, 13:24:29 PM
Did you update your code using the sample code we posted right at the beginning of this thread?
You need to update a number of files, product page, cart page etc to make this all work correctly.
#1 At the backend I checked all options to show all prices
#2 Updated administrator/components/com_virtuemart/helpers/currencydisplay.php
#3 Updated template/html/com_virtuemart/productdetails/default.php
What else am I missing?
i think you place that code inside the wrong template, do you use template overrides?
if you have a custom template you should check inside your_joomla_folder\templates\your_joomla_template\html\com_virtuemart\category and your_joomla_folder\templates\your_joomla_template\html\com_virtuemart\productdetails
or cart...
there you should change your files ...
Quote from: bytelord on August 22, 2012, 13:29:23 PM
i think you place that code inside the wrong template, do you use template overrides?
if you have a custom template you should check inside your_joomla_folder\templates\your_joomla_template\html\com_virtuemart\category and your_joomla_folder\templates\your_joomla_template\html\com_virtuemart\productdetails
or cart...
there you should change your files ...
I am currently trying on the product details page, so I didn't start with category page.
But the path I changed is correct, it is the template overrides folder
I tried a few times for the code but it is still showing the same thing.. :'(
OK, try this:
com_virtuemart/category/default.php
<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_desc, 255, '...') ?>
</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);
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=$this->currency->formatNumber($product->prices['discountAmount']);
$pricewithtax = $this->currency->formatNumber($product->prices['basePriceWithTax']);
$total =($discount * 100) / $pricewithtax;
echo "<div class='discountpercent'>Discount: ".$total."%</div>";
}
}
//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->link, JText::_('COM_VIRTUEMART_PRODUCT_DETAILS'), array('title' => $product->product_name,'class' => 'catProductDetails button'));
?>
</div></div>
</div>
com_virtuemart/productdetails/default.php
<?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 "<strong>" . JText::_ ( 'COM_VIRTUEMART_CART_PRICE_PER_UNIT' ) . ' (' . $this->product->product_unit . "):</strong>";
} else {
echo "<strong>" . JText::_ ( 'COM_VIRTUEMART_CART_PRICE' ) . "</strong>";
}
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 );
// echo $this->currency->createPriceDiv ( 'discountAmount', 'COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT', $this->product->prices );
if (!empty($this->product->prices['discountAmount']) ) {
echo $this->currency->createPriceDiv('basePriceWithTax','COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX',$this->product->prices);
if ($this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$this->product->prices))
{
$discount=$this->currency->formatNumber($this->product->prices['discountAmount']);
$pricewithtax = $this->currency->formatNumber($this->product->prices['basePriceWithTax']);
$total =($discount * 100) / $pricewithtax;
echo "<div class='discountpercent'>Discount: ".$total."%</div>";
}
}
echo $this->currency->createPriceDiv ( 'taxAmount', 'COM_VIRTUEMART_PRODUCT_TAX_AMOUNT', $this->product->prices );
echo $this->currency->createPriceDiv ( 'salesPrice', 'COM_VIRTUEMART_PRODUCT_SALESPRICE', $this->product->prices );
?>
Hello,
you should start over and be more careful with what you change on your source. Also there is also some CSS that should applied. Take a look on the original post about that :)
You've done something wrong when editing the code, but it's hard to see what or where from here.
Try reverting back to the ORIGINAL files that came with the template, then start again using the code I posted above and making the changes where indicated in my last post.
I should also point out that the code works for the template we are using, you might need to tweak it to suit your own page.
Hello,
Any solution for "original price, discounted price and discount percentage" WITHOUT core hack?
In admin Config - Pricing, I have thicked
Baseprice
Baseprice with Tax, but without discounts
Final salesprice
Discount amount (- I cannot understand, why is there only amount....instead of %)
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'm not an expert in coding, I wouldn' t like to touch php files
Everyone writes different solution. Should I really try every suggestion?
I have posted this before http://forum.virtuemart.net/index.php?topic=96175.60 (http://forum.virtuemart.net/index.php?topic=96175.60)
but it seems to be a too hard question
admis
Create an override
This might work for you:-
templates/your template/html/com_virtuemart/productdetails/default_showprices.php
Then add this to the pricing layout
//quorvia created discount percentage calculation and display to replace the discount value
if (round($this->product->prices['discountAmount'] != 0 )) {
$discount_percent = round(($this->product->prices['basePriceWithTax'] - $this->product->prices['salesPrice']) * 100 / $this->product->prices['basePriceWithTax']);
?>
<div class="discountAmount">
Save <?php echo $discount_percent; ?>%
</div>
<?php
}
It works for me and the "div" allow you to position and color as required
Maybe I've pasted it on wrong place...
Front end: Warning: Division by zero in /var/www/clients/client186/web266/web/templates/sj_bakery/html/com_virtuemart/productdetails/default_showprices.php on line 43
Save 0%
Thats what I was talking about...related to touching php-s...So I suppose, there is no possibility to solve it in Joomla BE, in e.g. VM Config (Pricing)