Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Country.php
Go to the documentation of this file.
1 <?php
7 
15 {
21  protected function _construct()
22  {
23  $this->_init('directory_country', 'country_id');
24  }
25 
34  public function loadByCode(\Magento\Directory\Model\Country $country, $code)
35  {
36  switch (strlen($code)) {
37  case 2:
38  $field = 'iso2_code';
39  break;
40 
41  case 3:
42  $field = 'iso3_code';
43  break;
44 
45  default:
46  throw new \Magento\Framework\Exception\LocalizedException(
47  __('Please correct the country code: %1.', htmlspecialchars($code))
48  );
49  }
50 
51  return $this->load($country, $code, $field);
52  }
53 }
__()
Definition: __.php:13
load(\Magento\Framework\Model\AbstractModel $object, $value, $field=null)
Definition: AbstractDb.php:339
$code
Definition: info.phtml:12
loadByCode(\Magento\Directory\Model\Country $country, $code)
Definition: Country.php:34