コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function set($cartId, \Magento\Quote\Api\Data\PaymentInterface $method)
 {
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->quoteRepository->get($cartId);
     $method->setChecks([\Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_CHECKOUT, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_COUNTRY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_CURRENCY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX]);
     $payment = $quote->getPayment();
     $payment->importData($method->getData());
     if ($quote->isVirtual()) {
         // check if billing address is set
         if ($quote->getBillingAddress()->getCountryId() === null) {
             throw new InvalidTransitionException(__('Billing address is not set'));
         }
         $quote->getBillingAddress()->setPaymentMethod($payment->getMethod());
     } else {
         // check if shipping address is set
         if ($quote->getShippingAddress()->getCountryId() === null) {
             throw new InvalidTransitionException(__('Shipping address is not set'));
         }
         $quote->getShippingAddress()->setPaymentMethod($payment->getMethod());
     }
     if (!$quote->isVirtual() && $quote->getShippingAddress()) {
         $quote->getShippingAddress()->setCollectShippingRates(true);
     }
     if (!$this->zeroTotalValidator->isApplicable($payment->getMethodInstance(), $quote)) {
         throw new InvalidTransitionException(__('The requested Payment Method is not available.'));
     }
     $quote->setTotalsCollectedFlag(false)->collectTotals()->save();
     return $quote->getPayment()->getId();
 }
コード例 #2
0
ファイル: QuoteManagement.php プロジェクト: nja78/magento2
 /**
  * {@inheritdoc}
  */
 public function placeOrder($cartId, $agreements = null, PaymentInterface $paymentMethod = null)
 {
     $quote = $this->quoteRepository->getActive($cartId);
     if ($paymentMethod) {
         $paymentMethod->setChecks([\Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_CHECKOUT, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_COUNTRY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_CURRENCY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX, \Magento\Payment\Model\Method\AbstractMethod::CHECK_ZERO_TOTAL]);
         $quote->getPayment()->setQuote($quote);
         $data = $paymentMethod->getData();
         if (isset($data['additional_data'])) {
             $data = array_merge($data, (array) $data['additional_data']);
             unset($data['additional_data']);
         }
         $quote->getPayment()->importData($data);
     }
     if ($quote->getCheckoutMethod() === self::METHOD_GUEST) {
         $quote->setCustomerId(null);
         $quote->setCustomerEmail($quote->getBillingAddress()->getEmail());
         $quote->setCustomerIsGuest(true);
         $quote->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID);
     }
     $order = $this->submit($quote);
     $this->checkoutSession->setLastQuoteId($quote->getId());
     $this->checkoutSession->setLastSuccessQuoteId($quote->getId());
     $this->checkoutSession->setLastOrderId($order->getId());
     $this->checkoutSession->setLastRealOrderId($order->getIncrementId());
     $this->checkoutSession->setLastOrderStatus($order->getStatus());
     $this->eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]);
     return $order->getId();
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function placeOrder($cartId, PaymentInterface $paymentMethod = null)
 {
     $quote = $this->quoteRepository->getActive($cartId);
     if ($paymentMethod) {
         $paymentMethod->setChecks([\Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_CHECKOUT, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_COUNTRY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_CURRENCY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX, \Magento\Payment\Model\Method\AbstractMethod::CHECK_ZERO_TOTAL]);
         $quote->getPayment()->setQuote($quote);
         $data = $paymentMethod->getData();
         $quote->getPayment()->importData($data);
     }
     if ($quote->getCheckoutMethod() === self::METHOD_GUEST) {
         $quote->setCustomerId(null);
         $quote->setCustomerEmail($quote->getBillingAddress()->getEmail());
         $quote->setCustomerIsGuest(true);
         $quote->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID);
     }
     $this->eventManager->dispatch('checkout_submit_before', ['quote' => $quote]);
     $order = $this->submit($quote);
     if (null == $order) {
         throw new LocalizedException(__('Unable to place order. Please try again later.'));
     }
     $this->checkoutSession->setLastQuoteId($quote->getId());
     $this->checkoutSession->setLastSuccessQuoteId($quote->getId());
     $this->checkoutSession->setLastOrderId($order->getId());
     $this->checkoutSession->setLastRealOrderId($order->getIncrementId());
     $this->checkoutSession->setLastOrderStatus($order->getStatus());
     $this->eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]);
     return $order->getId();
 }