VirtueMart Forum

VirtueMart 2 + 3 + 4 => Product pricing => Topic started by: NickExnIT on February 22, 2023, 12:25:15 PM

Title: Price display with some conditions
Post by: NickExnIT on February 22, 2023, 12:25:15 PM
Hi, I'm trying to achieve the following result with the price display in products page:

In the first row I want the base price without tax
In the second row I want the discounted price without tax, only if there is a discount applied to it
In the third row I want the final price (base price + tax - discount).

For example, in a product with discount 10%:
Base price: 100.00€
Discounted price: 90.00€
Final price: 109.80€

And in a product without discount I want:
Base price: 100.00€
Final price: 90.00€

At the moment I have all 3 prices shown even if there is no discount, like this:
Base price: 100.00€
Discounted price: 100.00€
Final price: 122.00€


I can't find  a way to achieve this goal. In my ignorace of php and VirtueMart code, I thought I need a if statement with a comparison between the base price and the discounted price, to decide what to show, is this the right path? If yes, where I have to put the if statemente to achieve this?

I'm using VirtueMart 4.0.12.10777, Joomla 3.10.11

Thank you all in advance for your help, kind regards Nick.
Title: Re: Price display with some conditions
Post by: GJC Web Design on February 22, 2023, 12:31:45 PM
have a look how it is done in components\com_virtuemart\sublayouts\prices.php and change/over ride this to your requirements
Title: Re: Price display with some conditions
Post by: NickExnIT on February 23, 2023, 09:39:45 AM
Hi, I follow your tips and I edited the following code in components/com_virtuemart/sublayouts/prices.php

<?php
// 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 ?>" data-vm="product-prices">
<?php
if (!empty(
$product->prices['salesPrice'])) {
//echo '<div class="vm-cart-price">' . vmText::_ ('COM_VIRTUEMART_CART_PRICE') . '</div>';
}

if ($product->prices['salesPrice']<=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);
echo $currency->createPriceDiv ('salesPriceTt''COM_VIRTUEMART_PRODUCT_SALESPRICE_TT'$product->prices);
$infotax vmConfig::get('vm_prices_info_tax'0);
$infodelivery vmConfig::get('vm_prices_info_delivery'0);
if ($infotax == or $infodelivery == 1) { ?>

<div class="vm-prices-info">
<?php
if ($infotax == 1) {
if ($product->prices['priceWithoutTax'] == $product->prices['salesPrice']) {
$taxclusive 'COM_VM_TAX_EXCLUSIVE';
} else {
$taxclusive 'COM_VM_TAX_INCLUSIVE';
}
echo vmText::_($taxclusive);
}
if ($infotax == and $infodelivery == 1) {
echo vmText::_('COM_VM_PRICES_INFO_DIVIDER');
}
if ($infodelivery == 1) {
echo vmText::_('COM_VM_PRICES_INFO_DELIVERY');
?>

</div>
<?php
}
//echo $currency->createPriceDiv ('salesPrice', 'COM_VIRTUEMART_PRODUCT_SALESPRICE', $product->prices);
//echo $currency->createPriceDiv ('salesPriceQu', '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);
echo $currency->createPriceDiv ('discountedPriceWithoutTaxTt''COM_VIRTUEMART_PRODUCT_SALESPRICE_WITHOUT_TAX_TT'$product->prices);
} else {
echo $currency->createPriceDiv ('priceWithoutTax''COM_VIRTUEMART_PRODUCT_SALESPRICE_WITHOUT_TAX'$product->prices);
echo $currency->createPriceDiv ('priceWithoutTaxTt''COM_VIRTUEMART_PRODUCT_SALESPRICE_WITHOUT_TAX_TT'$product->prices);
}
echo $currency->createPriceDiv ('discountAmount''COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT'$product->prices);
echo $currency->createPriceDiv ('discountAmountTt''COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT_TT'$product->prices);
echo $currency->createPriceDiv ('taxAmount''COM_VIRTUEMART_PRODUCT_TAX_AMOUNT'$product->prices);
echo $currency->createPriceDiv ('taxAmountTt''COM_VIRTUEMART_PRODUCT_TAX_AMOUNT_TT'$product->prices);
$unitPriceDescription vmText::sprintf ('COM_VIRTUEMART_PRODUCT_UNITPRICE'vmText::_('COM_VIRTUEMART_UNIT_SYMBOL_'.strtoupper($product->product_unit)));
echo $currency->createPriceDiv ('unitPrice'$unitPriceDescription$product->prices);
}
?>

</div>



with this:


<?php
// 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 ?>" data-vm="product-prices">
<?php
/* If price is empty, show button "Ask price" */
if ($product->prices['salesPrice']<=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 basePrice != discountedPrice, show basePrice with strikethrough */
if (round($product->prices['basePrice'],$currency->_priceConfig['salesPrice'][1]) != round($product->prices['salesPriceWithDiscount'],$currency->_priceConfig['salesPrice'][1])) {
echo '<span class="price-crossed" >' $currency->createPriceDiv ('basePrice''COM_VIRTUEMART_PRODUCT_BASEPRICE'$product->prices) . "</span>";
echo $currency->createPriceDiv ('salesPriceWithDiscount''COM_VIRTUEMART_PRODUCT_SALESPRICE_WITH_DISCOUNT'$product->prices);
echo $currency->createPriceDiv ('salesPrice''COM_VIRTUEMART_PRODUCT_SALESPRICE'$product->prices);
} else { /* If basePrice == discountedPrice show only the first */
echo $currency->createPriceDiv ('basePrice''COM_VIRTUEMART_PRODUCT_BASEPRICE'$product->prices);
echo $currency->createPriceDiv ('salesPrice''COM_VIRTUEMART_PRODUCT_SALESPRICE'$product->prices);
}
}
?>

</div>


As far as I can understand about php, this should be the correct way, but on the frontend side nothing change. Where is my mistake?
Title: Re: Price display with some conditions
Post by: GJC Web Design on February 23, 2023, 14:32:40 PM
no idea but you shouldn't be changing core files .. that is what over rides are for..

Have u checked the prices.php isn't already over ridden in your template?
Title: Re: Price display with some conditions
Post by: jenkinhill on February 23, 2023, 19:38:23 PM
Template overrides for VM sublayouts should be in Joomla root/templates/your-joomla-template/html/com_virtuemart/sublayouts/

Have a look there to see if you already have a prices.php override file.