Address.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <?php
  2. /**
  3. * Data Model implementing the Address interface
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Customer\Model\Data;
  9. use Magento\Customer\Api\Data\RegionInterface;
  10. use \Magento\Framework\Api\AttributeValueFactory;
  11. /**
  12. * Class Address
  13. *
  14. *
  15. * @api
  16. * @since 100.0.2
  17. */
  18. class Address extends \Magento\Framework\Api\AbstractExtensibleObject implements
  19. \Magento\Customer\Api\Data\AddressInterface
  20. {
  21. /**
  22. * @var \Magento\Customer\Api\AddressMetadataInterface
  23. */
  24. protected $metadataService;
  25. /**
  26. * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
  27. * @param AttributeValueFactory $attributeValueFactory
  28. * @param \Magento\Customer\Api\AddressMetadataInterface $metadataService
  29. * @param array $data
  30. */
  31. public function __construct(
  32. \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
  33. AttributeValueFactory $attributeValueFactory,
  34. \Magento\Customer\Api\AddressMetadataInterface $metadataService,
  35. $data = []
  36. ) {
  37. $this->metadataService = $metadataService;
  38. parent::__construct($extensionFactory, $attributeValueFactory, $data);
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. protected function getCustomAttributesCodes()
  44. {
  45. if ($this->customAttributesCodes === null) {
  46. $this->customAttributesCodes = $this->getEavAttributesCodes($this->metadataService);
  47. }
  48. return $this->customAttributesCodes;
  49. }
  50. /**
  51. * Get id
  52. *
  53. * @return int|null
  54. */
  55. public function getId()
  56. {
  57. return $this->_get(self::ID);
  58. }
  59. /**
  60. * Get region
  61. *
  62. * @return \Magento\Customer\Api\Data\RegionInterface|null
  63. */
  64. public function getRegion()
  65. {
  66. return $this->_get(self::REGION);
  67. }
  68. /**
  69. * Get region ID
  70. *
  71. * @return int
  72. */
  73. public function getRegionId()
  74. {
  75. return $this->_get(self::REGION_ID);
  76. }
  77. /**
  78. * Get country id
  79. *
  80. * @return string|null
  81. */
  82. public function getCountryId()
  83. {
  84. return $this->_get(self::COUNTRY_ID);
  85. }
  86. /**
  87. * Get street
  88. *
  89. * @return string[]|null
  90. */
  91. public function getStreet()
  92. {
  93. return $this->_get(self::STREET);
  94. }
  95. /**
  96. * Get company
  97. *
  98. * @return string|null
  99. */
  100. public function getCompany()
  101. {
  102. return $this->_get(self::COMPANY);
  103. }
  104. /**
  105. * Get telephone number
  106. *
  107. * @return string|null
  108. */
  109. public function getTelephone()
  110. {
  111. return $this->_get(self::TELEPHONE);
  112. }
  113. /**
  114. * Get fax number
  115. *
  116. * @return string|null
  117. */
  118. public function getFax()
  119. {
  120. return $this->_get(self::FAX);
  121. }
  122. /**
  123. * Get postcode
  124. *
  125. * @return string|null
  126. */
  127. public function getPostcode()
  128. {
  129. return $this->_get(self::POSTCODE);
  130. }
  131. /**
  132. * Get city name
  133. *
  134. * @return string|null
  135. */
  136. public function getCity()
  137. {
  138. return $this->_get(self::CITY);
  139. }
  140. /**
  141. * Get first name
  142. *
  143. * @return string|null
  144. */
  145. public function getFirstname()
  146. {
  147. return $this->_get(self::FIRSTNAME);
  148. }
  149. /**
  150. * Get last name
  151. *
  152. * @return string|null
  153. */
  154. public function getLastname()
  155. {
  156. return $this->_get(self::LASTNAME);
  157. }
  158. /**
  159. * Get middle name
  160. *
  161. * @return string|null
  162. */
  163. public function getMiddlename()
  164. {
  165. return $this->_get(self::MIDDLENAME);
  166. }
  167. /**
  168. * Get prefix
  169. *
  170. * @return string|null
  171. */
  172. public function getPrefix()
  173. {
  174. return $this->_get(self::PREFIX);
  175. }
  176. /**
  177. * Get suffix
  178. *
  179. * @return string|null
  180. */
  181. public function getSuffix()
  182. {
  183. return $this->_get(self::SUFFIX);
  184. }
  185. /**
  186. * Get Vat id
  187. *
  188. * @return string|null
  189. */
  190. public function getVatId()
  191. {
  192. return $this->_get(self::VAT_ID);
  193. }
  194. /**
  195. * Get customer id
  196. *
  197. * @return string|null
  198. */
  199. public function getCustomerId()
  200. {
  201. return $this->_get(self::CUSTOMER_ID);
  202. }
  203. /**
  204. * Get if this address is default shipping address.
  205. *
  206. * @return bool|null
  207. */
  208. public function isDefaultShipping()
  209. {
  210. return $this->_get(self::DEFAULT_SHIPPING);
  211. }
  212. /**
  213. * Get if this address is default billing address
  214. *
  215. * @return bool|null
  216. */
  217. public function isDefaultBilling()
  218. {
  219. return $this->_get(self::DEFAULT_BILLING);
  220. }
  221. /**
  222. * Set ID
  223. *
  224. * @param int $id
  225. * @return $this
  226. */
  227. public function setId($id)
  228. {
  229. return $this->setData(self::ID, $id);
  230. }
  231. /**
  232. * Set customer ID
  233. *
  234. * @param int $customerId
  235. * @return $this
  236. */
  237. public function setCustomerId($customerId)
  238. {
  239. return $this->setData(self::CUSTOMER_ID, $customerId);
  240. }
  241. /**
  242. * Set region
  243. *
  244. * @param \Magento\Customer\Api\Data\RegionInterface $region
  245. * @return $this
  246. */
  247. public function setRegion(RegionInterface $region = null)
  248. {
  249. return $this->setData(self::REGION, $region);
  250. }
  251. /**
  252. * Set region ID
  253. *
  254. * @param int $regionId
  255. * @return $this
  256. */
  257. public function setRegionId($regionId)
  258. {
  259. return $this->setData(self::REGION_ID, $regionId);
  260. }
  261. /**
  262. * Set country id
  263. *
  264. * @param string $countryId
  265. * @return $this
  266. */
  267. public function setCountryId($countryId)
  268. {
  269. return $this->setData(self::COUNTRY_ID, $countryId);
  270. }
  271. /**
  272. * Set street
  273. *
  274. * @param string[] $street
  275. * @return $this
  276. */
  277. public function setStreet(array $street)
  278. {
  279. return $this->setData(self::STREET, $street);
  280. }
  281. /**
  282. * Set company
  283. *
  284. * @param string $company
  285. * @return $this
  286. */
  287. public function setCompany($company)
  288. {
  289. return $this->setData(self::COMPANY, $company);
  290. }
  291. /**
  292. * Set telephone number
  293. *
  294. * @param string $telephone
  295. * @return $this
  296. */
  297. public function setTelephone($telephone)
  298. {
  299. return $this->setData(self::TELEPHONE, $telephone);
  300. }
  301. /**
  302. * Set fax number
  303. *
  304. * @param string $fax
  305. * @return $this
  306. */
  307. public function setFax($fax)
  308. {
  309. return $this->setData(self::FAX, $fax);
  310. }
  311. /**
  312. * Set postcode
  313. *
  314. * @param string $postcode
  315. * @return $this
  316. */
  317. public function setPostcode($postcode)
  318. {
  319. return $this->setData(self::POSTCODE, $postcode);
  320. }
  321. /**
  322. * Set city name
  323. *
  324. * @param string $city
  325. * @return $this
  326. */
  327. public function setCity($city)
  328. {
  329. return $this->setData(self::CITY, $city);
  330. }
  331. /**
  332. * Set first name
  333. *
  334. * @param string $firstName
  335. * @return $this
  336. */
  337. public function setFirstname($firstName)
  338. {
  339. return $this->setData(self::FIRSTNAME, $firstName);
  340. }
  341. /**
  342. * Set last name
  343. *
  344. * @param string $lastName
  345. * @return $this
  346. */
  347. public function setLastname($lastName)
  348. {
  349. return $this->setData(self::LASTNAME, $lastName);
  350. }
  351. /**
  352. * Set middle name
  353. *
  354. * @param string $middleName
  355. * @return $this
  356. */
  357. public function setMiddlename($middleName)
  358. {
  359. return $this->setData(self::MIDDLENAME, $middleName);
  360. }
  361. /**
  362. * Set prefix
  363. *
  364. * @param string $prefix
  365. * @return $this
  366. */
  367. public function setPrefix($prefix)
  368. {
  369. return $this->setData(self::PREFIX, $prefix);
  370. }
  371. /**
  372. * Set suffix
  373. *
  374. * @param string $suffix
  375. * @return $this
  376. */
  377. public function setSuffix($suffix)
  378. {
  379. return $this->setData(self::SUFFIX, $suffix);
  380. }
  381. /**
  382. * Set Vat id
  383. *
  384. * @param string $vatId
  385. * @return $this
  386. */
  387. public function setVatId($vatId)
  388. {
  389. return $this->setData(self::VAT_ID, $vatId);
  390. }
  391. /**
  392. * Set if this address is default shipping address.
  393. *
  394. * @param bool $isDefaultShipping
  395. * @return $this
  396. */
  397. public function setIsDefaultShipping($isDefaultShipping)
  398. {
  399. return $this->setData(self::DEFAULT_SHIPPING, $isDefaultShipping);
  400. }
  401. /**
  402. * Set if this address is default billing address
  403. *
  404. * @param bool $isDefaultBilling
  405. * @return $this
  406. */
  407. public function setIsDefaultBilling($isDefaultBilling)
  408. {
  409. return $this->setData(self::DEFAULT_BILLING, $isDefaultBilling);
  410. }
  411. /**
  412. * {@inheritdoc}
  413. *
  414. * @return \Magento\Customer\Api\Data\AddressExtensionInterface|null
  415. */
  416. public function getExtensionAttributes()
  417. {
  418. return $this->_getExtensionAttributes();
  419. }
  420. /**
  421. * {@inheritdoc}
  422. *
  423. * @param \Magento\Customer\Api\Data\AddressExtensionInterface $extensionAttributes
  424. * @return $this
  425. */
  426. public function setExtensionAttributes(\Magento\Customer\Api\Data\AddressExtensionInterface $extensionAttributes)
  427. {
  428. return $this->_setExtensionAttributes($extensionAttributes);
  429. }
  430. }