News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

[SOLVED] Minor - but annoying - bug in models/country.php

Started by mb000000, August 14, 2013, 12:51:41 PM

Previous topic - Next topic

mb000000

J2.5.14 & VM2.0.22a

I am working on updating someone else's plugin to support VM2 and at the same time am adding some additional functionality - the plugin allows for address lookup based on postcode, but only works for the UK.  Part of the additional functionaliy I am adding is to test what country the visitor has entered and thence only display the look up if the country is the UK.  There are many solutions to determining whether the UK was selected, but I thought I would use the VirtuemartModelCountry class to look up based on the ISO defined (and therefore largely immutable) "GBR".

Firstly I see that that class is not apparently used within VM itself (nor by any of the plugins I have installed) and secondly I see that at least one of the functions doesn't work - getCountryByCode.  This returns a country DB object based on a match with either the 2 or 3 letter code.  Here's the relevent snippet:
$countryCodeLength = strlen($code);
switch ($countryCodeLength) {
    case 2:
$countryCodeFieldname = 'country_2_code';
break;
    case 3:
$countryCodeFieldname = 'country_3_code';
break;
    default:
return false;
}

$query = 'SELECT *';
$query .= ' FROM `#__virtuemart_countries`';
$query .= ' WHERE `' . $countryCodeFieldname . '` = ' . (int)$code;

However, note that above the $query casts the $code to an int (when it is always expected to be a string), so the query always returns rubbish.

I suggest the query should be something like:
$query = 'SELECT *';
$query .= ' FROM `#__virtuemart_countries`';
$query .= ' WHERE `' . $countryCodeFieldname . '` = ' .  "'". $code ."'";


Mark

alatak

Hello

We probably did not notice, because as you said it is not used.
We use this one ShopFunctions::getCountryIDByName

I have fixed the getCountryByCode function. Txs