Exemple #1
0
 /**
  * Create new order
  *
  * @return \Magento\Sales\Model\Order
  */
 public function createOrder()
 {
     $this->_prepareCustomer();
     $this->_validate();
     $quote = $this->getQuote();
     $this->_prepareQuoteItems();
     $orderData = [];
     if ($this->getSession()->getOrder()->getId()) {
         $oldOrder = $this->getSession()->getOrder();
         $originalId = $oldOrder->getOriginalIncrementId();
         if (!$originalId) {
             $originalId = $oldOrder->getIncrementId();
         }
         $orderData = ['original_increment_id' => $originalId, 'relation_parent_id' => $oldOrder->getId(), 'relation_parent_real_id' => $oldOrder->getIncrementId(), 'edit_increment' => $oldOrder->getEditIncrement() + 1, 'increment_id' => $originalId . '-' . ($oldOrder->getEditIncrement() + 1)];
         $quote->setReservedOrderId($orderData['increment_id']);
     }
     $order = $this->quoteManagement->submit($quote, $orderData);
     if ($this->getSession()->getOrder()->getId()) {
         $oldOrder = $this->getSession()->getOrder();
         $oldOrder->setRelationChildId($order->getId());
         $oldOrder->setRelationChildRealId($order->getIncrementId());
         $this->orderManagement->cancel($oldOrder->getEntityId());
         $order->save();
     }
     if ($this->getSendConfirmation()) {
         $this->emailSender->send($order);
     }
     $this->_eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]);
     return $order;
 }
Exemple #2
0
 /**
  * Place the order when customer returned from PayPal until this moment all quote data must be valid.
  *
  * @param string $token
  * @param string|null $shippingMethodCode
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function place($token, $shippingMethodCode = null)
 {
     if ($shippingMethodCode) {
         $this->updateShippingMethod($shippingMethodCode);
     }
     if ($this->getCheckoutMethod() == \Magento\Checkout\Model\Type\Onepage::METHOD_GUEST) {
         $this->prepareGuestQuote();
     }
     $this->ignoreAddressValidation();
     $this->_quote->collectTotals();
     $order = $this->quoteManagement->submit($this->_quote);
     if (!$order) {
         return;
     }
     // commence redirecting to finish payment, if paypal requires it
     if ($order->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_REDIRECT)) {
         $this->_redirectUrl = $this->_config->getExpressCheckoutCompleteUrl($token);
     }
     switch ($order->getState()) {
         // even after placement paypal can disallow to authorize/capture, but will wait until bank transfers money
         case \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT:
             // TODO
             break;
             // regular placement, when everything is ok
         // regular placement, when everything is ok
         case \Magento\Sales\Model\Order::STATE_PROCESSING:
         case \Magento\Sales\Model\Order::STATE_COMPLETE:
         case \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW:
             $this->orderSender->send($order);
             $this->_checkoutSession->start();
             break;
         default:
             break;
     }
     $this->_order = $order;
 }
Exemple #3
0
 /**
  * Create order based on checkout type. Create customer if necessary.
  *
  * @return $this
  */
 public function saveOrder()
 {
     $this->validate();
     $isNewCustomer = false;
     switch ($this->getCheckoutMethod()) {
         case self::METHOD_GUEST:
             $this->_prepareGuestQuote();
             break;
         case self::METHOD_REGISTER:
             $this->_prepareNewCustomerQuote();
             $isNewCustomer = true;
             break;
         default:
             $this->_prepareCustomerQuote();
             break;
     }
     $order = $this->quoteManagement->submit($this->getQuote());
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (\Exception $e) {
             $this->_logger->critical($e);
         }
     }
     $this->_checkoutSession->setLastQuoteId($this->getQuote()->getId())->setLastSuccessQuoteId($this->getQuote()->getId())->clearHelperData();
     if ($order) {
         $this->_eventManager->dispatch('checkout_type_onepage_save_order_after', ['order' => $order, 'quote' => $this->getQuote()]);
         /**
          * a flag to set that there will be redirect to third party after confirmation
          */
         $redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();
         /**
          * we only want to send to customer about new order when there is no redirect to third party
          */
         if (!$redirectUrl && $order->getCanSendNewEmailFlag()) {
             try {
                 $this->orderSender->send($order);
             } catch (\Exception $e) {
                 $this->_logger->critical($e);
             }
         }
         // add order information to the session
         $this->_checkoutSession->setLastOrderId($order->getId())->setRedirectUrl($redirectUrl)->setLastRealOrderId($order->getIncrementId())->setLastOrderStatus($order->getStatus());
     }
     $this->_eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $this->getQuote()]);
     return $this;
 }