Bypass the VirtueMart's built in currency converter

Recently one of my clients needed an interesting feature: to have different, un-related prices for the products in his shop for each "currencies" he wanted to use. The quote signs aren't by mistake there, one of his "currencies" was for example Payments in USD from China... Interesting currency, what you think?

At the first the problem seemed to be simple: since the existing VM framework let you define any kind of extra currencies, and also let you enter prices for products in all of your currencies, the logical step was to simply switch off the currency converter plugin, as was possible in VirtueMart 1.1.9 and earlier versions.

But there is the first catch - this is no more possible.

The second option was to write a custom pseudo-currency converter to handle the pseudo-conversion (read to take over of the process and do simply nothing). Sounds great, but is not that easy to implement.

Fortunately there is allways a bigger hammer: if you know some PHP, you can hack the VirtueMart core. It is not recommended, for many reasons - first of them being that the next VirtueMart upgrade may override your hack - but if you are in a hurry, and you need a quick and dirty solution, here is mine.

You will hack two core files, so, do the usual stuff: save everything.

Then look in /administrator/components/com_virtuemart/helpers/ folder, and locate these files:

currencyDisplay.php
calculationh.php

First of all we will bypass the currency conversion. Open /administrator/components/com_virtuemart/helpers/currencydisplay.php and locate the function

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

Usually is somewhere around line 400. Insert after the curly bracket this line:

return $price;

to have in the output this:

function convertCurrencyTo($currency,$price,$shop=true){
                       return $price;

This line will cause the function to return the unaltered/not converted price as is found in the database. This was the easy part. The trickier - not too tricky, but anyway - part is to retrieve that value correctly from the database.

For that we will open the calculationh.php file, and locate this function:

public function getProductPrices($product, $variant=0.0, $amount=0, $ignoreAmount=true, $currencydisplay=true) {

Obviously, this is the function which retrieves the product prices from the database. We will not bother with what this does, just go to the end of the function, just above these lines:

		return $this->productPrices;
	}

Just above this, place these lines:

$app = JFactory::getApplication(); 
$currency = $app->getUserStateFromRequest( "virtuemart_currency_id", 'virtuemart_currency_id',JRequest::getInt('virtuemart_currency_id', 0)); 
foreach($product->prices as $myprices){
           if($myprices['product_currency'] == $currency){
                   $this->productPrices['costPrice']            = $myprices['product_price']; 
                   $this->productPrices['basePrice']            = $myprices['product_price']; 
                   $this->productPrices['basePriceVariant']     = $myprices['product_price']; 
                   $this->productPrices['priceBeforeTax']       = $myprices['product_price']; 
                   $this->productPrices['salesPrice']           = $myprices['product_price']; 
                   $this->productPrices['salesPriceTemp']       = $myprices['product_price']; 
                   $this->productPrices['priceWithoutTax']      = $myprices['product_price']; 
          } 
}

With these lines you simply fill the $product array's price section for the active currency with the unaltered prices stored in the database, completing the bypassing currency conversion process.

That's all. Have fun!