Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SellerBuilder.php
Go to the documentation of this file.
1 <?php
7 
15 
23 {
27  private $scopeConfig;
28 
32  private $regionFactory;
33 
37  private $regionCodes = [];
38 
43  public function __construct(
44  ScopeConfigInterface $scopeConfig,
45  RegionFactory $regionFactory
46  ) {
47  $this->scopeConfig = $scopeConfig;
48  $this->regionFactory = $regionFactory;
49  }
50 
57  public function build(Order $order)
58  {
59  $store = $order->getStore();
60 
61  return [
62  'seller' => [
63  'name' => $this->getConfigValue(Information::XML_PATH_STORE_INFO_NAME, $store),
64  'domain' => $this->getPublicDomain($store),
65  'shipFromAddress' => [
66  'streetAddress' => $this->getConfigValue(Shipment::XML_PATH_STORE_ADDRESS1, $store),
67  'unit' => $this->getConfigValue(Shipment::XML_PATH_STORE_ADDRESS2, $store),
68  'city' => $this->getConfigValue(Shipment::XML_PATH_STORE_CITY, $store),
69  'provinceCode' => $this->getRegionCodeById(
70  $this->getConfigValue(Shipment::XML_PATH_STORE_REGION_ID, $store)
71  ),
72  'postalCode' => $this->getConfigValue(Shipment::XML_PATH_STORE_ZIP, $store),
73  'countryCode' => $this->getConfigValue(Shipment::XML_PATH_STORE_COUNTRY_ID, $store),
74  ],
75  'corporateAddress' => [
76  'streetAddress' => $this->getConfigValue(Information::XML_PATH_STORE_INFO_STREET_LINE1, $store),
77  'unit' => $this->getConfigValue(Information::XML_PATH_STORE_INFO_STREET_LINE2, $store),
78  'city' => $this->getConfigValue(Information::XML_PATH_STORE_INFO_CITY, $store),
79  'provinceCode' => $this->getRegionCodeById(
81  ),
82  'postalCode' => $this->getConfigValue(Information::XML_PATH_STORE_INFO_POSTCODE, $store),
83  'countryCode' => $this->getConfigValue(Information::XML_PATH_STORE_INFO_COUNTRY_CODE, $store),
84  ]
85  ]
86  ];
87  }
88 
95  private function getRegionCodeById($regionId)
96  {
97  if (!isset($this->regionCodes[$regionId])) {
98  $this->regionCodes[$regionId] = $this->regionFactory->create()->load($regionId)->getCode();
99  }
100 
101  return $this->regionCodes[$regionId];
102  }
103 
111  private function getConfigValue($value, StoreInterface $store)
112  {
113  return $this->scopeConfig->getValue(
114  $value,
116  $store
117  );
118  }
119 
126  private function getPublicDomain(StoreInterface $store)
127  {
128  $baseUrl = $store->getBaseUrl();
129  $domain = parse_url($baseUrl, PHP_URL_HOST);
130  if (\function_exists('checkdnsrr') && false === \checkdnsrr($domain)) {
131  return null;
132  }
133 
134  return $domain;
135  }
136 }
__construct(ScopeConfigInterface $scopeConfig, RegionFactory $regionFactory)
$order
Definition: order.php:55
$value
Definition: gender.phtml:16