Created
April 12, 2016 08:25
-
-
Save uzaharova/061f0676d0c2648c27c8d99ee3894348 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/addons/rus_cities/controllers/frontend/city.php b/app/addons/rus_cities/controllers/frontend/city.php | |
index 426a567..cc321fd 100644 | |
--- a/app/addons/rus_cities/controllers/frontend/city.php | |
+++ b/app/addons/rus_cities/controllers/frontend/city.php | |
@@ -20,9 +20,9 @@ if (!defined('BOOTSTRAP')) { die('Access denied'); } | |
if ($mode == 'autocomplete_city') { | |
$params = $_REQUEST; | |
- $status_country = db_get_field("SELECT status FROM ?:countries WHERE code = 'RU'"); | |
+ $d_country = db_get_fields("SELECT code FROM ?:countries WHERE status = 'A'"); | |
- if (defined('AJAX_REQUEST') && $params['q'] && $status_country == 'A') { | |
+ if (defined('AJAX_REQUEST') && $params['q'] && !empty($d_country)) { | |
$select = array(); | |
$prefix = array('гор.','г.' ,'г ', 'гор ','город '); | |
@@ -34,69 +34,49 @@ if ($mode == 'autocomplete_city') { | |
$params['q'] = str_replace($prefix,'',$params['q']); | |
- if (Registry::get('addons.rus_spsr.status') == 'A') { | |
- $server = 'spsr'; | |
- } elseif (Registry::get('addons.rus_sdek.status') == 'A') { | |
+ if (Registry::get('addons.rus_sdek.status') == 'A') { | |
$server = 'sdek'; | |
- } else { | |
- $server = 'edost'; | |
} | |
- if ($server == 'spsr') { | |
- $location['city'] = $params['q']; | |
- $cities = rus_spsr_get_cities($location); | |
- | |
- if (!empty($cities)) { | |
- $cities = array_slice($cities , 0, 15); | |
- foreach ($cities as $city) { | |
- $select[] = array( | |
- 'code' => $city['City_ID'], | |
- 'value' => $city['CityName'], | |
- 'label' => $city['CityName'] . ' ('. $city['RegionName'] .')', | |
- ); | |
- } | |
- } | |
- | |
+ if (!empty($server) && $server == 'sdek') { | |
+ $table = '?:rus_cities_sdek'; | |
+ $table_description = '?:rus_city_sdek_descriptions'; | |
} else { | |
- if ($server == 'sdek') { | |
- $table = '?:rus_cities_sdek'; | |
- $table_description = '?:rus_city_sdek_descriptions'; | |
- } elseif ($server == 'edost') { | |
- $table = '?:rus_cities'; | |
- $table_description = '?:rus_city_descriptions'; | |
- } | |
- | |
- $search = trim($params['q'])."%"; | |
+ $table = '?:rus_cities'; | |
+ $table_description = '?:rus_city_descriptions'; | |
+ } | |
- $join = db_quote("LEFT JOIN $table as c ON c.city_id = d.city_id"); | |
+ $search = trim($params['q'])."%"; | |
- $condition = db_quote(" AND c.status = ?s", 'A'); | |
+ $join = db_quote("LEFT JOIN $table as c ON c.city_id = d.city_id"); | |
- if (!empty($params['check_country']) && $params['check_country'] != 'undefined') { | |
- $condition .= db_quote(" AND c.country_code = ?s", $params['check_country']); | |
+ $condition = db_quote(" AND c.status = ?s", 'A'); | |
- if (!empty($params['check_state']) && $params['check_state'] != 'undefined') { | |
- $condition .= db_quote(" AND c.state_code = ?s", $params['check_state']); | |
- } else { | |
- $data_states = db_get_fields("SELECT code FROM ?:states WHERE country_code = 'RU' AND status = 'A'"); | |
- $condition .= db_quote(" AND c.state_code IN (?a) ", $data_states); | |
- } | |
+ if (!empty($params['check_country']) && $params['check_country'] != 'undefined') { | |
+ $condition .= db_quote(" AND c.country_code = ?s", $params['check_country']); | |
+ if (!empty($params['check_state']) && $params['check_state'] != 'undefined') { | |
+ $condition .= db_quote(" AND c.state_code = ?s", $params['check_state']); | |
} else { | |
- $data_states = db_get_fields("SELECT code FROM ?:states WHERE country_code = 'RU' AND status = 'A'"); | |
+ $data_states = db_get_fields("SELECT code FROM ?:states WHERE country_code = ?s AND status = 'A'", $params['check_country']); | |
$condition .= db_quote(" AND c.state_code IN (?a) ", $data_states); | |
} | |
- $cities = db_get_array("SELECT d.city, c.city_code FROM $table_description as d ?p WHERE city LIKE ?l AND lang_code = ?s ?p LIMIT ?i", $join , $search , $lang_code, $condition, 10); | |
+ } else { | |
+ $data_states = db_get_fields("SELECT code FROM ?:states WHERE country_code IN (?a) AND status = 'A'", $d_country); | |
- if (!empty($cities)) { | |
- foreach ($cities as $city) { | |
- $select[] = array( | |
- 'code' => $city['city_code'], | |
- 'value' => $city['city'], | |
- 'label' => $city['city'], | |
- ); | |
- } | |
+ $condition .= db_quote(" AND c.state_code IN (?a) ", $data_states); | |
+ } | |
+ | |
+ $cities = db_get_array("SELECT d.city, c.city_code FROM $table_description as d ?p WHERE city LIKE ?l AND lang_code = ?s ?p LIMIT ?i", $join , $search , $lang_code, $condition, 10); | |
+ | |
+ if (!empty($cities)) { | |
+ foreach ($cities as $city) { | |
+ $select[] = array( | |
+ 'code' => $city['city_code'], | |
+ 'value' => $city['city'], | |
+ 'label' => $city['city'], | |
+ ); | |
} | |
} | |
@@ -165,57 +145,3 @@ if ($mode == 'shipping_estimation_city') { | |
} | |
} | |
- | |
-function rus_spsr_get_cities($location) | |
-{ | |
- $city_name = $location['city']; | |
- | |
- $url = 'http://api.spsr.ru/waExec/WAExec'; | |
- | |
- $extra = array ( | |
- 'headers' => array('Content-Type: application/xml'), | |
- ); | |
- | |
- if (!empty($location['country'])) { | |
- $country_name = fn_get_country_name($location['country'], 'ru'); | |
- } else { | |
- $country_name = ''; | |
- } | |
- | |
- $data=<<<EOT | |
-<root xmlns="http://spsr.ru/webapi/Info/GetCities/1.0"> | |
-<p:Params Name="WAGetCities" Ver="1.0" xmlns:p="http://spsr.ru/webapi/WA/1.0" /> | |
-<GetCities CityName="{$city_name}" CountryName="{$country_name}"/> | |
-</root> | |
-EOT; | |
- | |
- $response = Http::post($url, $data, $extra); | |
- | |
- $xml = @simplexml_load_string($response); | |
- | |
- $status_code = (string) $xml->Result['RC']; | |
- | |
- if ($status_code != 0) { | |
- return false; | |
- } else { | |
- | |
- if (isset($xml->City->Cities) && !empty($xml->City)) { | |
- | |
- $result = array(); | |
- | |
- foreach ($xml->City->Cities as $key => $city) { | |
- $city_data = array(); | |
- foreach ($city->attributes() as $a_key => $value) { | |
- $city_data[$a_key] = (string) $value; | |
- } | |
- $result[] = $city_data; | |
- } | |
- } | |
- } | |
- | |
- if (empty($result)) { | |
- return false; | |
- } | |
- | |
- return $result; | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment