Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GuestShippingMethodManagement.php
Go to the documentation of this file.
1 <?php
8 
15 use Magento\Quote\Model\QuoteIdMaskFactory;
16 
24 {
28  private $shippingMethodManagement;
29 
33  private $quoteIdMaskFactory;
34 
38  private $shipmentEstimationManagement;
39 
46  public function __construct(
47  ShippingMethodManagementInterface $shippingMethodManagement,
48  QuoteIdMaskFactory $quoteIdMaskFactory
49  ) {
50  $this->shippingMethodManagement = $shippingMethodManagement;
51  $this->quoteIdMaskFactory = $quoteIdMaskFactory;
52  }
53 
57  public function get($cartId)
58  {
60  $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
61  return $this->shippingMethodManagement->get($quoteIdMask->getQuoteId());
62  }
63 
67  public function getList($cartId)
68  {
70  $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
71  return $this->shippingMethodManagement->getList($quoteIdMask->getQuoteId());
72  }
73 
77  public function set($cartId, $carrierCode, $methodCode)
78  {
80  $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
81  return $this->shippingMethodManagement->set($quoteIdMask->getQuoteId(), $carrierCode, $methodCode);
82  }
83 
87  public function estimateByAddress($cartId, \Magento\Quote\Api\Data\EstimateAddressInterface $address)
88  {
90  $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
91  return $this->shippingMethodManagement->estimateByAddress($quoteIdMask->getQuoteId(), $address);
92  }
93 
97  public function estimateByExtendedAddress($cartId, AddressInterface $address)
98  {
100  $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
101 
102  return $this->getShipmentEstimationManagement()
103  ->estimateByExtendedAddress((int) $quoteIdMask->getQuoteId(), $address);
104  }
105 
111  private function getShipmentEstimationManagement()
112  {
113  if ($this->shipmentEstimationManagement === null) {
114  $this->shipmentEstimationManagement = ObjectManager::getInstance()
115  ->get(ShipmentEstimationInterface::class);
116  }
117  return $this->shipmentEstimationManagement;
118  }
119 }
__construct(ShippingMethodManagementInterface $shippingMethodManagement, QuoteIdMaskFactory $quoteIdMaskFactory)
estimateByAddress($cartId, \Magento\Quote\Api\Data\EstimateAddressInterface $address)
$address
Definition: customer.php:38
$cartId
Definition: quote.php:22
estimateByExtendedAddress($cartId, AddressInterface $address)