News:

Support the VirtueMart project and become a member

Main Menu

Price display with some conditions

Started by NickExnIT, February 22, 2023, 12:25:15 PM

Previous topic - Next topic

NickExnIT

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.

GJC Web Design

have a look how it is done in components\com_virtuemart\sublayouts\prices.php and change/over ride this to your requirements
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

NickExnIT

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?

GJC Web Design

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?
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

jenkinhill

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.
Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum