scopeConfig = $scopeConfig; $this->regionFactory = $regionFactory; } /** * Returns seller data params * * @param Order $order * @return array */ public function build(Order $order) { $store = $order->getStore(); return [ 'seller' => [ 'name' => $this->getConfigValue(Information::XML_PATH_STORE_INFO_NAME, $store), 'domain' => $this->getPublicDomain($store), 'shipFromAddress' => [ 'streetAddress' => $this->getConfigValue(Shipment::XML_PATH_STORE_ADDRESS1, $store), 'unit' => $this->getConfigValue(Shipment::XML_PATH_STORE_ADDRESS2, $store), 'city' => $this->getConfigValue(Shipment::XML_PATH_STORE_CITY, $store), 'provinceCode' => $this->getRegionCodeById( $this->getConfigValue(Shipment::XML_PATH_STORE_REGION_ID, $store) ), 'postalCode' => $this->getConfigValue(Shipment::XML_PATH_STORE_ZIP, $store), 'countryCode' => $this->getConfigValue(Shipment::XML_PATH_STORE_COUNTRY_ID, $store), ], 'corporateAddress' => [ 'streetAddress' => $this->getConfigValue(Information::XML_PATH_STORE_INFO_STREET_LINE1, $store), 'unit' => $this->getConfigValue(Information::XML_PATH_STORE_INFO_STREET_LINE2, $store), 'city' => $this->getConfigValue(Information::XML_PATH_STORE_INFO_CITY, $store), 'provinceCode' => $this->getRegionCodeById( $this->getConfigValue(Information::XML_PATH_STORE_INFO_REGION_CODE, $store) ), 'postalCode' => $this->getConfigValue(Information::XML_PATH_STORE_INFO_POSTCODE, $store), 'countryCode' => $this->getConfigValue(Information::XML_PATH_STORE_INFO_COUNTRY_CODE, $store), ] ] ]; } /** * Returns region code by id * * @param int $regionId * @return string */ private function getRegionCodeById($regionId) { if (!isset($this->regionCodes[$regionId])) { $this->regionCodes[$regionId] = $this->regionFactory->create()->load($regionId)->getCode(); } return $this->regionCodes[$regionId]; } /** * Returns value from config * * @param string $value * @param StoreInterface $store * @return mixed */ private function getConfigValue($value, StoreInterface $store) { return $this->scopeConfig->getValue( $value, ScopeInterface::SCOPE_STORE, $store ); } /** * Returns public domain name * * @param StoreInterface $store * @return string|null null if no DNS records corresponding to a current host found */ private function getPublicDomain(StoreInterface $store) { $baseUrl = $store->getBaseUrl(); $domain = parse_url($baseUrl, PHP_URL_HOST); if (\function_exists('checkdnsrr') && false === \checkdnsrr($domain)) { return null; } return $domain; } }