Region.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Directory\Model;
  7. /**
  8. * Region
  9. *
  10. * @method string getRegionId()
  11. * @method string getCountryId()
  12. * @method \Magento\Directory\Model\Region setCountryId(string $value)
  13. * @method string getCode()
  14. * @method \Magento\Directory\Model\Region setCode(string $value)
  15. * @method string getDefaultName()
  16. * @method \Magento\Directory\Model\Region setDefaultName(string $value)
  17. *
  18. * @api
  19. * @since 100.0.2
  20. */
  21. class Region extends \Magento\Framework\Model\AbstractModel
  22. {
  23. /**
  24. * @return void
  25. */
  26. protected function _construct()
  27. {
  28. $this->_init(\Magento\Directory\Model\ResourceModel\Region::class);
  29. }
  30. /**
  31. * Retrieve region name
  32. *
  33. * If name is not declared, then default_name is used
  34. *
  35. * @return string
  36. */
  37. public function getName()
  38. {
  39. $name = $this->getData('name');
  40. if ($name === null) {
  41. $name = $this->getData('default_name');
  42. }
  43. return $name;
  44. }
  45. /**
  46. * Load region by code
  47. *
  48. * @param string $code
  49. * @param string $countryId
  50. * @return $this
  51. */
  52. public function loadByCode($code, $countryId)
  53. {
  54. if ($code) {
  55. $this->_getResource()->loadByCode($this, $code, $countryId);
  56. }
  57. return $this;
  58. }
  59. /**
  60. * Load region by name
  61. *
  62. * @param string $name
  63. * @param string $countryId
  64. * @return $this
  65. */
  66. public function loadByName($name, $countryId)
  67. {
  68. $this->_getResource()->loadByName($this, $name, $countryId);
  69. return $this;
  70. }
  71. }