Exemple #1
0
 /**
  * Execute request
  *
  * @throws AlreadyExistsException
  * @throws NoSuchEntityException
  * @throws \Exception
  * @return void
  */
 public function executeInternal()
 {
     if ($this->customerSession->isLoggedIn()) {
         $this->messageManager->addError(__("Customer is already registered"));
         return;
     }
     $orderId = $this->checkoutSession->getLastOrderId();
     if (!$orderId) {
         $this->messageManager->addError(__("Your session has expired"));
         return;
     }
     try {
         $this->orderCustomerService->create($orderId);
     } catch (\Exception $e) {
         $this->messageManager->addException($e, $e->getMessage());
         throw $e;
     }
 }
Exemple #2
0
 /**
  * Execute request
  *
  * @throws AlreadyExistsException
  * @throws NoSuchEntityException
  * @throws \Exception
  * @return \Magento\Framework\Controller\Result\Json
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->_objectManager->get(\Magento\Framework\Controller\Result\JsonFactory::class)->create();
     if ($this->customerSession->isLoggedIn()) {
         return $resultJson->setData(['errors' => true, 'message' => __('Customer is already registered')]);
     }
     $orderId = $this->checkoutSession->getLastOrderId();
     if (!$orderId) {
         return $resultJson->setData(['errors' => true, 'message' => __('Your session has expired')]);
     }
     try {
         $this->orderCustomerService->create($orderId);
         return $resultJson->setData(['errors' => false, 'message' => __('A letter with further instructions will be sent to your email.')]);
     } catch (\Exception $e) {
         $this->messageManager->addException($e, $e->getMessage());
         throw $e;
     }
 }
 /**
  * @param \Magento\Framework\Event\Observer $observer
  * @throws \Exception
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $orderIds = $observer->getEvent()->getData('order_ids');
     if (isset($orderIds[0])) {
         $order = $this->orderRepository->get($orderIds[0]);
         if (!$order->getCustomerId()) {
             $isEmailAvailable = $this->accountManagement->isEmailAvailable($order->getCustomerEmail());
             //$this->logger->addInfo(print_r($isEmailAvailable,true));
             if ($isEmailAvailable) {
                 try {
                     $this->orderCustomerService->create($orderIds[0]);
                 } catch (\Exception $e) {
                     $this->messageManager->addException($e, $e->getMessage());
                     throw $e;
                 }
                 $this->coreRegistry->register('automatic_account', true);
             }
         }
     }
 }