News:

Support the VirtueMart project and become a member

Main Menu

Show price in two currencies

Started by mratki, August 10, 2022, 11:16:10 AM

Previous topic - Next topic

mratki

Hello,
I need a solution for displaying price in two currencies, EURO is coming to our country and my shop will have to display prices in two currencies at the same time, one below another.

I managed to add two prices in category view, product view and order page by adding code in /public_html/administrator/components/com_virtuemart/helpers/currencydisplay.php:

After line 340, I added:
$priceEUR = $price / 7.5345;
                $priceEUR = number_format($priceEUR, 2, ",", ".");

And after 355:
                    return '<div class="Price'.$name.$vis.'"><span class="vm-price-desc">'.$descr.'</span><span class="Price'.$name.'">'.$priceFormatted.'</span><br/><span class"price-eur">'.$priceEUR.' €</span></div>';

But It doesn't apply for a cart module, does somebody know the solution?

https://prnt.sc/V9ALzx6Ea_sK

Webpage: https://canivau.com/hr/shop
VM version: 4.0.6
PHP version: 8.0
Joomla: 3.9.11.

Regards,
Mateo

pinochico

This is wrong code and wrong idea :)

You have to use internal core VM function ($currency->roundForDisplay) and add this code to sublayout price

You can see on our shop:
https://www.zelenazeme.cz

EUR + CZK
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

Studio 42

#2
Pinocchio, your method doesnt work when you have price per quantity or variant, you have to change some javascripts too.

About your module, some third party module does not use VM Logic
To display correctly prices you should see this code in your modules
shopFunctionsF::renderVmSubLayout('prices',array('product'=>$this->product,'currency'=>$this->currency));
This use a file that you can overide in your template folder templates\TEMPLATE-NAME\html\com_virtuemart\sublayouts\
Original file is JOOMLA\components\com_virtuemart\sublayouts\prices.php
The lines to add :$price = $product->prices['SalesPrice'];
$product->prices['convertedPrice'] = $currency->roundForDisplay($price, 0,1.0,true)
echo $currency->createPriceDiv ('convertedPrice', 'COM_VIRTUEMART_PRODUCT_CONVERTEDPRICE', $product->prices);

I do not tested. But should be right

Jumbo!

You can use the following codes to display the prices in Euro. It will also work on the checkout page and orders.

<?php
$euroCurrencyId 
47;
$vendorId       1;
$currencyEur    CurrencyDisplay::getInstance($euroCurrencyId$vendorId);

echo 
$currencyEur->priceDisplay($price$euroCurrencyId);
?>

pinochico

To Patrick:

Yes, I see this RIGHT code in our module, sorry about your info :)


<div class="vm3pr-<?php echo $rowsHeights['price'?>">
<?php
echo 
shopFunctionsF::renderVmSubLayout('prices', array(
'product' => $product'currency' => $currency
));
?>

</div>


QuoteThis use a file that you can overide in your template folder templates

Yes, we use OVERRIDE in our template, sorry about your info :)


QuoteThe lines to add :

You are right and your code should be function, but see this code :)
Important is not function createPriceDIV, but function about I wrote:
$currency->roundForDisplay(xxxxxx)

Why?
Because we need in our shops not default html structure from function createPriceDiv, but other.

Then my idea is right.


I think basic idea is still right, your info is only add more notes:
- use sublayout price in tmpl for module
- in sublayout price create custom price by function roundForDisplay (better is use override in template)

And if people looking to code right, find this code self....
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

pinochico

Jumbo,

I don't think so.

Why is so complicated?

In sublayout price is only one line and on one place.
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

Jumbo!

Quote from: pinochico on August 10, 2022, 18:15:03 PM
Jumbo,

I don't think so.

Why is so complicated?

In sublayout price is only one line and on one place.

That's because if you simply use the sub-layout without creating a new instance of CurrencyDisplay with the correct currency, it will not get the correct Exchange Rate.

Test it yourself, and you will understand.

pinochico

aha,
But I think I created new instalce in sublayout prices:


