- Posts: 3
- Thank you received: 0
2.2.0 - Default Country Stuck as France
13 years 1 month ago #118920
by fmedia
2.2.0 - Default Country Stuck as France was created by fmedia
Hey,
Sorry if this is a duplicate post, but I spent half a day looking for an answer and couldn't find one.
Trying out the Starter Version 2.2.0, but when I select another country to be the default for registration (in the address_country custom field edit page), hit save, and the page reloads, it's back to France. The front end form also still displays France as the default.
The default field in the DB shows up as "country_Canada_38", however.
The states field will also give me only French options.
Is this something I can fix? Is it a starter version thing?
Sorry if this is a duplicate post, but I spent half a day looking for an answer and couldn't find one.
Trying out the Starter Version 2.2.0, but when I select another country to be the default for registration (in the address_country custom field edit page), hit save, and the page reloads, it's back to France. The front end form also still displays France as the default.
The default field in the DB shows up as "country_Canada_38", however.
The states field will also give me only French options.
Is this something I can fix? Is it a starter version thing?
Please Log in or Create an account to join the conversation.
13 years 1 month ago #118922
by Jerome
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
Replied by Jerome on topic 2.2.0 - Default Country Stuck as France
Hi,
Can you edit the file "administrator/components/com_hikashop/classes/field.php" and replace the code:
By:
Thanks
Can you edit the file "administrator/components/com_hikashop/classes/field.php" and replace the code:
Code:
$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;
}
}
Code:
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;
}
}
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
Please Log in or Create an account to join the conversation.
13 years 1 month ago #118926
by fmedia
Replied by fmedia on topic 2.2.0 - Default Country Stuck as France
Hi Jerome,
i replaced lines 1835 through 1841 in classes/field.php with what you posted, I'm still experiencing the bug.
i replaced lines 1835 through 1841 in classes/field.php with what you posted, I'm still experiencing the bug.
Please Log in or Create an account to join the conversation.
13 years 1 month ago #118970
by Jerome
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
Replied by Jerome on topic 2.2.0 - Default Country Stuck as France
Hi,
We can't reproduce your problem in our local websites. So we will require an access to your website in order to see it directly and make some tests.
You can send us such private information by private message.
Regards,
We can't reproduce your problem in our local websites. So we will require an access to your website in order to see it directly and make some tests.
You can send us such private information by private message.
Regards,
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
Please Log in or Create an account to join the conversation.
13 years 1 month ago #119129
by Xavier
Replied by Xavier on topic 2.2.0 - Default Country Stuck as France
Hi,
Thanks to replace the display() function of the class "hikashopDropDown" in the file indicated by Jerome by:
And the "display()" function of the class "hikashopZone" in the same file by:
Thanks to replace the display() function of the class "hikashopDropDown" in the file indicated by Jerome by:
Code:
function display($field, $value, $map, $inside, $options = '', $test = false, $allFields = null, $allValues = null){
$string = '';
if(!empty($field->field_value) && !is_array($field->field_value)){
$field->field_value = $this->parent->explodeValues($field->field_value);
}
if(empty($field->field_value) || !count($field->field_value)){
return '<input type="hidden" name="'.$map.'" value="" />';
}
if($this->type == "multiple"){
$string.= '<input type="hidden" name="'.$map.'" value=" " />';
$map.='[]';
$arg = 'multiple="multiple"';
if(!empty($field->field_options['size'])) $arg .= ' size="'.intval($field->field_options['size']).'"';
}else{
$arg = 'size="1"';
if(is_string($value)&& empty($value) && !empty($field->field_value)){
$found = false;
$first = false;
foreach($field->field_value as $oneValue => $title){
if($first===false){
$first=$oneValue;
}
if($oneValue==$value){
$found = true;
break;
}
}
//set default value for IE
if(!$found){
$value = $first;
}
}
}
$string .= '<select id="'.$this->prefix.$field->field_namekey.$this->suffix.'" name="'.$map.'" '.$arg.$options.'>';
if(empty($field->field_value))
return $string.'</select>';
$app = JFactory::getApplication();
$admin = $app->isAdmin();
foreach($field->field_value as $oneValue => $title){
if(isset($field->field_default) && array_key_exists($field->field_default, $field->field_value)){
if($oneValue === $field->field_default){
$selected = (is_string($field->field_default) && $oneValue === $field->field_default) || is_array($field->field_default) && in_array($oneValue,$field->field_default) ? 'selected="selected" ' : '';
}else{
$selected = ((int)$title->disabled && !$admin) ? 'disabled="disabled" ' : '';
}
}else{
$selected = ((int)$title->disabled && !$admin) ? 'disabled="disabled" ' : '';
$selected .= ((is_numeric($value) && is_numeric($oneValue) AND $oneValue == $value) || (is_string($value) && $oneValue === $value) || is_array($value) && in_array($oneValue,$value)) ? 'selected="selected" ' : '';
}
$id = $this->prefix.$field->field_namekey.$this->suffix.'_'.$oneValue;
$string .= '<option value="'.$oneValue.'" id="'.$id.'" '.$selected.'>'.$this->trans($title->value).'</option>';
}
$string .= '</select>';
return $string;
}
Code:
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) && JFactory::getApplication()->isSite()){
$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'){
if(isset($defaultCountry)){
$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 = 'window.addEvent(\'domready\', 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;
}
}
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);
}
Please Log in or Create an account to join the conversation.
13 years 1 month ago #119218
by fmedia
Replied by fmedia on topic 2.2.0 - Default Country Stuck as France
Thanks!
That fixed the problem on the back end, but the registration on the front end at the checkout is still showing France as a default when the backend says Canada.
Do I need to update any other code?
That fixed the problem on the back end, but the registration on the front end at the checkout is still showing France as a default when the backend says Canada.
Do I need to update any other code?
Please Log in or Create an account to join the conversation.
13 years 1 month ago #119485
by Xavier
Replied by Xavier on topic 2.2.0 - Default Country Stuck as France
Hi,
Can you try to unpublish the plugin "Hikashop geolocation" to see if it's correcting the problem ?
Or remove the following code of the code given in the previous post:
Can you try to unpublish the plugin "Hikashop geolocation" to see if it's correcting the problem ?
Or remove the following code of the code given in the previous post:
Code:
$currentZoneId = hikashop_getZone()?hikashop_getZone():'';
if(!empty($currentZoneId) && JFactory::getApplication()->isSite()){
$zoneClass = hikashop_get('class.zone');
$currentZone = $zoneClass->getZoneParents($currentZoneId);
foreach($currentZone as $currentZoneInfos){
if(preg_match('/country/',$currentZoneInfos)){
$defaultCountry = $currentZoneInfos;
}
}
}
The following user(s) said Thank You: hactic
Please Log in or Create an account to join the conversation.
11 years 2 weeks ago #214012
by hactic
Replied by hactic on topic 2.2.0 - Default Country Stuck as France
I am digging on a similar topic. Variable $currentZoneInfos contains something like 'country_Germany_81'.
This is zone_namekey. To obtain a more readable zone_name or zone_name_english, I did this workaround:
This is zone_namekey. To obtain a more readable zone_name or zone_name_english, I did this workaround:
Code:
$database = JFactory::getDBO();
$query = $database->getQuery(true);
$query = 'SELECT zone_name, zone_name_english FROM ' . hikashop_table('zone') . ' WHERE zone_namekey = \'' . $defaultCountry . '\'';
$database->setQuery($query);
$rows = $database->loadObjectList();
// var_dump($rows);
echo $rows[0]->zone_name;
Please Log in or Create an account to join the conversation.
11 years 2 weeks ago #214017
by Jerome
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
Replied by Jerome on topic 2.2.0 - Default Country Stuck as France
Hi,
You can use the zone class to "get" the 2one thanks to is namekey.
Otherwise you can perform the sql query but i'll suggest you to use the joomla database quote function to avoid sql injection from the defaultCountry variable.
Regards,
You can use the zone class to "get" the 2one thanks to is namekey.
Otherwise you can perform the sql query but i'll suggest you to use the joomla database quote function to avoid sql injection from the defaultCountry variable.
Regards,
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: hactic
Please Log in or Create an account to join the conversation.
Time to create page: 0.178 seconds