/** * 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; }
/** * 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; }
/** * {@inheritDoc} */ public function get($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); return $this->shippingMethodManagement->get($quoteIdMask->getQuoteId()); }