/** * Create orders per each quote address * * @return \Magento\Multishipping\Model\Checkout\Type\Multishipping * @throws \Exception */ public function createOrders() { $orderIds = []; $this->_validate(); $shippingAddresses = $this->getQuote()->getAllShippingAddresses(); $orders = []; if ($this->getQuote()->hasVirtualItems()) { $shippingAddresses[] = $this->getQuote()->getBillingAddress(); } try { foreach ($shippingAddresses as $address) { $order = $this->_prepareOrder($address); $orders[] = $order; $this->_eventManager->dispatch('checkout_type_multishipping_create_orders_single', ['order' => $order, 'address' => $address, 'quote' => $this->getQuote()]); } foreach ($orders as $order) { $order->place(); $order->save(); if ($order->getCanSendNewEmailFlag()) { $this->orderSender->send($order); } $orderIds[$order->getId()] = $order->getIncrementId(); } $this->_session->setOrderIds($orderIds); $this->_checkoutSession->setLastQuoteId($this->getQuote()->getId()); $this->getQuote()->setIsActive(false); $this->quoteRepository->save($this->getQuote()); $this->_eventManager->dispatch('checkout_submit_all_after', ['orders' => $orders, 'quote' => $this->getQuote()]); return $this; } catch (\Exception $e) { $this->_eventManager->dispatch('checkout_multishipping_refund_all', ['orders' => $orders]); throw $e; } }