VirtueMart 1.1.x [ Old version - no longer supported ] > Products, Prices, Tax and Categories VM 1.1

[SOLVED] Selecting VM currency by Joomfish language

(1/2) > >>

Bedrock:
Hello!

I have a problem, namely that I'd like to change VM's currency by changing language. Or there is another possibility, that I disable currency converting. If I could do this, then Joomfish could translate both the currency and product price. Help me please, how should I do this?

Regards

Bedrock:
So I solved the problem. I modified the Virtuemart Currencies module.
The file can be found here: \modules\mod_virtuemart_currencies\mod_virtuemart_currencies.php


--- Code: ---$lang =& JFactory::getLanguage();
$eredeti = $GLOBALS['product_currency'];

if ($lang->get('tag') == "hu-HU" ) {
$GLOBALS['product_currency'] = "HUF";
}
elseif ($lang->get('tag') == "en-GB") {
$GLOBALS['product_currency'] = "EUR" ;
}

--- End code ---

This has to be pasted in the php after the "$sess = new ps_session;".

Explanation:
 
Enquiring the page's language tag: 
(for example: Hungarian => hu-Hu , English => en-GB)

$lang =& JFactory::getLanguage();
$lang->get('tag')

We'll need a variable that stores the value of "$GLOBALS['product_currency']" before we change it. (More about this later) (This is the original value)
for example:
$eredeti = $GLOBALS['product_currency'];

You have to create an IF statement and define the value of "$GLOBALS['product_currency']".

for example:
if ($lang->get('tag') == "hu-HU" ) {
$GLOBALS['product_currency'] = "HUF";
}

So if the "$lang->get('tag')" agrees "hu-HU" then the "$GLOBALS['product_currency']" will have a "HUF" value.
The php part is finished.

You have to delete the <input class="button" type="submit" name="submit" value="<?php echo 'Change Currency' ?>" /> row and replace it with


--- Code: ---<script type="text/javascript">
    $(document).ready(function(){
        var currency = '<?php echo $GLOBALS['product_currency']; ?>';
        var eredeti = '<?php echo $eredeti; ?>';
if(currency == eredeti)
        {
return;
        }
        else
{
document.form.submit();
}
});
</script>

--- End code ---

Explanation:

You have to define the two variables, for example "currency" and "eredeti".
The "currency" gets the value of $GLOBALS['product_currency']; , and the "eredeti" gets the "$eredeti;" 's value. (This is the original value)

