/**
  * {@inheritdoc}
  */
 public function placeOrder($cartId, PaymentInterface $paymentMethod = null)
 {
     /** @var $quoteIdMask QuoteIdMask */
     $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
     $this->cartRepository->get($quoteIdMask->getQuoteId())->setCheckoutMethod(CartManagementInterface::METHOD_GUEST);
     return $this->quoteManagement->placeOrder($quoteIdMask->getQuoteId(), $paymentMethod);
 }
 /**
  * {@inheritDoc}
  */
 public function savePaymentInformationAndPlaceOrder($cartId, \Magento\Quote\Api\Data\PaymentInterface $paymentMethod, \Magento\Quote\Api\Data\AddressInterface $billingAddress = null)
 {
     $this->savePaymentInformation($cartId, $paymentMethod, $billingAddress);
     try {
         $orderId = $this->cartManagement->placeOrder($cartId);
     } catch (\Exception $e) {
         throw new CouldNotSaveException(__('Unable to place order. Please try again later.'), $e);
     }
     return $orderId;
 }
 /**
  * Execute operation
  *
  * @param Quote $quote
  * @param array $agreement
  * @return void
  * @throws LocalizedException
  */
 public function execute(Quote $quote, array $agreement)
 {
     if (!$this->agreementsValidator->isValid($agreement)) {
         throw new LocalizedException(__('Please agree to all the terms and conditions before placing the order.'));
     }
     if ($this->getCheckoutMethod($quote) === Onepage::METHOD_GUEST) {
         $this->prepareGuestQuote($quote);
     }
     $this->disabledQuoteAddressValidation($quote);
     $quote->collectTotals();
     $this->cartManagement->placeOrder($quote->getId());
 }
예제 #4
0
 public function testExecuteGuest()
 {
     $agreement = ['test', 'test'];
     $quoteMock = $this->getQuoteMock();
     $this->agreementsValidatorMock->expects(self::once())->method('isValid')->willReturn(true);
     $this->getCheckoutMethodStep($quoteMock);
     $this->prepareGuestQuoteStep($quoteMock);
     $this->disabledQuoteAddressValidationStep($quoteMock);
     $quoteMock->expects(self::once())->method('collectTotals');
     $quoteMock->expects(self::once())->method('getId')->willReturn(10);
     $this->cartManagementMock->expects(self::once())->method('placeOrder')->with(10);
     $this->orderPlace->execute($quoteMock, $agreement);
 }
 /**
  * {@inheritDoc}
  */
 public function getOverriddenValue()
 {
     try {
         if ($this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER) {
             $customerId = $this->userContext->getUserId();
             /** @var \Magento\Quote\Api\Data\CartInterface */
             $cart = $this->cartManagement->getCartForCustomer($customerId);
             if ($cart) {
                 return $cart->getId();
             }
         }
     } catch (NoSuchEntityException $e) {
         /* do nothing and just return null */
     }
     return null;
 }
예제 #6
0
 /**
  * @param $paymentMethod
  * @param $controller
  * @param $quoteId
  * @param $result
  * @dataProvider textExecuteFailedPlaceOrderDataProvider
  */
 public function testExecuteFailedPlaceOrder($paymentMethod, $controller, $quoteId, $result)
 {
     $this->requestMock->expects($this->at(0))->method('getParam')->with('payment')->will($this->returnValue($paymentMethod));
     $this->requestMock->expects($this->at(1))->method('getParam')->with('controller')->will($this->returnValue($controller));
     $this->quoteMock->expects($this->any())->method('getId')->will($this->returnValue($quoteId));
     $this->cartManagementMock->expects($this->once())->method('placeOrder')->willThrowException(new \Exception());
     $this->jsonHelperMock->expects($this->any())->method('jsonEncode')->with($result);
     $this->placeOrderController->execute();
 }
예제 #7
0
 /**
  * Place order for checkout flow
  *
  * @return string
  */
 protected function placeCheckoutOrder()
 {
     $result = new DataObject();
     $response = $this->getResponse();
     try {
         $this->cartManagement->placeOrder($this->_getCheckout()->getQuote()->getId());
         $result->setData('success', true);
         $this->eventManager->dispatch('checkout_directpost_placeOrder', ['result' => $result, 'action' => $this]);
     } catch (\Exception $exception) {
         $result->setData('error', true);
         $result->setData('error_messages', __('An error occurred on the server. Please try to place the order again.'));
     }
     if ($response instanceof Http) {
         $response->representJson($this->jsonHelper->jsonEncode($result));
     }
 }
예제 #8
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;
 }
예제 #9
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;
 }
 /**
  * {@inheritDoc}
  */
 public function savePaymentInformationAndPlaceOrder($cartId, \Magento\Quote\Api\Data\PaymentInterface $paymentMethod, \Magento\Quote\Api\Data\AddressInterface $billingAddress)
 {
     $this->savePaymentInformation($cartId, $paymentMethod, $billingAddress);
     return $this->cartManagement->placeOrder($cartId);
 }
예제 #11
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;
 }
예제 #12
0
 /**
  * {@inheritdoc}
  */
 public function placeOrderCreatingAccount($cartId, $customer, $password, $agreements = null, PaymentInterface $paymentMethod = null)
 {
     /** @var $quoteIdMask QuoteIdMask */
     $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
     return $this->quoteManagement->placeOrderCreatingAccount($quoteIdMask->getQuoteId(), $customer, $password, $agreements, $paymentMethod);
 }
예제 #13
0
 /**
  * {@inheritdoc}
  */
 public function placeOrder($cartId)
 {
     /** @var $quoteIdMask QuoteIdMask */
     $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
     return $this->quoteManagement->placeOrder($quoteIdMask->getId());
 }