Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CountryRegion.php
Go to the documentation of this file.
1 <?php
8 
10 {
16  public function execute()
17  {
18  $arrRes = [];
19 
20  $countryId = $this->getRequest()->getParam('parent');
21  if (!empty($countryId)) {
22  $arrRegions = $this->_objectManager->create(
23  \Magento\Directory\Model\ResourceModel\Region\Collection::class
24  )->addCountryFilter(
25  $countryId
26  )->load()->toOptionArray();
27 
28  if (!empty($arrRegions)) {
29  foreach ($arrRegions as $region) {
30  $arrRes[] = $region;
31  }
32  }
33  }
34  $this->getResponse()->representJson(
35  $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($arrRes)
36  );
37  }
38 }