diff --git a/addons/default/visiosoft/location-module/src/Http/Controller/AjaxController.php b/addons/default/visiosoft/location-module/src/Http/Controller/AjaxController.php index 0ac30691e..89f057d97 100644 --- a/addons/default/visiosoft/location-module/src/Http/Controller/AjaxController.php +++ b/addons/default/visiosoft/location-module/src/Http/Controller/AjaxController.php @@ -1,6 +1,7 @@ country_model = $countryModel; $this->city_model = $cityModel; @@ -48,6 +55,7 @@ class AjaxController extends PublicController $this->neighborhood_model = $neighborhoodModel; $this->village_model = $villageModel; parent::__construct(); + $this->citiesEntryTranslationsModel = $citiesEntryTranslationsModel; } /** @@ -72,6 +80,21 @@ class AjaxController extends PublicController $id = explode(',', $this->request->id); $query = $this->city_model->whereIn('parent_country_id', $id); + if (request()->order_by && $this->city_model->isTranslatedAttribute(request()->order_by)) { + return $this->citiesEntryTranslationsModel->newQuery() + ->select('entry_id as id', 'name') + ->whereIn('locale', [ + Request()->session()->get('_locale'), + setting_value('streams::default_locale'), + 'en' + ]) + ->whereIn('entry_id', $query->pluck('id')->all()) + ->orderBy(request()->order_by) + ->get(); + } elseif ($orderBy = request()->order_by) { + return $this->queryOrder($query, $orderBy); + } + return $this->queryOrder($query); } } @@ -133,10 +156,10 @@ class AjaxController extends PublicController } } - public function queryOrder($query) + public function queryOrder($query, $orderBy = null) { $sorting_type = setting_value('visiosoft.module.location::sorting_type'); - $sorting_column = setting_value('visiosoft.module.location::sorting_column'); + $sorting_column = $orderBy ?: setting_value('visiosoft.module.location::sorting_column'); return $query->orderBy($sorting_column, $sorting_type)->get(); }