/** * Export address data to request * * @param DataObject $address * @param string $type * @return array */ protected function getAddress(DataObject $address, $type = '') { $type = !empty($type) ? $type . '_' : ''; $request = [$type . 'first_name' => $address->getFirstname(), $type . 'last_name' => $address->getLastname(), $type . 'city' => $address->getCity(), $type . 'state' => $this->getRegion($address), $type . 'zip' => $address->getPostcode(), $type . 'country' => $address->getCountryId()]; $streets = $this->getAddressStreets($address); $request[$type . 'address1'] = $streets[0]; $request[$type . 'address2'] = $streets[1]; return $request; }
/** * Get billing address request data * * @param \Magento\Framework\DataObject $address * @return array * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function _getBillingAddress(\Magento\Framework\DataObject $address) { $region = $address->getRegionCode() ? $address->getRegionCode() : $address->getRegion(); $request = ['billing_first_name' => $address->getFirstname(), 'billing_last_name' => $address->getLastname(), 'billing_city' => $address->getCity(), 'billing_state' => $region ? $region : $address->getCity(), 'billing_zip' => $address->getPostcode(), 'billing_country' => $address->getCountryId()]; // convert streets to tow lines format $street = $this->_customerAddress->convertStreetLines($address->getStreet(), 2); $request['billing_address1'] = isset($street[0]) ? $street[0] : ''; $request['billing_address2'] = isset($street[1]) ? $street[1] : ''; return $request; }
/** * @param DataObject $request * @param DataObject $shipping * * @return Object */ public function setShipping($request, $shipping) { $request->setShiptofirstname($shipping->getFirstname())->setShiptolastname($shipping->getLastname())->setShiptostreet(implode(' ', $shipping->getStreet()))->setShiptocity($shipping->getCity())->setShiptostate($shipping->getRegionCode())->setShiptozip($shipping->getPostcode())->setShiptocountry($shipping->getCountryId()); return $request; }