Author Topic: Currency conversion problem - custom dynamic price module  (Read 605 times)

kacie_23

  • Guest
Currency conversion problem - custom dynamic price module
« 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.

Code: [Select]

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

  • Global Moderator
  • Full Member
  • *
  • Posts: 2425
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: Currency conversion problem - custom dynamic price module
« Reply #1 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
Joomla 3.9.8
Virtuemart 3.4.x
Olympiantheme Hera (customized)

kacie_23

  • Guest
Re: Currency conversion problem - custom dynamic price module
« Reply #2 on: November 04, 2019, 10:06:32 am »
Quote
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.

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 :

Code: [Select]
/* 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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9196
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: Currency conversion problem - custom dynamic price module
« Reply #3 on: November 04, 2019, 10:10:33 am »
function convertCurrencyTo($currency,$price,$shop=true)

administrator\components\com_virtuemart\helpers\currencydisplay.php

GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

kacie_23

  • Guest
Re: Currency conversion problem - custom dynamic price module
« Reply #4 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.

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9196
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: Currency conversion problem - custom dynamic price module
« Reply #5 on: November 04, 2019, 10:37:44 am »
Quote
Did 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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

kacie_23

  • Guest
Re: Currency conversion problem - custom dynamic price module
« Reply #6 on: November 04, 2019, 11:00:55 am »
Quote
Rude 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

  • UK Web Developer & Consultant
  • Global Moderator
  • Super Hero
  • *
  • Posts: 27573
  • Always on vacation
    • Jenkin Hill Internet
Re: Currency conversion problem - custom dynamic price module
« Reply #7 on: November 04, 2019, 11:49:01 am »
@kacie_23 any form of abuse in this forum is not acceptable.
Kelvyn

Jenkin Hill Internet,
Lowestoft, Suffolk, UK

Unsolicited PMs/emails will be ignored.

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

Currently using VM 3.6.8 10204 on Joomla 3.9.13 PHP 7.0.33

kacie_23

  • Guest
Re: Currency conversion problem - custom dynamic price module
« Reply #8 on: November 04, 2019, 12:05:50 pm »
The truth is never abusive.... only lies.

The solution however is the following:

Code: [Select]
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);