Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Registration.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Checkout\Block;
7 
9 
15 {
19  protected $checkoutSession;
20 
24  protected $customerSession;
25 
29  protected $registration;
30 
34  protected $accountManagement;
35 
39  protected $orderRepository;
40 
44  protected $addressValidator;
45 
57  public function __construct(
58  Template\Context $context,
59  \Magento\Checkout\Model\Session $checkoutSession,
60  \Magento\Customer\Model\Session $customerSession,
61  \Magento\Customer\Model\Registration $registration,
62  \Magento\Customer\Api\AccountManagementInterface $accountManagement,
63  \Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
64  \Magento\Sales\Model\Order\Address\Validator $addressValidator,
65  array $data = []
66  ) {
67  $this->checkoutSession = $checkoutSession;
68  $this->customerSession = $customerSession;
69  $this->registration = $registration;
70  $this->accountManagement = $accountManagement;
71  $this->orderRepository = $orderRepository;
72  $this->addressValidator = $addressValidator;
73  parent::__construct($context, $data);
74  }
75 
82  public function getEmailAddress()
83  {
84  return $this->checkoutSession->getLastRealOrder()->getCustomerEmail();
85  }
86 
93  public function getCreateAccountUrl()
94  {
95  return $this->getUrl('checkout/account/delegateCreate');
96  }
97 
101  public function toHtml()
102  {
103  if ($this->customerSession->isLoggedIn()
104  || !$this->registration->isAllowed()
105  || !$this->accountManagement->isEmailAvailable($this->getEmailAddress())
106  || !$this->validateAddresses()
107  ) {
108  return '';
109  }
110  return parent::toHtml();
111  }
112 
118  protected function validateAddresses()
119  {
120  $order = $this->orderRepository->get($this->checkoutSession->getLastOrderId());
121  $addresses = $order->getAddresses();
122  foreach ($addresses as $address) {
123  $result = $this->addressValidator->validateForCustomer($address);
124  if (is_array($result) && !empty($result)) {
125  return false;
126  }
127  }
128  return true;
129  }
130 }
__construct(Template\Context $context, \Magento\Checkout\Model\Session $checkoutSession, \Magento\Customer\Model\Session $customerSession, \Magento\Customer\Model\Registration $registration, \Magento\Customer\Api\AccountManagementInterface $accountManagement, \Magento\Sales\Api\OrderRepositoryInterface $orderRepository, \Magento\Sales\Model\Order\Address\Validator $addressValidator, array $data=[])
$addresses
Definition: address_list.php:7
$order
Definition: order.php:55
$address
Definition: customer.php:38