44 $this->_countryCollectionFactory = $countryCollectionFactory;
45 $this->_regionCollectionFactory = $regionCollectionFactory;
54 if (!$this->_options) {
55 $countriesArray = $this->_countryCollectionFactory->create()->load()->toOptionArray(
false);
56 $this->_countries = [];
57 foreach ($countriesArray as $a) {
58 $this->_countries[$a[
'value']] = $a[
'label'];
62 $regionsCollection = $this->_regionCollectionFactory->create()->load();
63 foreach ($regionsCollection as $region) {
64 $countryRegions[$region->getCountryId()][$region->getId()] = $region->getDefaultName();
66 uksort($countryRegions, [$this,
'sortRegionCountries']);
69 foreach ($countryRegions as $countryId => $regions) {
71 foreach ($regions as $regionId => $regionName) {
72 $regionOptions[] = [
'label' => $regionName,
'value' => $regionId];
74 $this->_options[] = [
'label' => $this->_countries[$countryId],
'value' => $regionOptions];
78 if (!$isMultiselect) {
79 array_unshift(
$options, [
'value' =>
'',
'label' =>
'']);
92 return strcmp($this->_countries[$a], $this->_countries[$b]);
__construct(\Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory, \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollectionFactory)
sortRegionCountries($a, $b)
$_countryCollectionFactory
$_regionCollectionFactory
toOptionArray($isMultiselect=false)