We compare the original and the changed value.: (we need this because we don't want it to get into a loop)
"if(currency == eredeti)"

If they agree, nothing happens.
If the two values don't agree, then: "document.form.submit();"

The modification is done, but to run the script you"ll need the jQuery plugin.
You can download it from here: http://tushev.org/products/jqueryintegrator

The jQuery didn't work perfectly for me only when I changed "jQuery integration" to "Yes local copy" and it works whis way (Joomla 1.5.25).
You can check out the modification at www.petrasworkshop.com/en/jewellery

 I hope I could help some people.
 Regards

Bedrock:
Supplement:

The jQuery integrator didn't work for me because it stopped other Java things so that's why I'm using SC jQuery.

For this you have to modify the code:


--- Code: ---<script type="text/javascript">
    jQuery(document).ready(function(){
        var currency = '<?php echo $GLOBALS['product_currency']; ?>';
        var eredeti = '<?php echo $eredeti; ?>';
if(currency == eredeti)
        {
return;
        }
        else
{
document.form.submit();
}
});
</script>
--- End code ---


And another thing:

To make the drop-down list of the currencies disappear:

modify line 175:

--- Code: ---echo $ps_html->selectList( 'product_currency', $GLOBALS['product_currency'], $currencies, 1, '', 'style="width:130px;"');
--- End code ---

to this:
             
--- Code: --- if ($GLOBALS['product_currency'] == $eredeti){
              }
else
              {
echo $ps_html->selectList( 'product_currency', $GLOBALS['product_currency'], $currencies, 1, '', 'style="width:130px;"');
}
--- End code ---

and now copy the contents of the whole module and paste it at the end of Joomfish's language selecting module
(modules\mod_jflanguageselection\mod_jflanguageselection.php)

The code looks like this that you have to paste after the 95. line of Joomfish :

--- Code: ---<?php
global $mosConfig_absolute_path, $sess, $option, $page, $ps_html, $vendor_accepted_currencies;

// Load the virtuemart main parse code
if( file_exists(dirname(__FILE__).'/../../components/com_virtuemart/virtuemart_parser.php' )) {
require_once( dirname(__FILE__).'/../../components/com_virtuemart/virtuemart_parser.php' );
} else {
require_once( dirname(__FILE__).'/../components/com_virtuemart/virtuemart_parser.php' );
}

$text_before = $params->get( 'text_before', '');
$currencies = @explode( ',', $params->get( 'product_currency', $vendor_accepted_currencies ) );
$vendor_currencies = @explode( ',', $vendor_accepted_currencies );
if( count( $currencies ) < count( $vendor_currencies )) {
$currencies = $vendor_currencies;
}
$db = new ps_DB();
$db->query( 'SELECT currency_id, currency_code, currency_name FROM `#__{vm}_currency` WHERE FIND_IN_SET(`currency_code`, \''.implode(',',$currencies).'\') ORDER BY `currency_name`' );#

//$currencies = explode( ',', $currencies );
//$db->query( 'SELECT currency_id, currency_code, currency_name FROM `#__{vm}_currency` ORDER BY `currency_name`' );
unset( $currencies );

while( $db->next_record()) {
$currencies[$db->f('currency_code')] = $db->f('currency_name');
}

$sess = new ps_session;
$lang =& JFactory::getLanguage();
$eredeti = $GLOBALS['product_currency'];
if ($lang->get('tag') == "hu-HU" ) {
$GLOBALS['product_currency'] = "HUF";
}
elseif ($lang->get('tag') == "en-GB") {
$GLOBALS['product_currency'] = "EUR" ;
}
?>
<!-- Currency Selector Module -->
<?php echo $text_before ?>
<form name="form" method="post">
<?php
if( !empty( $_POST )) {
foreach( $_POST as $key => $val ) {
if( $key == 'product_currency' ) continue;
if( is_array($val) ) {
if( $key == 'checkout_this_step' ) {
foreach( $val as $value ) {
echo '<input type="hidden" name="'.$key.'[]" value="'.htmlspecialchars($value, ENT_QUOTES)."\" />\n";
}

continue;


$key = htmlspecialchars($key, ENT_QUOTES);
$val = htmlspecialchars($val, ENT_QUOTES);
echo "<input type=\"hidden\" name=\"$key\" value=\"$val\" />\n";
}
}
elseif( !empty( $_GET )) {

foreach( $_GET as $key => $val ) {
if( $key == 'product_currency' ) continue;
if( is_array($val) ) {
if( $key == 'checkout_this_step' ) {
foreach( $val as $value ) {
echo '<input type="hidden" name="'.$key.'[]" value="'.htmlspecialchars($value, ENT_QUOTES)."\" />\n";
}

continue;

}

$key = htmlspecialchars($key, ENT_QUOTES);
echo "<input type=\"hidden\" name=\"$key\" value=\"".htmlspecialchars($val, ENT_QUOTES)."\" />\n";
}
}
if ($GLOBALS['product_currency'] == $eredeti){
}
else{
echo $ps_html->selectList( 'product_currency', $GLOBALS['product_currency'], $currencies, 1, '', 'style="width:130px;"');
}
?>
<input type="hidden" name="do_coupon" value="yes" />
<script type="text/javascript">
    jQuery(document).ready(function(){
        var currency = '<?php echo $GLOBALS['product_currency']; ?>';
        var eredeti = '<?php echo $eredeti; ?>';
if(currency == eredeti)
        {
return;
        }
        else
{
document.form.submit();
}
});
</script>
</form>
--- End code ---

 After this disable the "mod_virtuemart_currencies"

Regards

atrus:
Thanks for this great post! I have another way which i think it is faster and easier and also avoids the refresh of the page. You just have to modify the tmpl file of the joomfish module, nothing else. For example, we use the rawimages.php. Therefore,

In /public_html/modules/mod_jflanguageselection/tmpl/rawimages.php

ADD THE FOLLOWIN under $langImg = JFModuleHTML::getLanguageImageSource($language);)

   if ($language->code == "en-GB" ) {
   $GLOBALS['product_currency'] = "GBP";
   }
   elseif ($language->code == "en-US") {
   $GLOBALS['product_currency'] = 'USD' ;
   }
   elseif ($language->code == "en-AU") {
   $GLOBALS['product_currency'] = 'AUD' ;
   }
.
.
.
. and so on, depending on the actual languages you have on your site.

Finally, change line 109 to:

$outString .= '<span' .$langActive. '><a href="' .$href."&product_currency=".$GLOBALS['product_currency'].'"><img src="' .JURI::base(false) . $langImg. '" alt="' .$language->name. '" title="' .$language->name. '" width="20" height="14"/></a></span>';

This will simply append the currency string to the URL which is the most foolproof method.

Another tip is to add the following before the final ?>

setcookie(Currency, $GLOBALS['product_currency'], $Month);

This will set the cookie to the browser and greatly assist you especially if you are using page caching.

You can see the above mod working in our website:

http://www.quality-tuning.com

Rgrds,
Chris

Ahmad Alfy:
Thanks atrus for your amazing solution. It worked for me but everytime the module try to translate the URL, it uses the currency variables 2 times ... To fix that you have to edit the helper.php of mod_jflanguageselection

after :  $vars = $router->getVars();
add :   unset($vars['product_currency']);

Works like charm to me.

Thanks again

Navigation

[0] Message Index

[#] Next page

Go to full version