Hi i am new on this forum.
VirtueMart 3.0.X & Joomla 3.0.X
i was wondering is there any way i can show "Discount Rule Value like 15% or any %" under the products instead of calculated value?
at the moment i am getting values like:
Basic Price: 1000
Discount Price: 100 (which is done by 10% Discount rule) i want to display 10% instead of 100
I hope there is a way of doing this???
Regards,
ZillurRehman
normally a small php snippet in your prices.php sublayout
take the two prices, work out the discount % and display
Here is the snippet that I use
//quorvia created discount percentage calculation and display to replace the discount value
if (round($product->prices['discountAmount'] != 0 )) {
// quorvia used a simpler method below $discount_percent = round(($product->prices['basePriceWithTax'] - $product->prices['salesPrice']) * 100 / $product->prices['basePriceWithTax']);
$discount_percent = round(($product->prices['discountAmount'] / $product->prices['basePriceVariant']) * 100);
?>
<div class="Pricediscountpercent">
-<?php echo $discount_percent; ?>%
</div>
<?php
}
Your snippet do not work right, if you have multiple price with different price rules. by quantity for eg. on updating prices after change an option.
Studio42
Thank you for the heads up - I did not say that this would work in every circumstance, it is just what I use.
If you have a more flexible solution please feel free to post.
The only solution is using a plugin or core hack, because Virtuemart do not return it, but it's a light change, perhaps a day the team add
$product->prices['discountPercent']; using your method in the core, then all can use it.
Spyros has this nice feature in his Hera template, it doesnt show below the product but next to the product image.
http://heravm3.olympianthemes.com/televisions/smart-tv-6900-detail.html
This one works with multiple prices.
Don't find multiple price in demo, but it's not a problem to do it work. Only need to add some code and most want discount %.
i added it myself here : http://tutoriels-mao.com/recherche-produits-vm/tutoriels for eg. (solution is similar to AH code)
But i warned the customer that this solution do not work dynamic because VM do not return discount% in ajax. Or i had to write a (system) plugin to get it and override original ajax call.
Thanks for giving such solutions.
But Unfortunately i tried pasting the code in my prices.php file but it didn't work.
Please let me know where i should paste the code. I have "Price Modifier before Tax" set in my discount rule.
Here is my prices.php file. with no change.
<?php
/**
*
* Show the product prices
*
* @package VirtueMart
* @subpackage
* @author Max Milbers, Valerie Isaksen
* @link http://www.virtuemart.net
* @copyright Copyright (c) 2004 - 2014 VirtueMart Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* @version $Id: default_showprices.php 8024 2014-06-12 15:08:59Z Milbo $
*/
// Check to ensure this file is included in Joomla!
defined ('_JEXEC') or die('Restricted access');
$product = $viewData['product'];
$currency = $viewData['currency'];
?>
<div class="product-price" id="productPrice<?php echo $product->virtuemart_product_id ?>">
<?php
if (!empty($product->prices['salesPrice'])) {
//echo '<div class="vm-cart-price">' . vmText::_ ('COM_VIRTUEMART_CART_PRICE') . '</div>';
}
if ($product->prices['salesPrice']<=0 and VmConfig::get ('askprice', 1) and isset($product->images[0]) and !$product->images[0]->file_is_downloadable) {
$askquestion_url = JRoute::_('index.php?option=com_virtuemart&view=productdetails&task=askquestion&virtuemart_product_id=' . $product->virtuemart_product_id . '&virtuemart_category_id=' . $product->virtuemart_category_id . '&tmpl=component', FALSE);
?>
<a class="ask-a-question bold" href="<?php echo $askquestion_url ?>" rel="nofollow" ><?php echo vmText::_ ('COM_VIRTUEMART_PRODUCT_ASKPRICE') ?></a>
<?php
} else {
//if ($showBasePrice) {
echo $currency->createPriceDiv ('basePrice', 'COM_VIRTUEMART_PRODUCT_BASEPRICE', $product->prices);
//if (round($product->prices['basePrice'],$currency->_priceConfig['basePriceVariant'][1]) != $product->prices['basePriceVariant']) {
echo $currency->createPriceDiv ('basePriceVariant', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_VARIANT', $product->prices);
//}
//}
echo $currency->createPriceDiv ('variantModification', 'COM_VIRTUEMART_PRODUCT_VARIANT_MOD', $product->prices);
if (round($product->prices['basePriceWithTax'],$currency->_priceConfig['salesPrice'][1]) != round($product->prices['salesPrice'],$currency->_priceConfig['salesPrice'][1])) {
echo '<span class="price-crossed" >' . $currency->createPriceDiv ('basePriceWithTax', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX', $product->prices) . "</span>";
}
if (round($product->prices['salesPriceWithDiscount'],$currency->_priceConfig['salesPrice'][1]) != round($product->prices['salesPrice'],$currency->_priceConfig['salesPrice'][1])) {
echo $currency->createPriceDiv ('salesPriceWithDiscount', 'COM_VIRTUEMART_PRODUCT_SALESPRICE_WITH_DISCOUNT', $product->prices);
}
echo $currency->createPriceDiv ('salesPrice', 'COM_VIRTUEMART_PRODUCT_SALESPRICE', $product->prices);
if ($product->prices['discountedPriceWithoutTax'] != $product->prices['priceWithoutTax']) {
echo $currency->createPriceDiv ('discountedPriceWithoutTax', 'COM_VIRTUEMART_PRODUCT_SALESPRICE_WITHOUT_TAX', $product->prices);
} else {
echo $currency->createPriceDiv ('priceWithoutTax', 'COM_VIRTUEMART_PRODUCT_SALESPRICE_WITHOUT_TAX', $product->prices);
}
echo $currency->createPriceDiv ('discountAmount', 'COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT', $product->prices);
echo $currency->createPriceDiv ('taxAmount', 'COM_VIRTUEMART_PRODUCT_TAX_AMOUNT', $product->prices);
$unitPriceDescription = vmText::sprintf ('COM_VIRTUEMART_PRODUCT_UNITPRICE', vmText::_('COM_VIRTUEMART_UNIT_SYMBOL_'.$product->product_unit));
echo $currency->createPriceDiv ('unitPrice', $unitPriceDescription, $product->prices);
}
?>
</div>
Quote from: Studio 42 on June 01, 2016, 23:14:53 PM
Don't find multiple price in demo, but it's not a problem to do it work. Only need to add some code and most want discount %.
i added it myself here : http://tutoriels-mao.com/recherche-produits-vm/tutoriels for eg. (solution is similar to AH code)
But i warned the customer that this solution do not work dynamic because VM do not return discount% in ajax. Or i had to write a (system) plugin to get it and override original ajax call.
Hi Patrick, works with multiple prices too and updates prices on quantity change but I'm not gonna paste code here since is a commercial template and Spyro's work.
Was just to show the user posting here that is possible since we are using it.
Regards
Hi manu, you can do it on overriding the javascript too, i think it's what your template do. But you have the problem that you need to modify code for a standard shop feature.
My code (simplified here) is :
if($product->prices['discountedPriceWithoutTax'] != $product->prices['basePriceVariant']) {
$Percent = round( 100 *(1 - ($product->prices['discountedPriceWithoutTax'] / $product->prices['basePriceVariant'])) ); ?>
<div class="priceDiscountPercent">-<?php echo $Percent; ?>%</div>
<?php }
if you need to do same in javascript then you have to modify >vmprices.js Virtuemart.setproducttype best is to copy in your template, but you have to maintain it on VM updates.
Thanks for sharing codes but please let me know where i should paste these codes????
try in the product_detail default.php just under where prices.php is called
YOu can add this code on any place, this depend where you need it.
Best is to add it in the sublayout YOURSITE\components\com_virtuemart\sublayouts\prices.php
But an override of this file in the template is better
If you only need it in product details, then any of this file YOURSITE\components\com_virtuemart\views\productdetails\tmpl\ or in your
template overrides.
it depend where you want the price is displayed
Quote from: Studio 42 on June 02, 2016, 15:32:19 PM
YOu can add this code on any place, this depend where you need it.
Best is to add it in the sublayout YOURSITE\components\com_virtuemart\sublayouts\prices.php
But an override of this file in the template is better
If you only need it in product details, then any of this file YOURSITE\components\com_virtuemart\views\productdetails\tmpl\ or in your
template overrides.
it depend where you want the price is displayed
i pasted the code but not working :(
i pasted this code:
//quorvia created discount percentage calculation and display to replace the discount value
if (round($product->prices['discountAmount'] != 0 )) {
// quorvia used a simpler method below $discount_percent = round(($product->prices['basePriceWithTax'] - $product->prices['salesPrice']) * 100 / $product->prices['basePriceWithTax']);
$discount_percent = round(($product->prices['discountAmount'] / $product->prices['basePriceVariant']) * 100);
?>
<div class="Pricediscountpercent">
-<?php echo $discount_percent; ?>%
</div>
<?php
}
in my prices.php file as:
<?php
/**
*
* Show the product prices
*
* @package VirtueMart
* @subpackage
* @author Max Milbers, Valerie Isaksen
* @link http://www.virtuemart.net
* @copyright Copyright (c) 2004 - 2014 VirtueMart Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* @version $Id: default_showprices.php 8024 2014-06-12 15:08:59Z Milbo $
*/
// Check to ensure this file is included in Joomla!
defined ('_JEXEC') or die('Restricted access');
$product = $viewData['product'];
$currency = $viewData['currency'];
?>
<div class="product-price" id="productPrice<?php echo $product->virtuemart_product_id ?>">
<?php
//quorvia created discount percentage calculation and display to replace the discount value
if (round($product->prices['discountAmount'] != 0 )) {
// quorvia used a simpler method below $discount_percent = round(($product->prices['basePriceWithTax'] - $product->prices['salesPrice']) * 100 / $product->prices['basePriceWithTax']);
$discount_percent = round(($product->prices['discountAmount'] / $product->prices['basePriceVariant']) * 100);
?>
<div class="Pricediscountpercent">
-<?php echo $discount_percent; ?>%
</div>
<?php
}
if (!empty($product->prices['salesPrice'])) {
//echo '<div class="vm-cart-price">' . vmText::_ ('COM_VIRTUEMART_CART_PRICE') . '</div>';
}
if ($product->prices['salesPrice']<=0 and VmConfig::get ('askprice', 1) and isset($product->images[0]) and !$product->images[0]->file_is_downloadable) {
$askquestion_url = JRoute::_('index.php?option=com_virtuemart&view=productdetails&task=askquestion&virtuemart_product_id=' . $product->virtuemart_product_id . '&virtuemart_category_id=' . $product->virtuemart_category_id . '&tmpl=component', FALSE);
?>
<a class="ask-a-question bold" href="<?php echo $askquestion_url ?>" rel="nofollow" ><?php echo vmText::_ ('COM_VIRTUEMART_PRODUCT_ASKPRICE') ?></a>
<?php
} else {
//if ($showBasePrice) {
echo $currency->createPriceDiv ('basePrice', 'COM_VIRTUEMART_PRODUCT_BASEPRICE', $product->prices);
//if (round($product->prices['basePrice'],$currency->_priceConfig['basePriceVariant'][1]) != $product->prices['basePriceVariant']) {
echo $currency->createPriceDiv ('basePriceVariant', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_VARIANT', $product->prices);
//}
//}
echo $currency->createPriceDiv ('variantModification', 'COM_VIRTUEMART_PRODUCT_VARIANT_MOD', $product->prices);
if (round($product->prices['basePriceWithTax'],$currency->_priceConfig['salesPrice'][1]) != round($product->prices['salesPrice'],$currency->_priceConfig['salesPrice'][1])) {
echo '<span class="price-crossed" >' . $currency->createPriceDiv ('basePriceWithTax', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX', $product->prices) . "</span>";
}
if (round($product->prices['salesPriceWithDiscount'],$currency->_priceConfig['salesPrice'][1]) != round($product->prices['salesPrice'],$currency->_priceConfig['salesPrice'][1])) {
echo $currency->createPriceDiv ('salesPriceWithDiscount', 'COM_VIRTUEMART_PRODUCT_SALESPRICE_WITH_DISCOUNT', $product->prices);
}
echo $currency->createPriceDiv ('salesPrice', 'COM_VIRTUEMART_PRODUCT_SALESPRICE', $product->prices);
if ($product->prices['discountedPriceWithoutTax'] != $product->prices['priceWithoutTax']) {
echo $currency->createPriceDiv ('discountedPriceWithoutTax', 'COM_VIRTUEMART_PRODUCT_SALESPRICE_WITHOUT_TAX', $product->prices);
} else {
echo $currency->createPriceDiv ('priceWithoutTax', 'COM_VIRTUEMART_PRODUCT_SALESPRICE_WITHOUT_TAX', $product->prices);
}
echo $currency->createPriceDiv ('discountAmount', 'COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT', $product->prices);
echo $currency->createPriceDiv ('taxAmount', 'COM_VIRTUEMART_PRODUCT_TAX_AMOUNT', $product->prices);
$unitPriceDescription = vmText::sprintf ('COM_VIRTUEMART_PRODUCT_UNITPRICE', vmText::_('COM_VIRTUEMART_UNIT_SYMBOL_'.$product->product_unit));
echo $currency->createPriceDiv ('unitPrice', $unitPriceDescription, $product->prices);
}
?>
</div>
Do not use mix of the 2 codes, but only my, i don't know if the other work.
Quote from: Studio 42 on June 02, 2016, 21:27:18 PM
Do not use mix of the 2 codes, but only my, i don't know if the other work.
sorry i was unable to understand what you said
Mix of 2 codes?
Your making this so much harder than it needs to be
add a comment some where in the file u THINK you should be in and see if it shows..
either html or php
<!--I am here-->
or
<?php
echo 'I am here';
?>
Quote from: GJC Web Design on June 04, 2016, 15:22:31 PM
Your making this so much harder than it needs to be
add a comment some where in the file u THINK you should be in and see if it shows..
either html or php
<!--I am here-->
or
<?php
echo 'I am here';
?>
Already tried this but nothing shows up.
then obviously you are in the wrong file!!! Find the correct one!
Quote from: GJC Web Design on June 04, 2016, 17:05:57 PM
then obviously you are in the wrong file!!! Find the correct one!
i am making changes in "installed Joomla > templates > mytemplate > html > com_virtuemart > sublayouts > prices.php"
is this the right one?
Yes, the file should be this.