function display($field, $value, $map, $inside, $options = '', $test = false, $allFields = null, $allValues = null){
// Set default zone depending on the geolocation plugin
$currentZoneId = hikashop_getZone()?hikashop_getZone():'';
if(!empty($currentZoneId)){
$zoneClass = hikashop_get('class.zone');
$currentZone = $zoneClass->getZoneParents($currentZoneId);
foreach($currentZone as $currentZoneInfos){
if(preg_match('/country/',$currentZoneInfos)){
$defaultCountry = $currentZoneInfos;
}
}
}
if($field->field_options['zone_type']=='country'){
$field->field_default = $defaultCountry;
$stateNamekey = str_replace('country','state',$field->field_namekey);
if(!empty($allFields)) {
foreach($allFields as &$f) {
if(!empty($f->field_options['zone_type']) && $f->field_options['zone_type'] == 'state') {
$stateNamekey = $f->field_namekey;
break;
}
}
}
$stateId = str_replace(
array('[',']',$field->field_namekey),
array('_','',$stateNamekey),
$map
);
$changeJs = 'window.hikashop.changeState(this,\''.$stateId.'\',\''.$field->field_url.'field_type='.$field->field_table.'&field_id='.$stateId.'&field_namekey='.$stateNamekey.'&namekey=\'+this.value);';
if(!empty($options) && stripos($options,'onchange="')!==false){
$options = preg_replace('#onchange="#i','onchange="'.$changeJs,$options);
}else{
$options = ' onchange="'.$changeJs.'"';
}
if($allFields == null || $allValues == null) {
$doc = JFactory::getDocument();
$js = 'do_nothing( function() {
var el = document.getElementById(\''.$this->prefix.$field->field_namekey.$this->suffix.'\');
window.hikashop.changeState(el,\''.$stateId.'\',\''.$field->field_url.'field_type='.$field->field_table.'&field_id='.$stateId.'&field_namekey='.$stateNamekey.'&namekey=\'+el.value);
});';
$doc->addScriptDeclaration($js);
}
} elseif($field->field_options['zone_type']=='state') {
$stateId = str_replace(array('[',']'),array('_',''),$map);
$dropdown = '';
if($allFields != null) {
$country = null;
foreach($allFields as $f) {
if($f->field_type=='zone' && !empty($f->field_options['zone_type']) && $f->field_options['zone_type']=='country') {
$key = $f->field_namekey;
if(!empty($allValues->$key)) {
$country = $allValues->$key;
} else {
$country = $f->field_default;
}
break;
}
}
$country = '';
if(empty($country)) {
$address_country_field = $this->parent->get(14); //14 = id of country field
if(!empty($address_country_field) && $address_country_field->field_type=='zone' && !empty($address_country_field->field_options['zone_type']) && $address_country_field->field_options['zone_type']=='country' && !empty($address_country_field->field_default)) {
$country = $address_country_field->field_default;
}
}
if(isset($defaultCountry)){
$country = $defaultCountry;
}
if(!empty($country)) {
$countryType = hikashop_get('type.country');
$dropdown = $countryType->displayStateDropDown($country, $stateId, $map, '', $value);
}
}
return '<span id="'.$stateId.'_container">'.$dropdown.'</span>'.
'<input type="hidden" id="'.$stateId.'_default_value" name="'.$stateId.'_default_value" value="'.$value.'"/>';
}
return parent::display($field,$value,$map,$inside,$options,$test,$allFields,$allValues);
}