Exemple #1
0
 /**
  * Submit the order
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  */
 public function executeInternal()
 {
     try {
         if (!$this->agreementsValidator->isValid(array_keys($this->getRequest()->getPost('agreement', [])))) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Please agree to all the terms and conditions before placing the order.'));
         }
         $this->initCheckout();
         $this->getCheckout()->place(null);
         // prepare session to success or cancellation page
         $this->checkoutSession->clearHelperData();
         // "last successful quote"
         $quoteId = $this->getQuote()->getId();
         $this->checkoutSession->setLastQuoteId($quoteId)->setLastSuccessQuoteId($quoteId);
         // an order may be created
         $order = $this->getCheckout()->getOrder();
         if ($order) {
             $this->checkoutSession->setLastOrderId($order->getId())->setLastRealOrderId($order->getIncrementId());
         }
         /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
         return $resultRedirect->setPath('checkout/onepage/success');
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->messageManager->addExceptionMessage($e, $e->getMessage());
     } catch (\Exception $e) {
         $this->messageManager->addExceptionMessage($e, __('We can\'t place the order.'));
     }
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
     return $resultRedirect->setPath('checkout/cart');
 }
Exemple #2
0
 /**
  * @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod
  * @throws \Magento\Framework\Exception\CouldNotSaveException
  * @return void
  */
 protected function validateAgreements(\Magento\Quote\Api\Data\PaymentInterface $paymentMethod)
 {
     $agreements = $paymentMethod->getExtensionAttributes() === null ? [] : $paymentMethod->getExtensionAttributes()->getAgreementIds();
     if (!$this->agreementsValidator->isValid($agreements)) {
         throw new \Magento\Framework\Exception\CouldNotSaveException(__('Please agree to all the terms and conditions before placing the order.'));
     }
 }
Exemple #3
0
 /**
  * Overview action
  *
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function executeInternal()
 {
     if (!$this->formKeyValidator->validate($this->getRequest())) {
         $this->_forward('backToAddresses');
         return;
     }
     if (!$this->_validateMinimumAmount()) {
         return;
     }
     try {
         if (!$this->agreementsValidator->isValid(array_keys($this->getRequest()->getPost('agreement', [])))) {
             $this->messageManager->addError(__('Please agree to all Terms and Conditions before placing the order.'));
             $this->_redirect('*/*/billing');
             return;
         }
         $payment = $this->getRequest()->getPost('payment');
         $paymentInstance = $this->_getCheckout()->getQuote()->getPayment();
         if (isset($payment['cc_number'])) {
             $paymentInstance->setCcNumber($payment['cc_number']);
         }
         if (isset($payment['cc_cid'])) {
             $paymentInstance->setCcCid($payment['cc_cid']);
         }
         $this->_getCheckout()->createOrders();
         $this->_getState()->setActiveStep(State::STEP_SUCCESS);
         $this->_getState()->setCompleteStep(State::STEP_OVERVIEW);
         $this->_getCheckout()->getCheckoutSession()->clearQuote();
         $this->_getCheckout()->getCheckoutSession()->setDisplaySuccess(true);
         $this->_redirect('*/*/success');
     } catch (PaymentException $e) {
         $message = $e->getMessage();
         if (!empty($message)) {
             $this->messageManager->addError($message);
         }
         $this->_redirect('*/*/billing');
     } catch (\Magento\Checkout\Exception $e) {
         $this->_objectManager->get('Magento\\Checkout\\Helper\\Data')->sendPaymentFailedEmail($this->_getCheckout()->getQuote(), $e->getMessage(), 'multi-shipping');
         $this->_getCheckout()->getCheckoutSession()->clearQuote();
         $this->messageManager->addError($e->getMessage());
         $this->_redirect('*/cart');
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->_objectManager->get('Magento\\Checkout\\Helper\\Data')->sendPaymentFailedEmail($this->_getCheckout()->getQuote(), $e->getMessage(), 'multi-shipping');
         $this->messageManager->addError($e->getMessage());
         $this->_redirect('*/*/billing');
     } catch (\Exception $e) {
         $this->logger->critical($e);
         try {
             $this->_objectManager->get('Magento\\Checkout\\Helper\\Data')->sendPaymentFailedEmail($this->_getCheckout()->getQuote(), $e->getMessage(), 'multi-shipping');
         } catch (\Exception $e) {
             $this->logger->error($e->getMessage());
         }
         $this->messageManager->addError(__('Order place error'));
         $this->_redirect('*/*/billing');
     }
 }
 /**
  * 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());
 }
 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);
 }
Exemple #6
0
 /**
  * Submit the order
  *
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function executeInternal()
 {
     try {
         if ($this->isValidationRequired() && !$this->agreementsValidator->isValid(array_keys($this->getRequest()->getPost('agreement', [])))) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Please agree to all the terms and conditions before placing the order.'));
         }
         $this->_initCheckout();
         $this->_checkout->place($this->_initToken());
         // prepare session to success or cancellation page
         $this->_getCheckoutSession()->clearHelperData();
         // "last successful quote"
         $quoteId = $this->_getQuote()->getId();
         $this->_getCheckoutSession()->setLastQuoteId($quoteId)->setLastSuccessQuoteId($quoteId);
         // an order may be created
         $order = $this->_checkout->getOrder();
         if ($order) {
             $this->_getCheckoutSession()->setLastOrderId($order->getId())->setLastRealOrderId($order->getIncrementId())->setLastOrderStatus($order->getStatus());
         }
         $this->_eventManager->dispatch('paypal_express_place_order_success', ['order' => $order, 'quote' => $this->_getQuote()]);
         // redirect if PayPal specified some URL (for example, to Giropay bank)
         $url = $this->_checkout->getRedirectUrl();
         if ($url) {
             $this->getResponse()->setRedirect($url);
             return;
         }
         $this->_initToken(false);
         // no need in token anymore
         $this->_redirect('checkout/onepage/success');
         return;
     } catch (ApiProcessableException $e) {
         $this->_processPaypalApiError($e);
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->messageManager->addExceptionMessage($e, $e->getMessage());
         $this->_redirect('*/*/review');
     } catch (\Exception $e) {
         $this->messageManager->addExceptionMessage($e, __('We can\'t place the order.'));
         $this->_redirect('*/*/review');
     }
 }
 /**
  * @param int[] $agreements
  * @throws \Magento\Framework\Exception\CouldNotSaveException
  * @return void
  */
 protected function validateAgreements($agreements)
 {
     if (!$this->agreementsValidator->isValid($agreements)) {
         throw new \Magento\Framework\Exception\CouldNotSaveException(__('Please agree to all the terms and conditions before placing the order.'));
     }
 }