diff --git a/src/app/frontend/controllers/MenuController.php b/src/app/frontend/controllers/MenuController.php index 5faba80..1ec4077 100644 --- a/src/app/frontend/controllers/MenuController.php +++ b/src/app/frontend/controllers/MenuController.php @@ -32,10 +32,11 @@ class MenuController extends \controllers\ControllerBase $err = 0; $cities_ = $this->novaposhta->city(); - - foreach( $cities_->city as $c ) + + foreach( $cities_->item as $c ) { - $cities[strval($c->id)] = strval($c->nameUkr); + + $cities[strval($c->CityID)] = strval($c->Description); } if ( !empty( $in_cart ) ) @@ -318,18 +319,18 @@ class MenuController extends \controllers\ControllerBase $length = strlen($term); $cities_ = $this->novaposhta->city(); - foreach( $cities_->city as $c ) + foreach( $cities_->item as $c ) { - $cities[strval($c->id)] = strval($c->nameUkr); + $cities[strval($c->CityID)] = strval($c->Description); - if( mb_strtolower( substr( strval($c->nameUkr), 0, $length ), 'utf-8' ) == mb_strtolower( $term, 'utf-8' ) ) + if( mb_strtolower( substr( strval($c->Description), 0, $length ), 'utf-8' ) == mb_strtolower( $term, 'utf-8' ) ) { $selected_cities[] = [ - 'label' => strval($c->nameUkr), - 'value' => strval($c->nameUkr), - 'id' => strval($c->id), - 'ref' => strval($c->ref) + 'label' => strval($c->Description), + 'value' => strval($c->Ref), + 'id' => strval($c->CityID), + 'ref' => strval($c->Ref) ]; } } @@ -345,13 +346,13 @@ class MenuController extends \controllers\ControllerBase $city = $this->request->getPost('city', 'string', '' ); $offices_ = $this->novaposhta->warenhouse( $city ); - foreach( $offices_->warenhouse as $c ) + foreach( $offices_->item as $c ) { $offices[] = [ - 'number' => strval($c->number), - 'address' => strval($c->address), - 'store_ref' => strval($c->ref) + 'number' => strval($c->Number), + 'address' => strval($c->Description), + 'store_ref' => strval($c->Ref) ]; } diff --git a/src/lib/novaposhta.php b/src/lib/novaposhta.php index dfed0ab..95417fb 100644 --- a/src/lib/novaposhta.php +++ b/src/lib/novaposhta.php @@ -21,7 +21,7 @@ namespace protected $_sender_warehouse_ref = '1'; protected $_out_name = 'Петров Иван Иваныч'; protected $_out_phone = '0671234567'; - protected $_api_key = 'f77cc4bcaa985eb481ed289b89e6fb9e'; + protected $_api_key = '46eb7be54b344abfe21feab2ee17071c'; protected $_description = 'Насіння'; protected $_pack = 'Пакет'; protected $_rcpt_name = 'Приватна особа'; @@ -35,7 +35,7 @@ namespace public function send($xml) { $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, 'http://orders.novaposhta.ua/xml.php'); + curl_setopt($ch, CURLOPT_URL, 'https://api.novaposhta.ua/v2.0/xml/'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); curl_setopt($ch, CURLOPT_HEADER, 0); @@ -230,22 +230,22 @@ namespace * Запрос на получение списка складов Новой почты для определённого города (или полный список, если город не указан) $filter — город, по которому нужно отфильтровать список складов Новой почты */ - public function warenhouse($filter=false) + public function warenhouse($filter = false) { - $xml = - ' - - '.$this->_api_key.' - '; - if($filter) - { - $xml.=''.$filter.''; - } - $xml.=''; - $xml = simplexml_load_string($this->send($xml)); - return($xml->result->whs); + $xml = ' + + '.$this->_api_key.' + getWarehouses + '. + ($filter ? "$filter" : "") + .' + Address + '; + + $xml = simplexml_load_string($this->send($xml)); + return($xml->data); } ///////////////////////////////////////////////////////////////////////////// @@ -262,9 +262,16 @@ namespace '; - $xml = simplexml_load_string( $this->send($xml) ); + $xml = ' + + '.$this->_api_key.' + getCities + + Address +'; - return($xml->result->cities); + $xml = simplexml_load_string( $this->send($xml) ); + return($xml->data); } ///////////////////////////////////////////////////////////////////////////// @@ -302,6 +309,7 @@ namespace return($xml); } + ///////////////////////////////////////////////////////////////////////////// } diff --git a/www/js/main.js b/www/js/main.js index a39d961..e9f2865 100644 --- a/www/js/main.js +++ b/www/js/main.js @@ -133,7 +133,7 @@ function getNovaPoshtaCity() minLength: 2, select: function( event, ui ) { - $( "#order_city_novaposhta" ).val( ui.item.value ); + $( "#order_city_novaposhta" ).val( ui.item.label ); $( "#order_city_ref" ).val( ui.item.ref ); $('#loading_city').addClass('display_none'); diff --git a/www/js/main_ru.js b/www/js/main_ru.js index 1d20142..70ed5c7 100644 --- a/www/js/main_ru.js +++ b/www/js/main_ru.js @@ -126,7 +126,7 @@ function getNovaPoshtaCity() minLength: 2, select: function( event, ui ) { - $( "#order_city_novaposhta" ).val( ui.item.value ); + $( "#order_city_novaposhta" ).val( ui.item.label ); $( "#order_city_ref" ).val( ui.item.ref ); $('#loading_city').addClass('display_none'); -- libgit2 0.21.4