echo '<span class="price-locale"><div class="PricesalesPrice-locale vm-display vm-price-value"><span class="vm-price-desc">&nbsp;</span><span class="PricesalesPrice-locale">' . $currency->roundForDisplay($product->prices['product_price'],131,1,false,2) . ' ₽</span></div></span>';
echo '<span class="price-locale"><div class="PricesalesPrice-locale vm-display vm-price-value"><span class="vm-price-desc">&nbsp;</span><span class="PricesalesPrice-locale">' . $currency->roundForDisplay($product->prices['product_price'],199,1,false,2) . ' ₴</span></div></span>';


Basic price in shop is EUR,
two other prices are in RU rubles and UA hrivny

Or is my construct wrong?
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

mratki

Quote from: Studio 42 on August 10, 2022, 14:45:07 PM
Pinocchio, your method doesnt work when you have price per quantity or variant, you have to change some javascripts too.

About your module, some third party module does not use VM Logic
To display correctly prices you should see this code in your modules
shopFunctionsF::renderVmSubLayout('prices',array('product'=>$this->product,'currency'=>$this->currency));
This use a file that you can overide in your template folder templates\TEMPLATE-NAME\html\com_virtuemart\sublayouts\
Original file is JOOMLA\components\com_virtuemart\sublayouts\prices.php
The lines to add :$price = $product->prices['SalesPrice'];
$product->prices['convertedPrice'] = $currency->roundForDisplay($price, 0,1.0,true)
echo $currency->createPriceDiv ('convertedPrice', 'COM_VIRTUEMART_PRODUCT_CONVERTEDPRICE', $product->prices);

I do not tested. But should be right

I'm getting syntax error, unexpected T_ECHO, which clearly I have no idea how to solve. Or I'm just trying to put it in the wrong place...

Regards,
M

Studio 42

$product->prices['convertedPrice'] = $currency->roundForDisplay($price, 0,1.0,true)
Add ;

mratki

#10
Quote from: Studio 42 on August 12, 2022, 16:57:01 PM
$product->prices['convertedPrice'] = $currency->roundForDisplay($price, 0,1.0,true)
Add ;

Can you help me a little bit more about it please? I would be grateful.. I mean, The syntax error is gone, but I still don't see the price in euros

Regards,
M

mratki

Quote from: pinochico on August 10, 2022, 21:45:05 PM

echo '<span class="price-locale"><div class="PricesalesPrice-locale vm-display vm-price-value"><span class="vm-price-desc">&nbsp;</span><span class="PricesalesPrice-locale">' . $currency->roundForDisplay($product->prices['product_price'],131,1,false,2) . ' ₽</span></div></span>';
echo '<span class="price-locale"><div class="PricesalesPrice-locale vm-display vm-price-value"><span class="vm-price-desc">&nbsp;</span><span class="PricesalesPrice-locale">' . $currency->roundForDisplay($product->prices['product_price'],199,1,false,2) . ' ₴</span></div></span>';


This actually works, but not when you have price per quantity :/

Regards,
M

mratki

Quote from: Jumbo! on August 10, 2022, 18:04:21 PM
You can use the following codes to display the prices in Euro. It will also work on the checkout page and orders.

<?php
$euroCurrencyId 
47;
$vendorId       1;
$currencyEur    CurrencyDisplay::getInstance($euroCurrencyId$vendorId);

echo 
$currencyEur->priceDisplay($price$euroCurrencyId);
?>


Unfortunately, it doesn't work for me. The price in € has been added, but it always shows me 0.00€

Regards,
M

pinochico

QuoteThis actually works, but not when you have price per quantity

Is simple - change code as you wish :)

www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

mratki

Quote from: Jumbo! on August 10, 2022, 18:04:21 PM
You can use the following codes to display the prices in Euro. It will also work on the checkout page and orders.

<?php
$euroCurrencyId 
47;
$vendorId       1;
$currencyEur    CurrencyDisplay::getInstance($euroCurrencyId$vendorId);

echo 
$currencyEur->priceDisplay($price$euroCurrencyId);
?>


Here's the screenshot: https://prnt.sc/kqJV2ST7fqYl
Any ideas?

Regards,
Mateo