From eb441d8edfd4e6307b6490ee95e6b60eb545ecd2 Mon Sep 17 00:00:00 2001
From: Marion Muszynski
Date: Thu, 19 May 2016 13:13:47 +0200
Subject: [PATCH] adding autocomplete postcode
---
check_address.php | 24 ++
override/controllers/AddressController.php | 53 ++++
themes/site/address.tpl | 267 +++++++++++++++++++++
themes/site/css/style.css | 31 +++
4 files changed, 375 insertions(+)
create mode 100644 check_address.php
create mode 100644 override/controllers/AddressController.php
diff --git a/check_address.php b/check_address.php
new file mode 100644
index 00000000..be1a2ec5
--- /dev/null
+++ b/check_address.php
@@ -0,0 +1,24 @@
+isLogged()) {
+ exit;
+}
+
+$token = Tools::getValue('token');
+if($token && $token === Tools::encrypt(date('Y-m-d').$cookie->id_customer.'Wb62nI1mcPdwyqqt')) {
+ if((int) Tools::getValue('id_country') === 8) {
+ $postcode = Tools::getValue('postcode');
+ $city = Tools::getValue('city');
+ header('Content-Type: application/json; charset=utf-8');
+ echo json_encode(Db::getInstance()->ExecuteS('
+ SELECT `city`, `postcode`
+ FROM `'._DB_PREFIX_.'france_postcode`
+ WHERE 1
+ '.($postcode? ' AND `postcode` LIKE "%'.pSQL($postcode).'%"': '').'
+ '.($city? ' AND `city` LIKE "%'.pSQL(preg_replace('/ C(I|E)DEX(.*)$/i', '', $city)).'%"': '').'
+ LIMIT 46
+ '));
+ }
+}
\ No newline at end of file
diff --git a/override/controllers/AddressController.php b/override/controllers/AddressController.php
new file mode 100644
index 00000000..c5840d87
--- /dev/null
+++ b/override/controllers/AddressController.php
@@ -0,0 +1,53 @@
+is_guest)
+ Tools::redirect('addresses.php');
+
+ if (Tools::isSubmit('id_country') AND Tools::getValue('id_country') != NULL AND is_numeric(Tools::getValue('id_country')))
+ $selectedCountry = (int)Tools::getValue('id_country');
+ elseif (isset($this->_address) AND isset($this->_address->id_country) AND !empty($this->_address->id_country) AND is_numeric($this->_address->id_country))
+ $selectedCountry = (int)$this->_address->id_country;
+ elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
+ {
+ $array = preg_split('/,|-/', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
+ if (!Validate::isLanguageIsoCode($array[0]) OR !($selectedCountry = Country::getByIso($array[0])))
+ $selectedCountry = (int)Configuration::get('PS_COUNTRY_DEFAULT');
+ }
+ else
+ $selectedCountry = (int)Configuration::get('PS_COUNTRY_DEFAULT');
+
+ if (Configuration::get('PS_RESTRICT_DELIVERED_COUNTRIES'))
+ $countries = Carrier::getDeliveredCountries((int)self::$cookie->id_lang, true, true);
+ else
+ $countries = Country::getCountries((int)self::$cookie->id_lang, true);
+
+ $countriesList = '';
+ foreach ($countries AS $country)
+ $countriesList .= '';
+
+ if ((Configuration::get('VATNUMBER_MANAGEMENT') AND file_exists(_PS_MODULE_DIR_.'vatnumber/vatnumber.php')) && VatNumber::isApplicable(Configuration::get('PS_COUNTRY_DEFAULT')))
+ self::$smarty->assign('vat_display', 2);
+ elseif (Configuration::get('VATNUMBER_MANAGEMENT'))
+ self::$smarty->assign('vat_display', 1);
+ else
+ self::$smarty->assign('vat_display', 0);
+
+ self::$smarty->assign('ajaxurl', _MODULE_DIR_);
+
+ self::$smarty->assign('vatnumber_ajax_call', (int)file_exists(_PS_MODULE_DIR_.'vatnumber/ajax.php'));
+
+ self::$smarty->assign(array(
+ 'address_ac_token' => (self::$cookie->isLogged()? Tools::encrypt(date('Y-m-d').self::$cookie->id_customer.'Wb62nI1mcPdwyqqt'): ''),
+ 'countries_list' => $countriesList,
+ 'countries' => $countries,
+ 'errors' => $this->errors,
+ 'token' => Tools::getToken(false),
+ 'select_address' => (int)(Tools::getValue('select_address'))
+ ));
+ }
+}
\ No newline at end of file
diff --git a/themes/site/address.tpl b/themes/site/address.tpl
index 5e51d54d..031633d3 100755
--- a/themes/site/address.tpl
+++ b/themes/site/address.tpl
@@ -273,5 +273,272 @@ $(function(){ldelim}
+
diff --git a/themes/site/css/style.css b/themes/site/css/style.css
index 0e913c60..d209168f 100755
--- a/themes/site/css/style.css
+++ b/themes/site/css/style.css
@@ -5675,6 +5675,37 @@ table#carrierTable tbody td {
display: none!important
}
+/******** Address autocomplete **********/
+#address_ac {
+ z-index: 5;
+ background: #FFF;
+ border-left: 1px solid #e4e4e4;
+ border-right: 1px solid #e4e4e4;
+ border-bottom: 1px solid #e4e4e4;
+ margin: 1px 0px 0px 0px;
+ min-width: 278px;
+ -moz-box-shadow: 2px 10px 10px -8px rgba(0, 0, 0, .5);
+ -webkit-box-shadow: 2px 10px 10px -8px rgba(0, 0, 0, .5);
+ -ms-box-shadow: 2px 10px 10px -8px rgba(0, 0, 0, .5);
+ -o-box-shadow: 2px 10px 10px -8px rgba(0, 0, 0, .5);
+ box-shadow: 2px 10px 10px -8px rgba(0, 0, 0, .5));
+ list-style: outside none;
+ overflow: auto;
+ max-height: 300px;
+}
+#address_ac li {
+ font-size: 12px;
+ line-height: 1.4em;
+ padding: 5px 20px 5px 10px;
+ cursor: pointer;
+}
+#address_ac li:hover {
+ background: #EEE;
+}
+#address_ac strong {
+ padding: 0px 1px;
+}
+
@keyframes slideInDown {
0% {