Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Address.php
Go to the documentation of this file.
1 <?php
7 
11 
23 {
27  const TYPE_BILLING = 'billing';
28 
29  const TYPE_SHIPPING = 'shipping';
30 
34  protected $order;
35 
39  protected $_eventPrefix = 'sales_order_address';
40 
44  protected $_eventObject = 'address';
45 
49  protected $orderFactory;
50 
54  protected $regionFactory;
55 
67  public function __construct(
68  \Magento\Framework\Model\Context $context,
69  \Magento\Framework\Registry $registry,
70  \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
72  \Magento\Sales\Model\OrderFactory $orderFactory,
73  \Magento\Directory\Model\RegionFactory $regionFactory,
74  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
75  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
76  array $data = []
77  ) {
78  $data = $this->implodeStreetField($data);
79  $this->regionFactory = $regionFactory;
80  $this->orderFactory = $orderFactory;
81  parent::__construct(
82  $context,
83  $registry,
84  $extensionFactory,
86  $resource,
87  $resourceCollection,
88  $data
89  );
90  }
91 
97  protected function _construct()
98  {
99  $this->_init(\Magento\Sales\Model\ResourceModel\Order\Address::class);
100  }
101 
110  public function setOrder(\Magento\Sales\Model\Order $order)
111  {
112  $this->order = $order;
113  return $this;
114  }
115 
121  public function getRegionCode()
122  {
123  $regionId = (!$this->getRegionId() && is_numeric($this->getRegion())) ?
124  $this->getRegion() :
125  $this->getRegionId();
126  $model = $this->regionFactory->create()->load($regionId);
127  if ($model->getCountryId() == $this->getCountryId()) {
128  return $model->getCode();
129  } elseif (is_string($this->getRegion())) {
130  return $this->getRegion();
131  } else {
132  return null;
133  }
134  }
135 
141  public function getName()
142  {
143  $name = '';
144  if ($this->getPrefix()) {
145  $name .= $this->getPrefix() . ' ';
146  }
147  $name .= $this->getFirstname();
148  if ($this->getMiddlename()) {
149  $name .= ' ' . $this->getMiddlename();
150  }
151  $name .= ' ' . $this->getLastname();
152  if ($this->getSuffix()) {
153  $name .= ' ' . $this->getSuffix();
154  }
155  return $name;
156  }
157 
164  protected function implodeStreetValue($value)
165  {
166  if (is_array($value)) {
167  $value = trim(implode(PHP_EOL, $value));
168  }
169  return $value;
170  }
171 
179  public function setData($key, $value = null)
180  {
181  if (is_array($key)) {
182  $key = $this->implodeStreetField($key);
184  $value = $this->implodeStreetValue($value);
185  }
186  return parent::setData($key, $value);
187  }
188 
195  protected function implodeStreetField(array $data)
196  {
197  if (array_key_exists(OrderAddressInterface::STREET, $data)) {
199  }
200  return $data;
201  }
202 
210  public function explodeStreetAddress()
211  {
212  $streetLines = $this->getStreet();
213  foreach ($streetLines as $lineNumber => $lineValue) {
214  $this->setData(OrderAddressInterface::STREET . ($lineNumber + 1), $lineValue);
215  }
216  return $this;
217  }
218 
224  public function getOrder()
225  {
226  if (!$this->order) {
227  $this->order = $this->orderFactory->create()->load($this->getParentId());
228  }
229  return $this->order;
230  }
231 
237  public function getStreet()
238  {
239  if (is_array($this->getData(OrderAddressInterface::STREET))) {
240  return $this->getData(OrderAddressInterface::STREET);
241  }
242  return explode(PHP_EOL, $this->getData(OrderAddressInterface::STREET));
243  }
244 
251  public function getStreetLine($number)
252  {
253  $lines = $this->getStreet();
254  return isset($lines[$number - 1]) ? $lines[$number - 1] : '';
255  }
256 
257  //@codeCoverageIgnoreStart
258 
264  public function getAddressType()
265  {
267  }
268 
274  public function getCity()
275  {
276  return $this->getData(OrderAddressInterface::CITY);
277  }
278 
284  public function getCompany()
285  {
287  }
288 
294  public function getCountryId()
295  {
297  }
298 
304  public function getCustomerAddressId()
305  {
307  }
308 
314  public function getCustomerId()
315  {
317  }
318 
324  public function getEmail()
325  {
326  return $this->getData(OrderAddressInterface::EMAIL);
327  }
328 
334  public function getEntityId()
335  {
337  }
338 
345  public function setEntityId($entityId)
346  {
347  return $this->setData(OrderAddressInterface::ENTITY_ID, $entityId);
348  }
349 
355  public function getFax()
356  {
357  return $this->getData(OrderAddressInterface::FAX);
358  }
359 
365  public function getFirstname()
366  {
368  }
369 
375  public function getLastname()
376  {
378  }
379 
385  public function getMiddlename()
386  {
388  }
389 
395  public function getParentId()
396  {
398  }
399 
405  public function getPostcode()
406  {
408  }
409 
415  public function getPrefix()
416  {
417  return $this->getData(OrderAddressInterface::PREFIX);
418  }
419 
425  public function getRegion()
426  {
427  return $this->getData(OrderAddressInterface::REGION);
428  }
429 
435  public function getRegionId()
436  {
438  }
439 
445  public function getSuffix()
446  {
447  return $this->getData(OrderAddressInterface::SUFFIX);
448  }
449 
455  public function getTelephone()
456  {
458  }
459 
465  public function getVatId()
466  {
467  return $this->getData(OrderAddressInterface::VAT_ID);
468  }
469 
475  public function getVatIsValid()
476  {
478  }
479 
485  public function getVatRequestDate()
486  {
488  }
489 
495  public function getVatRequestId()
496  {
498  }
499 
505  public function getVatRequestSuccess()
506  {
508  }
509 
513  public function setParentId($id)
514  {
516  }
517 
521  public function setCustomerAddressId($id)
522  {
524  }
525 
529  public function setRegionId($id)
530  {
532  }
533 
537  public function setStreet($street)
538  {
539  return $this->setData(OrderAddressInterface::STREET, $street);
540  }
541 
545  public function setCustomerId($id)
546  {
548  }
549 
553  public function setFax($fax)
554  {
555  return $this->setData(OrderAddressInterface::FAX, $fax);
556  }
557 
561  public function setRegion($region)
562  {
563  return $this->setData(OrderAddressInterface::REGION, $region);
564  }
565 
569  public function setPostcode($postcode)
570  {
571  return $this->setData(OrderAddressInterface::POSTCODE, $postcode);
572  }
573 
577  public function setLastname($lastname)
578  {
579  return $this->setData(OrderAddressInterface::LASTNAME, $lastname);
580  }
581 
585  public function setCity($city)
586  {
587  return $this->setData(OrderAddressInterface::CITY, $city);
588  }
589 
593  public function setEmail($email)
594  {
596  }
597 
601  public function setTelephone($telephone)
602  {
603  return $this->setData(OrderAddressInterface::TELEPHONE, $telephone);
604  }
605 
609  public function setCountryId($id)
610  {
612  }
613 
617  public function setFirstname($firstname)
618  {
619  return $this->setData(OrderAddressInterface::FIRSTNAME, $firstname);
620  }
621 
625  public function setAddressType($addressType)
626  {
627  return $this->setData(OrderAddressInterface::ADDRESS_TYPE, $addressType);
628  }
629 
633  public function setPrefix($prefix)
634  {
636  }
637 
641  public function setMiddlename($middlename)
642  {
643  return $this->setData(OrderAddressInterface::MIDDLENAME, $middlename);
644  }
645 
649  public function setSuffix($suffix)
650  {
652  }
653 
657  public function setCompany($company)
658  {
659  return $this->setData(OrderAddressInterface::COMPANY, $company);
660  }
661 
665  public function setVatId($id)
666  {
667  return $this->setData(OrderAddressInterface::VAT_ID, $id);
668  }
669 
673  public function setVatIsValid($vatIsValid)
674  {
675  return $this->setData(OrderAddressInterface::VAT_IS_VALID, $vatIsValid);
676  }
677 
681  public function setVatRequestId($id)
682  {
684  }
685 
689  public function setRegionCode($regionCode)
690  {
691  return $this->setData(OrderAddressInterface::KEY_REGION_CODE, $regionCode);
692  }
693 
697  public function setVatRequestDate($vatRequestDate)
698  {
699  return $this->setData(OrderAddressInterface::VAT_REQUEST_DATE, $vatRequestDate);
700  }
701 
705  public function setVatRequestSuccess($vatRequestSuccess)
706  {
707  return $this->setData(OrderAddressInterface::VAT_REQUEST_SUCCESS, $vatRequestSuccess);
708  }
709 
715  public function getExtensionAttributes()
716  {
717  return $this->_getExtensionAttributes();
718  }
719 
726  public function setExtensionAttributes(\Magento\Sales\Api\Data\OrderAddressExtensionInterface $extensionAttributes)
727  {
728  return $this->_setExtensionAttributes($extensionAttributes);
729  }
730 
731  //@codeCoverageIgnoreEnd
732 }
setVatRequestSuccess($vatRequestSuccess)
Definition: Address.php:705
$suffix
Definition: name.phtml:27
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$email
Definition: details.phtml:13
$number
Definition: details.phtml:22
$id
Definition: fieldset.phtml:14
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
$resource
Definition: bulk.php:12
setVatRequestDate($vatRequestDate)
Definition: Address.php:697
setData($key, $value=null)
Definition: Address.php:179
$prefix
Definition: name.phtml:25
$value
Definition: gender.phtml:16
setOrder(\Magento\Sales\Model\Order $order)
Definition: Address.php:110
setExtensionAttributes(\Magento\Sales\Api\Data\OrderAddressExtensionInterface $extensionAttributes)
Definition: Address.php:726
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, \Magento\Sales\Model\OrderFactory $orderFactory, \Magento\Directory\Model\RegionFactory $regionFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
Definition: Address.php:67
if(!isset($_GET['name'])) $name
Definition: log.php:14