Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Results.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
19 
26 class Results extends Success
27 {
31  private $addressConfig;
32 
36  private $orderRepository;
37 
41  private $session;
42 
51  public function __construct(
52  Context $context,
53  Multishipping $multishipping,
54  AddressConfig $addressConfig,
55  OrderRepositoryInterface $orderRepository,
56  SessionManagerInterface $session,
57  array $data = []
58  ) {
59  parent::__construct($context, $multishipping, $data);
60 
61  $this->addressConfig = $addressConfig;
62  $this->orderRepository = $orderRepository;
63  $this->session = $session;
64  }
65 
72  public function getQuoteShippingAddresses(): array
73  {
74  return $this->_multishipping->getQuote()->getAllShippingAddresses();
75  }
76 
83  public function getFailedAddresses(): array
84  {
86  if ($this->getAddressError($this->getQuoteBillingAddress())) {
88  }
89  return $addresses;
90  }
91 
99  public function getOrderShippingAddress(int $orderId)
100  {
101  return $this->orderRepository->get($orderId)->getShippingAddress();
102  }
103 
111  {
112  return $this->getCheckout()->getQuote()->getBillingAddress();
113  }
114 
123  {
124  return $this->getAddressOneline($address->getData());
125  }
126 
135  {
136  return $this->getAddressOneline($address->getData());
137  }
138 
146  public function isShippingAddress(QuoteAddress $address): bool
147  {
148  return $address->getAddressType() === QuoteAddress::ADDRESS_TYPE_SHIPPING;
149  }
150 
157  private function getAddressOneline(array $address): string
158  {
159  $renderer = $this->addressConfig->getFormatByCode('oneline')->getRenderer();
160 
161  return $renderer->renderArray($address);
162  }
163 
171  public function getAddressError(QuoteAddress $address): string
172  {
173  $errors = $this->session->getAddressErrors();
174 
175  return $errors[$address->getId()] ?? '';
176  }
177 
185  protected function _prepareLayout(): Success
186  {
188  $pageTitle = $this->getLayout()->getBlock('page.main.title');
189  if ($pageTitle) {
190  $title = $this->getOrderIds() ? $pageTitle->getPartlySuccessTitle() : $pageTitle->getFailedTitle();
191  $pageTitle->setPageTitle($title);
192  }
193 
194  return parent::_prepareLayout();
195  }
196 }
$title
Definition: default.phtml:14
$orderRepository
Definition: order.php:69
$addresses
Definition: address_list.php:7
formatOrderShippingAddress(OrderAddress $address)
Definition: Results.php:122
formatQuoteShippingAddress(QuoteAddress $address)
Definition: Results.php:134
$address
Definition: customer.php:38
isShippingAddress(QuoteAddress $address)
Definition: Results.php:146
__construct(Context $context, Multishipping $multishipping, AddressConfig $addressConfig, OrderRepositoryInterface $orderRepository, SessionManagerInterface $session, array $data=[])
Definition: Results.php:51
getAddressError(QuoteAddress $address)
Definition: Results.php:171
$errors
Definition: overview.phtml:9