// Fix error with AdminGeolocation trying to process serialized countries

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@13966 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
tDidierjean
2012-03-08 13:33:16 +00:00
parent 60a6855ec8
commit edc36a2294
@@ -65,13 +65,6 @@ class AdminGeolocationControllerCore extends AdminController
array('key' => _PS_GEOLOCATION_NO_CATALOG_, 'name' => $this->l('Visitors can\'t see your catalog')), array('key' => _PS_GEOLOCATION_NO_CATALOG_, 'name' => $this->l('Visitors can\'t see your catalog')),
array('key' => _PS_GEOLOCATION_NO_ORDER_, 'name' => $this->l('Visitors can see your catalog but can\'t make an order'))) array('key' => _PS_GEOLOCATION_NO_ORDER_, 'name' => $this->l('Visitors can see your catalog but can\'t make an order')))
), ),
'countries' => array(
'title' => $this->l('Select countries that can access your store:'),
'type' => 'checkbox_table',
'identifier' => 'iso_code',
'list' => Country::getCountries($this->context->language->id),
'auto_value' => false
),
), ),
), ),
'geolocationWhitelist' => array( 'geolocationWhitelist' => array(
@@ -91,47 +84,51 @@ class AdminGeolocationControllerCore extends AdminController
*/ */
public function processUpdateOptions($token) public function processUpdateOptions($token)
{ {
$redirectAdmin = false;
if ($this->isGeoLiteCityAvailable()) if ($this->isGeoLiteCityAvailable())
{
Configuration::updateValue('PS_GEOLOCATION_ENABLED', intval(Tools::getValue('PS_GEOLOCATION_ENABLED'))); Configuration::updateValue('PS_GEOLOCATION_ENABLED', intval(Tools::getValue('PS_GEOLOCATION_ENABLED')));
$redirectAdmin = true; // stop processing if geolocation is set to yes but geolite pack is not available
} elseif (Tools::getValue('PS_GEOLOCATION_ENABLED'))
else
$this->errors[] = Tools::displayError('Geolocation database is unavailable.'); $this->errors[] = Tools::displayError('Geolocation database is unavailable.');
if (!is_array(Tools::getValue('countries')) || !count(Tools::getValue('countries'))) if (empty($this->errors))
$this->errors[] = Tools::displayError('Country selection is invalid');
else
{ {
Configuration::updateValue( if (!is_array(Tools::getValue('countries')) || !count(Tools::getValue('countries')))
'PS_GEOLOCATION_BEHAVIOR', $this->errors[] = Tools::displayError('Country selection is invalid');
(!(int)Tools::getValue('PS_GEOLOCATION_BEHAVIOR') ? _PS_GEOLOCATION_NO_CATALOG_ : _PS_GEOLOCATION_NO_ORDER_) else
); {
Configuration::updateValue('PS_GEOLOCATION_NA_BEHAVIOR', (int)Tools::getValue('PS_GEOLOCATION_NA_BEHAVIOR')); Configuration::updateValue(
Configuration::updateValue('PS_ALLOWED_COUNTRIES', implode(';', Tools::getValue('countries'))); 'PS_GEOLOCATION_BEHAVIOR',
$redirectAdmin = true; (!(int)Tools::getValue('PS_GEOLOCATION_BEHAVIOR') ? _PS_GEOLOCATION_NO_CATALOG_ : _PS_GEOLOCATION_NO_ORDER_)
} );
Configuration::updateValue('PS_GEOLOCATION_NA_BEHAVIOR', (int)Tools::getValue('PS_GEOLOCATION_NA_BEHAVIOR'));
Configuration::updateValue('PS_ALLOWED_COUNTRIES', implode(';', Tools::getValue('countries')));
}
if (!Validate::isCleanHtml(Tools::getValue('PS_GEOLOCATION_WHITELIST'))) if (!Validate::isCleanHtml(Tools::getValue('PS_GEOLOCATION_WHITELIST')))
$this->errors[] = Tools::displayError('Invalid whitelist'); $this->errors[] = Tools::displayError('Invalid whitelist');
else else
{ {
Configuration::updateValue( Configuration::updateValue(
'PS_GEOLOCATION_WHITELIST', 'PS_GEOLOCATION_WHITELIST',
str_replace("\n", ';', str_replace("\r", '', Tools::getValue('PS_GEOLOCATION_WHITELIST'))) str_replace("\n", ';', str_replace("\r", '', Tools::getValue('PS_GEOLOCATION_WHITELIST')))
); );
$redirectAdmin = true; }
} }
if ($redirectAdmin)
$this->redirect_after = self::$currentIndex.'&token='.Tools::getValue('token').'&conf=4';
return parent::processUpdateOptions($token); return parent::processUpdateOptions($token);
} }
public function renderOptions() public function renderOptions()
{ {
// This field is not declared in class constructor because we want it to be manually post processed
$this->options['geolocationCountries']['fields']['countries'] = array(
'title' => $this->l('Select countries that can access your store:'),
'type' => 'checkbox_table',
'identifier' => 'iso_code',
'list' => Country::getCountries($this->context->language->id),
'auto_value' => false
);
$this->tpl_option_vars = array('allowed_countries' => explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))); $this->tpl_option_vars = array('allowed_countries' => explode(';', Configuration::get('PS_ALLOWED_COUNTRIES')));
return parent::renderOptions(); return parent::renderOptions();