Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Info.php
Go to the documentation of this file.
1 <?php
7 
11 
17 class Info extends \Magento\Sales\Block\Adminhtml\Order\AbstractOrder
18 {
24  protected $metadata;
25 
31  protected $groupRepository;
32 
39 
43  protected $addressRenderer;
44 
57  public function __construct(
58  \Magento\Backend\Block\Template\Context $context,
59  \Magento\Framework\Registry $registry,
60  \Magento\Sales\Helper\Admin $adminHelper,
61  \Magento\Customer\Api\GroupRepositoryInterface $groupRepository,
62  \Magento\Customer\Api\CustomerMetadataInterface $metadata,
63  \Magento\Customer\Model\Metadata\ElementFactory $elementFactory,
65  array $data = []
66  ) {
67  $this->groupRepository = $groupRepository;
68  $this->metadata = $metadata;
69  $this->_metadataElementFactory = $elementFactory;
70  $this->addressRenderer = $addressRenderer;
71  parent::__construct($context, $registry, $adminHelper, $data);
72  }
73 
80  protected function _beforeToHtml()
81  {
82  if (!$this->getParentBlock()) {
83  throw new \Magento\Framework\Exception\LocalizedException(
84  __('Please correct the parent block for this block.')
85  );
86  }
87  $this->setOrder($this->getParentBlock()->getOrder());
88 
89  foreach ($this->getParentBlock()->getOrderInfoData() as $key => $value) {
90  $this->setDataUsingMethod($key, $value);
91  }
92 
93  parent::_beforeToHtml();
94  }
95 
101  public function getOrderStoreName()
102  {
103  if ($this->getOrder()) {
104  $storeId = $this->getOrder()->getStoreId();
105  if ($storeId === null) {
106  $deleted = __(' [deleted]');
107  return nl2br($this->getOrder()->getStoreName()) . $deleted;
108  }
109  $store = $this->_storeManager->getStore($storeId);
110  $name = [$store->getWebsite()->getName(), $store->getGroup()->getName(), $store->getName()];
111  return implode('<br/>', $name);
112  }
113 
114  return null;
115  }
116 
122  public function getCustomerGroupName()
123  {
124  if ($this->getOrder()) {
125  $customerGroupId = $this->getOrder()->getCustomerGroupId();
126  try {
127  if ($customerGroupId !== null) {
128  return $this->groupRepository->getById($customerGroupId)->getCode();
129  }
130  } catch (NoSuchEntityException $e) {
131  return '';
132  }
133  }
134 
135  return '';
136  }
137 
143  public function getCustomerViewUrl()
144  {
145  if ($this->getOrder()->getCustomerIsGuest() || !$this->getOrder()->getCustomerId()) {
146  return '';
147  }
148 
149  return $this->getUrl('customer/index/edit', ['id' => $this->getOrder()->getCustomerId()]);
150  }
151 
158  public function getViewUrl($orderId)
159  {
160  return $this->getUrl('sales/order/view', ['order_id' => $orderId]);
161  }
162 
171  protected function _prepareAccountDataSortOrder(array $data, $sortOrder)
172  {
173  if (isset($data[$sortOrder])) {
174  return $this->_prepareAccountDataSortOrder($data, $sortOrder + 1);
175  }
176 
177  return $sortOrder;
178  }
179 
186  public function getCustomerAccountData()
187  {
188  $accountData = [];
189  $entityType = 'customer';
190 
191  /* @var \Magento\Customer\Api\Data\AttributeMetadataInterface $attribute */
192  foreach ($this->metadata->getAllAttributesMetadata($entityType) as $attribute) {
193  if (!$attribute->isVisible() || $attribute->isSystem()) {
194  continue;
195  }
196  $orderKey = sprintf('customer_%s', $attribute->getAttributeCode());
197  $orderValue = $this->getOrder()->getData($orderKey);
198  if ($orderValue != '') {
199  $metadataElement = $this->_metadataElementFactory->create($attribute, $orderValue, $entityType);
200  $value = $metadataElement->outputValue(AttributeDataFactory::OUTPUT_FORMAT_HTML);
201  $sortOrder = $attribute->getSortOrder() + $attribute->isUserDefined() ? 200 : 0;
202  $sortOrder = $this->_prepareAccountDataSortOrder($accountData, $sortOrder);
203  $accountData[$sortOrder] = [
204  'label' => $attribute->getFrontendLabel(),
205  'value' => $this->escapeHtml($value, ['br']),
206  ];
207  }
208  }
209  ksort($accountData, SORT_NUMERIC);
210 
211  return $accountData;
212  }
213 
221  public function getAddressEditLink($address, $label = '')
222  {
223  if ($this->_authorization->isAllowed('Magento_Sales::actions_edit')) {
224  if (empty($label)) {
225  $label = __('Edit');
226  }
227  $url = $this->getUrl('sales/order/address', ['address_id' => $address->getId()]);
228  return '<a href="' . $this->escapeUrl($url) . '">' . $this->escapeHtml($label) . '</a>';
229  }
230 
231  return '';
232  }
233 
239  public function shouldDisplayCustomerIp()
240  {
241  return !$this->_scopeConfig->isSetFlag(
242  'sales/general/hide_customer_ip',
243  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
244  $this->getOrder()->getStoreId()
245  );
246  }
247 
253  public function isSingleStoreMode()
254  {
255  return $this->_storeManager->isSingleStoreMode();
256  }
257 
265  public function getCreatedAtStoreDate($store, $createdAt)
266  {
267  return $this->_localeDate->scopeDate($store, $createdAt, true);
268  }
269 
276  public function getTimezoneForStore($store)
277  {
278  return $this->_localeDate->getConfigTimezone(
279  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
280  $store->getCode()
281  );
282  }
283 
290  public function getOrderAdminDate($createdAt)
291  {
292  return $this->_localeDate->date(new \DateTime($createdAt));
293  }
294 
302  {
303  return $this->addressRenderer->format($address, 'html');
304  }
305 
310  public function getChildHtml($alias = '', $useCache = true)
311  {
312  $layout = $this->getLayout();
313 
314  if ($alias || !$layout) {
315  return parent::getChildHtml($alias, $useCache);
316  }
317 
318  $childNames = $layout->getChildNames($this->getNameInLayout());
319  $outputChildNames = array_diff($childNames, ['extra_customer_info']);
320 
321  $out = '';
322  foreach ($outputChildNames as $childName) {
323  $out .= $layout->renderElement($childName, $useCache);
324  }
325 
326  return $out;
327  }
328 }
getCreatedAtStoreDate($store, $createdAt)
Definition: Info.php:265
_prepareAccountDataSortOrder(array $data, $sortOrder)
Definition: Info.php:171
__()
Definition: __.php:13
$address
Definition: customer.php:38
$label
Definition: details.phtml:21
$value
Definition: gender.phtml:16
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Framework\Registry $registry, \Magento\Sales\Helper\Admin $adminHelper, \Magento\Customer\Api\GroupRepositoryInterface $groupRepository, \Magento\Customer\Api\CustomerMetadataInterface $metadata, \Magento\Customer\Model\Metadata\ElementFactory $elementFactory, \Magento\Sales\Model\Order\Address\Renderer $addressRenderer, array $data=[])
Definition: Info.php:57
getChildHtml($alias='', $useCache=true)
Definition: Info.php:310
getAddressEditLink($address, $label='')
Definition: Info.php:221
if(!trim($html)) $alias
Definition: details.phtml:20
setDataUsingMethod($key, $args=[])
Definition: DataObject.php:204
if(!isset($_GET['name'])) $name
Definition: log.php:14