Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AddressDataBuilder.php
Go to the documentation of this file.
1 <?php
7 
10 
15 {
19  const SHIPPING_ADDRESS = 'shipping';
20 
24  const BILLING_ADDRESS = 'billing';
25 
29  const FIRST_NAME = 'firstName';
30 
34  const LAST_NAME = 'lastName';
35 
39  const COMPANY = 'company';
40 
45  const STREET_ADDRESS = 'streetAddress';
46 
50  const EXTENDED_ADDRESS = 'extendedAddress';
51 
55  const LOCALITY = 'locality';
56 
61  const REGION = 'region';
62 
68  const POSTAL_CODE = 'postalCode';
69 
76  const COUNTRY_CODE = 'countryCodeAlpha2';
77 
81  private $subjectReader;
82 
88  public function __construct(SubjectReader $subjectReader)
89  {
90  $this->subjectReader = $subjectReader;
91  }
92 
96  public function build(array $buildSubject)
97  {
98  $paymentDO = $this->subjectReader->readPayment($buildSubject);
99 
100  $order = $paymentDO->getOrder();
101  $result = [];
102 
103  $billingAddress = $order->getBillingAddress();
104  if ($billingAddress) {
106  self::FIRST_NAME => $billingAddress->getFirstname(),
107  self::LAST_NAME => $billingAddress->getLastname(),
108  self::COMPANY => $billingAddress->getCompany(),
109  self::STREET_ADDRESS => $billingAddress->getStreetLine1(),
110  self::EXTENDED_ADDRESS => $billingAddress->getStreetLine2(),
111  self::LOCALITY => $billingAddress->getCity(),
112  self::REGION => $billingAddress->getRegionCode(),
113  self::POSTAL_CODE => $billingAddress->getPostcode(),
114  self::COUNTRY_CODE => $billingAddress->getCountryId()
115  ];
116  }
117 
118  $shippingAddress = $order->getShippingAddress();
119  if ($shippingAddress) {
121  self::FIRST_NAME => $shippingAddress->getFirstname(),
122  self::LAST_NAME => $shippingAddress->getLastname(),
123  self::COMPANY => $shippingAddress->getCompany(),
124  self::STREET_ADDRESS => $shippingAddress->getStreetLine1(),
125  self::EXTENDED_ADDRESS => $shippingAddress->getStreetLine2(),
126  self::LOCALITY => $shippingAddress->getCity(),
127  self::REGION => $shippingAddress->getRegionCode(),
128  self::POSTAL_CODE => $shippingAddress->getPostcode(),
129  self::COUNTRY_CODE => $shippingAddress->getCountryId()
130  ];
131  }
132 
133  return $result;
134  }
135 }
$billingAddress
Definition: order.php:25
$shippingAddress
Definition: order.php:40
$order
Definition: order.php:55