News:

Support the VirtueMart project and become a member

Main Menu

Currency conversion problem - custom dynamic price module

Started by kacie_23, November 02, 2019, 17:29:21 PM

Previous topic - Next topic

kacie_23

Hello,

I am in the process of making a custom module for manipulating prices dynamically.
Simply put..... the price for product with purchase volume less than 10 have one price, and less than 100 have one price .... continuing in multiples of ten, up to 1 million.
A small database __mod_customprices ontains the different prices.

It is fairly simple to modify the javascript for the plus and minus sign, and modify the price based on volume, but the currency conversion is a problem I have not been able to solve.

Current code below does not work, because the __virtuemart_currencies does not contain any currency_exchange_rate values.... they are all zero.



if (!class_exists('CurrencyDisplay'))
                    require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php');
$currency = CurrencyDisplay::getInstance();
$amount_in_shop_currency =  $currency->convertCurrencyTo($europeeanCurrencyId, 450);



Of course with a defunct __virtuemart_currencies table with zero exchange rate values, the $amount_in_shop_currency value is returning 0 ($price * $currency_exchange_rate).

But when using the VirtueMart Currency Selector all product prices change properly.

So ....

What code is the VirtueMart Currency Selector using. I cannot really find out where and how the currency conversion is performed right now.

I need a perfect dynamic price and currency conversion module, and need to get to the proper code performing these conversions.
Do anyone have a clue?

Jörgen

If You do not have any curency rate in the currency table the currency derived from the currency module is used instead. This is a live update, and the VM currency table is static data. The currency conversion routines used when calculating prices in the template files could be a start. Load appropriate model, check the model directory, and start using the currency routines.

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

kacie_23

QuoteThe currency conversion routines used when calculating prices in the template files could be a start. Load appropriate model, check the model directory, and start using the currency routines.

Could you elaborate please..... Where are these currency routines.
I tried this:
grep -nrw /var/www/html/templates/mytemplate/ -e "currency", and could not find any PHP script in my template-files relating to currency, or any currency routines.

But in the mod_virtuemart_currencies i can find current code :


/* load the template */
$currencyModel = VmModel::getModel('currency');
$currencies = $currencyModel->getVendorAcceptedCurrrenciesList($vendorId);
$currencyDisplay = CurrencyDisplay::getInstance();
$virtuemart_currency_id = $mainframe->getUserStateFromRequest( "virtuemart_currency_id", 'virtuemart_currency_id',vRequest::getInt('virtuemart_currency_id',$currencyDisplay->_vendorCurrency) );


But still, I cannot find a currency conversion function... the currency module is only displaying a form, for changing the currency. Not doing any conversion.
So again .... I am still need to get to the code for performing these conversions.

I assume the conversion values are collected online somewhere, but I would like to know how it is done in the core PHP.

GJC Web Design

function convertCurrencyTo($currency,$price,$shop=true)

administrator\components\com_virtuemart\helpers\currencydisplay.php

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

kacie_23

Quote
function convertCurrencyTo($currency,$price,$shop=true)
administrator\components\com_virtuemart\helpers\currencydisplay.php

Did you read the post before you answered..... i belive I stated that this was tried, but the function convertCurrencyTo, returns Zero.

GJC Web Design

QuoteDid you read the post before you answered

Rude person...   

All you need to know is in that helper...
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

kacie_23

QuoteRude person... 

Not really that rude. I believe its more rude to answer people with something that is answered in the question. Because this implies that they did not read the post, and just answer something without any thoughtfulness.
Basically this creates a forum with 80% questions without any answers, and 10% questions with bad answers, and probably only 10% useful and good information. I believe that a lot of people would agree with such an assumption.

The helper function does not contain anything that helps me. Can you provide an example, that does not collect the data from __virtuemart_currencies table, it would be helpful.

jenkinhill

@kacie_23 any form of abuse in this forum is not acceptable.
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

kacie_23

The truth is never abusive.... only lies.

The solution however is the following:


if(!class_exists('convertECB')) require(JPATH_VM_ADMINISTRATOR.DS.'plugins'.DS.'currency_converter'.DS.'convertECB.php');
$newConverterECB = new convertECB();

$justConvertedPrice = $newConverterECB->convert( $price, $europeeanCurrencyId, $productCurrencyCode);