/**
  * {@inheritDoc}
  */
 public function collectTotals($cartId, \Magento\Quote\Api\Data\PaymentInterface $paymentMethod, $shippingCarrierCode = null, $shippingMethodCode = null, \Magento\Quote\Api\Data\TotalsAdditionalDataInterface $additionalData = null)
 {
     if ($shippingCarrierCode && $shippingMethodCode) {
         $this->shippingMethodManagement->set($cartId, $shippingCarrierCode, $shippingMethodCode);
     }
     $this->paymentMethodManagement->set($cartId, $paymentMethod);
     if ($additionalData !== null) {
         $this->dataProcessor->process($additionalData, $cartId);
     }
     return $this->cartTotalsRepository->get($cartId);
 }
Exemplo n.º 2
0
 /**
  * @param \Magento\Quote\Model\Quote $quote
  * @return void
  */
 public function collect(\Magento\Quote\Model\Quote $quote)
 {
     if ($this->customerSession->isLoggedIn()) {
         $customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
         if ($defaultShipping = $customer->getDefaultShipping()) {
             $address = $this->addressRepository->getById($defaultShipping);
             if ($address) {
                 /** @var \Magento\Quote\Api\Data\EstimateAddressInterface $estimatedAddress */
                 $estimatedAddress = $this->estimatedAddressFactory->create();
                 $estimatedAddress->setCountryId($address->getCountryId());
                 $estimatedAddress->setPostcode($address->getPostcode());
                 $estimatedAddress->setRegion((string) $address->getRegion()->getRegion());
                 $estimatedAddress->setRegionId($address->getRegionId());
                 $this->shippingMethodManager->estimateByAddress($quote->getId(), $estimatedAddress);
                 $this->quoteRepository->save($quote);
             }
         }
     }
 }
Exemplo n.º 3
0
 /**
  * @{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;
 }
Exemplo n.º 4
0
 /**
  * Retrieve selected shipping method
  *
  * @return array|null
  */
 private function getSelectedShippingMethod()
 {
     $shippingMethodData = null;
     try {
         $quoteId = $this->checkoutSession->getQuote()->getId();
         $shippingMethod = $this->shippingMethodManager->get($quoteId);
         if ($shippingMethod) {
             $shippingMethodData = $shippingMethod->__toArray();
         }
     } catch (\Exception $exception) {
         $shippingMethodData = null;
     }
     return $shippingMethodData;
 }
Exemplo n.º 5
0
 /**
  * Retrieve selected shipping method
  *
  * @return string
  */
 private function getSelectedShippingMethod()
 {
     // Shipping method ID contains carrier code and shipping method code
     $shippingMethodId = '';
     try {
         $quoteId = $this->checkoutSession->getQuote()->getId();
         $shippingMethod = $this->shippingMethodManager->get($quoteId);
         if ($shippingMethod) {
             $shippingMethodId = $shippingMethod->getCarrierCode() . '_' . $shippingMethod->getMethodCode();
         }
     } catch (\Exception $exception) {
         $shippingMethodId = '';
     }
     return $shippingMethodId;
 }
Exemplo n.º 6
0
 /**
  * {@inheritDoc}
  */
 protected function _beforeToHtml()
 {
     if ($this->_customerSession->isLoggedIn()) {
         $customer = $this->customerRepository->getById($this->_customerSession->getCustomerId());
         if ($defaultShipping = $customer->getDefaultShipping()) {
             $address = $this->addressRepository->getById($defaultShipping);
             if ($address) {
                 /** @var \Magento\Quote\Api\Data\EstimateAddressInterface $estimatedAddress */
                 $estimatedAddress = $this->estimatedAddressFactory->create();
                 $estimatedAddress->setCountryId($address->getCountryId());
                 $estimatedAddress->setPostcode($address->getPostcode());
                 $estimatedAddress->setRegion((string) $address->getRegion()->getRegion());
                 $estimatedAddress->setRegionId($address->getRegionId());
                 $this->shippingMethodManager->estimateByAddress($this->getQuote()->getId(), $estimatedAddress);
                 $this->quoteRepository->save($this->getQuote());
             }
         }
     }
     return parent::_beforeToHtml();
 }
 /**
  * {@inheritDoc}
  */
 public function estimateByAddress($cartId, \Magento\Quote\Api\Data\EstimateAddressInterface $address)
 {
     /** @var $quoteIdMask QuoteIdMask */
     $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
     return $this->shippingMethodManagement->estimateByAddress($quoteIdMask->getQuoteId(), $address);
 }
 /**
  * {@inheritDoc}
  */
 public function set($cartId, $carrierCode, $methodCode)
 {
     /** @var $quoteIdMask QuoteIdMask */
     $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
     return $this->shippingMethodManagement->set($quoteIdMask->getQuoteId(), $carrierCode, $methodCode);
 }