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

BUG in ps_shipping::country_multiple_list [fix included]

Started by DisgruntledGoat, March 18, 2009, 13:10:28 PM

Previous topic - Next topic

DisgruntledGoat

The bug:
When you open the "edit shipping rate" page, some countries are selected when they shouldn't be. Deselecting them means they are not saved in the list in the database, but when going back to the page, the country is selected again.
I changed all my countries to be postcode areas (counties) in the UK. I had the codes AB, B, BH, BR. Selecting any of these caused "B" to be selected as well.

The cause:
Having a country code that is a substring of another country code - in this case, B is a substring of AB, so if the database had "AB;BH;" in it, it would match B as well.

The fix:
I did a quick fix myself, which separates out the currently selected postcodes and checks each. The problem is in the country_multiple_list function, in /administrator/components/com_virtuemart/classes/ps_shipping.php. Here's the updated function:

function country_multiple_list($select_name, $selected_countries) {
global $VM_LANG;
$db = new ps_DB;
$selected_countries_list = explode( ';', $selected_countries );

echo "<select  class=\"inputbox\" multiple size=\"10\" name=\"$select_name\">\n";
$q = "SELECT * FROM #__{vm}_country ORDER BY country_name ASC";
$db->query($q);
while ($db->next_record()) {
echo "<option value=\"" . $db->f("country_3_code") . "\"";
if ( in_array( $db->f("country_3_code"), $selected_countries_list ) ) {
echo " selected=\"selected\"";
}
echo ">" . $db->f("country_name") . "</option>\n";
}
echo "</select>\n";
return True;
}


I don't know the procedure for bug reporting/fixing (dev.virtuemart.net wasn't working for me), so I trust someone else can review this and include in a future update?