Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function order($cartId)
 {
     $quote = $this->quoteRepository->get($cartId);
     /** @var \Magento\Sales\Model\Service\Quote $quoteService */
     $quoteService = $this->quoteServiceFactory->create(['quote' => $quote]);
     $order = $quoteService->submitOrderWithDataObject();
     return $order->getId();
 }
Esempio n. 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
  */
 public function place($token, $shippingMethodCode = null)
 {
     if ($shippingMethodCode) {
         $this->updateShippingMethod($shippingMethodCode);
     }
     $isNewCustomer = false;
     switch ($this->getCheckoutMethod()) {
         case \Magento\Checkout\Model\Type\Onepage::METHOD_GUEST:
             $this->_prepareGuestQuote();
             break;
         case \Magento\Checkout\Model\Type\Onepage::METHOD_REGISTER:
             $this->_prepareNewCustomerQuote();
             $isNewCustomer = true;
             break;
         default:
             $this->_prepareCustomerQuote();
             break;
     }
     $this->_ignoreAddressValidation();
     $this->_quote->collectTotals();
     $parameters = array('quote' => $this->_quote);
     $service = $this->_serviceQuoteFactory->create($parameters);
     $service->submitAllWithDataObject();
     $this->_quote->save();
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (\Exception $e) {
             $this->_logger->logException($e);
         }
     }
     $order = $service->getOrder();
     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);
             break;
         default:
             break;
     }
     $this->_order = $order;
 }
Esempio n. 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;
     }
     /** @var \Magento\Sales\Model\Service\Quote $quoteService */
     $quoteService = $this->_serviceQuoteFactory->create(array('quote' => $this->getQuote()));
     $quoteService->submitAllWithDataObject();
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (\Exception $e) {
             $this->_logger->logException($e);
         }
     }
     $this->_checkoutSession->setLastQuoteId($this->getQuote()->getId())->setLastSuccessQuoteId($this->getQuote()->getId())->clearHelperData();
     $order = $quoteService->getOrder();
     if ($order) {
         $this->_eventManager->dispatch('checkout_type_onepage_save_order_after', array('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 {
                 $order->sendNewOrderEmail();
             } catch (\Exception $e) {
                 $this->_logger->logException($e);
             }
         }
         // add order information to the session
         $this->_checkoutSession->setLastOrderId($order->getId())->setRedirectUrl($redirectUrl)->setLastRealOrderId($order->getIncrementId());
     }
     $this->_eventManager->dispatch('checkout_submit_all_after', array('order' => $order, 'quote' => $this->getQuote()));
     return $this;
 }