VirtueMart Forum

VirtueMart 2 + 3 + 4 => Product pricing => Topic started by: kacie_23 on November 02, 2019, 17:29:21 PM

Title: Currency conversion problem - custom dynamic price module
Post by: kacie_23 on November 02, 2019, 17:29:21 PM
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?
Title: Re: Currency conversion problem - custom dynamic price module
Post by: Jörgen on November 02, 2019, 18:08:00 PM
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
Title: Re: Currency conversion problem - custom dynamic price module
Post by: kacie_23 on November 04, 2019, 10:06:32 AM
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.
Title: Re: Currency conversion problem - custom dynamic price module
Post by: GJC Web Design on November 04, 2019, 10:10:33 AM
function convertCurrencyTo($currency,$price,$shop=true)

administrator\components\com_virtuemart\helpers\currencydisplay.php

Title: Re: Currency conversion problem - custom dynamic price module
Post by: kacie_23 on November 04, 2019, 10:17:22 AM
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.
Title: Re: Currency conversion problem - custom dynamic price module
Post by: GJC Web Design on November 04, 2019, 10:37:44 AM
QuoteDid you read the post before you answered

Rude person...   

All you need to know is in that helper...
Title: Re: Currency conversion problem - custom dynamic price module
Post by: kacie_23 on November 04, 2019, 11:00:55 AM
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.
Title: Re: Currency conversion problem - custom dynamic price module
Post by: jenkinhill on November 04, 2019, 11:49:01 AM
@kacie_23 any form of abuse in this forum is not acceptable.
Title: Re: Currency conversion problem - custom dynamic price module
Post by: kacie_23 on November 04, 2019, 12:05:50 PM
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);