VirtueMart Dev/Coding Central: VM1 (old version) > Development Projects, Modifications, Hacks & Tweaks. VM1.1

[HELP] hacking city dynamic drop down list in registration form.

(1/2) > >>

realayumi:
I have searching in google and virtuemart forum, i did not find any solution. So write this topic asking sombody

to help me.

I'm using:
Joomla 1.5.20
VM 1.1.4

My goal is to make user select city base on mysql database, because usualy they type the wrong spell for the

city. And city will conected to shipping rates. I'll modified the shipping module base on city.

When user register using virtuemart registration form, after selecting country in drop down list, then the state

automaticaly change using AJAX. So how can we hack that when user select state, the city will change

dinamically?



I'm trying to hack in
administrator\components\com_virtuemart\classes\ps_userfield.php
around line 45x

after

--- Code: ---     case 'state':
    echo $ps_html->dynamic_state_lists( "country", "state",

$db->sf('country', true, false), $db->sf('state', true, false) );
    echo "<noscript>\n";
    $ps_html->list_states("state", $db->sf('state', true, false), "",

"id=\"state_field\"");
    echo "</noscript>\n";
    break;

--- End code ---
I duplicate from case 'state': and rename to case 'city':

there is 2 $ps_html:
$ps_html->dynamic_state_lists (change to) $ps_html->dynamic_city_lists
$ps_html->list_states (change to) $ps_html->list_cities

I start with the second and located in
administrator\components\com_virtuemart\classes\ps_html.php
around line 230++

find: function list_states(

copy, paste after function close } and change to function list_cities(

also
find: function dynamic_state_lists( 

copy, paste after function close } and change to function dynamic_city_lists(

But have no luck. I'm sure we can hack in there.

I add database mysql a new table,
jos_vm_city
containing 3 column, city_id, state_id, city_name



--- Code: ---CREATE TABLE `jos_vm_city` (
  `city_id` int(11) NOT NULL AUTO_INCREMENT,
  `state_id` int(11) NOT NULL,
  `city_name` varchar(64) NOT NULL,
  PRIMARY KEY (`city_id`)
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8 AUTO_INCREMENT=24 ;

--
-- Dumping data for table `jos_vm_city`
--
--- End code ---


Anybody please help me.

realayumi:
1 step closer, not show the cities dropdown list in virtuemart checkout registration form.
Add 4 cities in United States -> Alabama

in administrator\components\com_virtuemart\classes\ps_userfield.php
FIND

--- Code: ---     $ps_html->list_states("state", $db->sf('state', true, false), "",

"id=\"state_field\"");
    echo "</noscript>\n";
    break;

--- End code ---
ADD

--- Code: ---     case 'city':
    echo $ps_html->dynamic_city_lists( "state", "city", $db->sf('state',

true, false), $db->sf('city', true, false) );
    echo "<noscript>\n";
    $ps_html->list_cities("city", $db->sf('city', true, false), "",

"id=\"city_field\"");
    echo "</noscript>\n";
    break;

--- End code ---

FILE: administrator\components\com_virtuemart\classes\ps_html.php
FIND

--- Code: --- $list[$db->f("state_2_code")] = $db->f("state_name");
}

$this->dropdown_display($list_name, $selected_item, $list,"","",$extra);
return 1;
}

--- End code ---
ADD:

--- Code: --- function list_cities($list_name,$selected_item="", $state_id="", $extra="") {
global $VM_LANG;

$db = new ps_DB;
$q = 'SELECT state_name, city_name, city_6_code
FROM #__{vm}_city c, #__{vm}_state s
WHERE c.state_id = s.state_id';
if( !empty( $state_id )) {
$q .= ' AND s.state_id='.(int)$city_id;
}
$q .= "\nORDER BY state_name, city_name";
$db->query( $q );
$list = Array();
$list["0"] = $VM_LANG->_('PHPSHOP_SELECT');
$list["NONE"] = "not listed";
$state = "";

while( $db->next_record() ) {
if( $state != $db->f("state_name")) {
$list[] = "------- ".$db->f("state_name")." -------";
$state = $db->f("state_name");
}
$list[$db->f("city_6_code")] = $db->f("city_name");
}

$this->dropdown_display($list_name, $selected_item, $list,"","",$extra);
return 1;
}

--- End code ---
FIND:

--- Code: --- $list[$db->f("state_2_code")] = $db->f("state_name");
}

$this->dropdown_display($list_name, $selected_item, $list,"","",$extra);
return 1;
}

--- End code ---
ADD:

--- Code: --- function list_cities($list_name,$selected_item="", $state_id="", $extra="") {
global $VM_LANG;

$db = new ps_DB;
$q = 'SELECT state_name, city_name, city_6_code
FROM #__{vm}_city c, #__{vm}_state s
WHERE c.state_id = s.state_id';
if( !empty( $state_id )) {
$q .= ' AND s.state_id='.(int)$city_id;
}
$q .= "\nORDER BY state_name, city_name";
$db->query( $q );
$list = Array();
$list["0"] = $VM_LANG->_('PHPSHOP_SELECT');
$list["NONE"] = "not listed";
$state = "";

while( $db->next_record() ) {
if( $state != $db->f("state_name")) {
$list[] = "------- ".$db->f("state_name")." -------";
$state = $db->f("state_name");
}
$list[$db->f("city_6_code")] = $db->f("city_name");
}

$this->dropdown_display($list_name, $selected_item, $list,"","",$extra);
return 1;
}

--- End code ---

I also insert more column in database, and the sample to make easier to modify.
mysql:

--- Code: ---DROP TABLE IF EXISTS `jos_vm_city`;
CREATE TABLE `jos_vm_city` (
  `city_id` int(11) NOT NULL AUTO_INCREMENT,
  `state_id` int(11) NOT NULL,
  `city_name` varchar(64) NOT NULL,
  `city_6_code` varchar(6) NOT NULL,
  PRIMARY KEY (`city_id`)
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8 AUTO_INCREMENT=28 ;

--
-- Dumping data for table `jos_vm_city`
--

INSERT INTO `jos_vm_city` VALUES (24, 1, 'Birmingham', 'BIRMIN');
INSERT INTO `jos_vm_city` VALUES (25, 1, 'Montgomery', 'MONTGO');
INSERT INTO `jos_vm_city` VALUES (26, 1, 'Auburn', 'AUBURN');
INSERT INTO `jos_vm_city` VALUES (27, 1, 'Florence', 'FLOREN');

--- End code ---

Try select:
Country: United States
State: Alabama
If you view source in the browser, you can see the 4 cities. But i dont know where is my fault, it cant show the drop down list in the registration form.

diablo:
try to comment noscript here

--- Code: ---case 'city':
  echo $ps_html->dynamic_city_lists( "state", "city", $db->sf('state',

true, false), $db->sf('city', true, false) );
  [b] echo "<noscript>\n";[/b]
   $ps_html->list_cities("city", $db->sf('city', true, false), "",

"id=\"city_field\"");
  [b] echo "</noscript>\n";[/b]
  break;
--- End code ---
I have dropdown in registration form and account management too.

bonbin:
@diablo

sorry i dont get what u mean, what shall we do on that part u try to bold in?

i also need this thing, since some of my customer did mistake on writing their city :(

colemjosel:
I want to do that...somebody got??? please post it

Thanks

Navigation

[0] Message Index

[#] Next page

Go to full version