/** * {@inheritDoc} */ public function getPaymentInformation($cartId) { /** @var \Magento\Checkout\Api\Data\PaymentDetailsInterface $paymentDetails */ $paymentDetails = $this->paymentDetailsFactory->create(); $paymentDetails->setPaymentMethods($this->paymentMethodManagement->getList($cartId)); $paymentDetails->setTotals($this->cartTotalsRepository->get($cartId)); return $paymentDetails; }
/** * {@inheritDoc} */ public function saveAddressInformation($cartId, \Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation) { $address = $addressInformation->getShippingAddress(); $billingAddress = $addressInformation->getBillingAddress(); $carrierCode = $addressInformation->getShippingCarrierCode(); $methodCode = $addressInformation->getShippingMethodCode(); if (!$address->getCountryId()) { throw new StateException(__('Shipping address is not set')); } /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->quoteRepository->getActive($cartId); $quote = $this->prepareShippingAssignment($quote, $address, $carrierCode . '_' . $methodCode); $this->validateQuote($quote); $quote->setIsMultiShipping(false); if ($billingAddress) { $quote->setBillingAddress($billingAddress); } try { $this->quoteRepository->save($quote); } catch (\Exception $e) { $this->logger->critical($e); throw new InputException(__('Unable to save shipping information. Please check input data.')); } $shippingAddress = $quote->getShippingAddress(); if (!$shippingAddress->getShippingRateByCode($shippingAddress->getShippingMethod())) { throw new NoSuchEntityException(__('Carrier with such method not found: %1, %2', $carrierCode, $methodCode)); } /** @var \Magento\Checkout\Api\Data\PaymentDetailsInterface $paymentDetails */ $paymentDetails = $this->paymentDetailsFactory->create(); $paymentDetails->setPaymentMethods($this->paymentMethodManagement->getList($cartId)); $paymentDetails->setTotals($this->cartTotalsRepository->get($cartId)); return $paymentDetails; }
/** * {@inheritDoc} * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function saveAddressInformation($cartId, \Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation) { $address = $addressInformation->getShippingAddress(); $carrierCode = $addressInformation->getShippingCarrierCode(); $methodCode = $addressInformation->getShippingMethodCode(); /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->quoteRepository->getActive($cartId); if ($quote->isVirtual()) { throw new NoSuchEntityException(__('Cart contains virtual product(s) only. Shipping address is not applicable.')); } if (0 == $quote->getItemsCount()) { throw new InputException(__('Shipping method is not applicable for empty cart')); } $saveInAddressBook = $address->getSaveInAddressBook() ? 1 : 0; $sameAsBilling = $address->getSameAsBilling() ? 1 : 0; $customerAddressId = $address->getCustomerAddressId(); $this->addressValidator->validate($address); $quote->setShippingAddress($address); $address = $quote->getShippingAddress(); if ($customerAddressId) { $addressData = $this->addressRepository->getById($customerAddressId); $address = $quote->getShippingAddress()->importCustomerAddressData($addressData); } $address->setSameAsBilling($sameAsBilling); $address->setSaveInAddressBook($saveInAddressBook); $address->setCollectShippingRates(true); if (!$address->getCountryId()) { throw new StateException(__('Shipping address is not set')); } $address->setShippingMethod($carrierCode . '_' . $methodCode); try { $address->save(); $address->collectTotals(); } catch (\Exception $e) { $this->logger->critical($e); throw new InputException(__('Unable to save address. Please, check input data.')); } if (!$address->getShippingRateByCode($address->getShippingMethod())) { throw new NoSuchEntityException(__('Carrier with such method not found: %1, %2', $carrierCode, $methodCode)); } if (!$quote->validateMinimumAmount($quote->getIsMultiShipping())) { throw new InputException($this->scopeConfig->getValue('sales/minimum_order/error_message', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $quote->getStoreId())); } try { $address->save(); $quote->collectTotals(); $this->quoteRepository->save($quote); } catch (\Exception $e) { $this->logger->critical($e); throw new InputException(__('Unable to save shipping information. Please, check input data.')); } /** @var \Magento\Checkout\Api\Data\PaymentDetailsInterface $paymentDetails */ $paymentDetails = $this->paymentDetailsFactory->create(); $paymentDetails->setPaymentMethods($this->paymentMethodManagement->getList($cartId)); $paymentDetails->setTotals($this->cartTotalsRepository->get($cartId)); return $paymentDetails; }
/** * @{inheritdoc} */ public function saveAddresses($cartId, \Magento\Quote\Api\Data\AddressInterface $billingAddress, \Magento\Quote\Api\Data\AddressInterface $shippingAddress = null, \Magento\Quote\Api\Data\AddressAdditionalDataInterface $additionalData = null, $checkoutMethod = null) { $this->billingAddressManagement->assign($cartId, $billingAddress); /** @var \Magento\Quote\Api\Data\AddressDetailsInterface $addressDetails */ $addressDetails = $this->addressDetailsFactory->create(); if ($shippingAddress) { $this->shippingAddressManagement->assign($cartId, $shippingAddress); $addressDetails->setFormattedShippingAddress($this->shippingAddressManagement->get($cartId)->format('html')); $addressDetails->setShippingMethods($this->shippingMethodManagement->getList($cartId)); } $addressDetails->setPaymentMethods($this->paymentMethodManagement->getList($cartId)); if ($additionalData !== null) { $this->dataProcessor->process($additionalData); } if ($checkoutMethod != null) { $this->quoteRepository->save($this->quoteRepository->getActive($cartId)->setCheckoutMethod($checkoutMethod)); } $addressDetails->setFormattedBillingAddress($this->billingAddressManagement->get($cartId)->format('html')); $addressDetails->setTotals($this->cartTotalsRepository->get($cartId)); return $addressDetails; }
/** * {@inheritdoc} */ public function getList($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); return $this->paymentMethodManagement->getList($quoteIdMask->getQuoteId()); }
/** * Returns array of payment methods * @return array */ private function getPaymentMethods() { $paymentMethods = []; $quote = $this->checkoutSession->getQuote(); if ($quote->getIsVirtual()) { foreach ($this->paymentMethodManagement->getList($quote->getId()) as $paymentMethod) { $paymentMethods[] = ['code' => $paymentMethod->getCode(), 'title' => $paymentMethod->getTitle()]; } } return $paymentMethods; }