I need some help in the module Magento directory. Actually I am able to sort id,two_letter_abbreviation & three_letter_abbreviation by setOrder to the collection which is defined in the helper class which is calling from the model.
i.e below is a function in the model class
public function getCountriesInfo()
{
$countriesInfo = [];
/** @var \Magento\Store\Model\Store $store */
$store = $this->storeManager->getStore();
$storeLocale = $this->scopeConfig->getValue(
'general/locale/code',
\Magento\Store\Model\ScopeInterface::SCOPE_STORES,
$store->getCode()
);
$countries = $this->directoryHelper->getCountryCollection($store);
$regions = $this->directoryHelper->getRegionData();
foreach ($countries as $data) {
$countryInfo = $this->setCountryInfo($data, $regions, $storeLocale);
$countriesInfo[] = $countryInfo;
}
return $countriesInfo;
}
Below is a function define in helper class.
public function getCountryCollection($store = null)
{
if (!$this->_countryCollection->isLoaded()) {
$this->_countryCollection->loadByStore($store);
}
return $this->_countryCollection;
}
I the above, i can sort by setOrder like $this->_countryCollection->setOrder('country_id,'ASC')
or by iso2_code & iso3_code. these three are the column of directory country table
My question is that how to sort full_name_english? please help me out. After that, I will override the file.
[
{
"id": "AD",
"two_letter_abbreviation": "AD",
"three_letter_abbreviation": "AND",
"full_name_locale": "Andorra",
"full_name_english": "Andorra"
},
{
"id": "AE",
"two_letter_abbreviation": "AE",
"three_letter_abbreviation": "ARE",
"full_name_locale": "United Arab Emirates",
"full_name_english": "United Arab Emirates"
},
{
"id": "AF",
"two_letter_abbreviation": "AF",
"three_letter_abbreviation": "AFG",
"full_name_locale": "Afghanistan",
"full_name_english": "Afghanistan"
},
{
"id": "AG",
"two_letter_abbreviation": "AG",
"three_letter_abbreviation": "ATG",
"full_name_locale": "Antigua & Barbuda",
"full_name_english": "Antigua & Barbuda"
}]
Update 1: Still did not get any solution
Update 2: I will update the answer to this once I have done with that.