Author Topic: [HELP] hacking city dynamic drop down list in registration form.  (Read 7599 times)

realayumi

  • Beginner
  • *
  • Posts: 4
[HELP] hacking city dynamic drop down list in registration form.
« on: September 15, 2010, 10:22:08 am »
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: [Select]
    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;
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: [Select]
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`
--


Anybody please help me.

realayumi

  • Beginner
  • *
  • Posts: 4
Re: [HELP] hacking city dynamic drop down list in registration form.
« Reply #1 on: September 16, 2010, 06:13:09 am »
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: [Select]
    $ps_html->list_states("state", $db->sf('state', true, false), "",

"id=\"state_field\"");
    echo "</noscript>\n";
    break;
ADD
Code: [Select]
    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;

FILE: administrator\components\com_virtuemart\classes\ps_html.php
FIND
Code: [Select]
$list[$db->f("state_2_code")] = $db->f("state_name");
}

$this->dropdown_display($list_name, $selected_item, $list,"","",$extra);
return 1;
}
ADD:
Code: [Select]
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;
}
FIND:
Code: [Select]
$list[$db->f("state_2_code")] = $db->f("state_name");
}

$this->dropdown_display($list_name, $selected_item, $list,"","",$extra);
return 1;
}
ADD:
Code: [Select]
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;
}

I also insert more column in database, and the sample to make easier to modify.
mysql:
Code: [Select]
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');

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

  • Beginner
  • *
  • Posts: 5
Re: [HELP] hacking city dynamic drop down list in registration form.
« Reply #2 on: February 16, 2011, 21:46:22 pm »
try to comment noscript here
Code: [Select]
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;
I have dropdown in registration form and account management too.


[attachment cleanup by admin]

bonbin

  • Beginner
  • *
  • Posts: 25
Re: [HELP] hacking city dynamic drop down list in registration form.
« Reply #3 on: March 15, 2011, 16:47:16 pm »
@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

  • Beginner
  • *
  • Posts: 1
Re: [HELP] hacking city dynamic drop down list in registration form.
« Reply #4 on: January 16, 2012, 23:49:28 pm »
I want to do that...somebody got??? please post it

Thanks

tmat

  • Beginner
  • *
  • Posts: 7
Re: [HELP] hacking city dynamic drop down list in registration form.
« Reply #5 on: July 05, 2012, 04:09:35 am »
I make this module-hack: Phurchase cetain (specified) Cities! (...with dropdown filed on user registration page!) With this module you can add specify certain cities to VirtueMart (like countries and state). Your users can choose from drop down list the cities. You can add new cities, from state to state in the Administration interface. (This package not included the ZIP codes, that must enter the users manually!)

For more information visit: http://virtuemartshop.blogspot.com