checkoutSession = $checkoutSession; $this->customerSession = $customerSession; $this->registration = $registration; $this->accountManagement = $accountManagement; $this->orderRepository = $orderRepository; $this->addressValidator = $addressValidator; parent::__construct($context, $data); } /** * Retrieve current email address * * @return string * @codeCoverageIgnore */ public function getEmailAddress() { return $this->checkoutSession->getLastRealOrder()->getCustomerEmail(); } /** * Retrieve account creation url * * @return string * @codeCoverageIgnore */ public function getCreateAccountUrl() { return $this->getUrl('checkout/account/delegateCreate'); } /** * {@inheritdoc} */ public function toHtml() { if ($this->customerSession->isLoggedIn() || !$this->registration->isAllowed() || !$this->accountManagement->isEmailAvailable($this->getEmailAddress()) || !$this->validateAddresses() ) { return ''; } return parent::toHtml(); } /** * Validate order addresses * * @return bool */ protected function validateAddresses() { $order = $this->orderRepository->get($this->checkoutSession->getLastOrderId()); $addresses = $order->getAddresses(); foreach ($addresses as $address) { $result = $this->addressValidator->validateForCustomer($address); if (is_array($result) && !empty($result)) { return false; } } return true; } }