GuestShippingMethodManagement.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Quote\Model\GuestCart;
  7. use Magento\Framework\App\ObjectManager;
  8. use Magento\Quote\Api\Data\AddressInterface;
  9. use Magento\Quote\Api\GuestShipmentEstimationInterface;
  10. use Magento\Quote\Api\ShipmentEstimationInterface;
  11. use Magento\Quote\Api\ShippingMethodManagementInterface;
  12. use Magento\Quote\Model\QuoteIdMask;
  13. use Magento\Quote\Model\QuoteIdMaskFactory;
  14. /**
  15. * Shipping method management class for guest carts.
  16. */
  17. class GuestShippingMethodManagement implements
  18. \Magento\Quote\Api\GuestShippingMethodManagementInterface,
  19. \Magento\Quote\Model\GuestCart\GuestShippingMethodManagementInterface,
  20. GuestShipmentEstimationInterface
  21. {
  22. /**
  23. * @var ShippingMethodManagementInterface
  24. */
  25. private $shippingMethodManagement;
  26. /**
  27. * @var QuoteIdMaskFactory
  28. */
  29. private $quoteIdMaskFactory;
  30. /**
  31. * @var ShipmentEstimationInterface
  32. */
  33. private $shipmentEstimationManagement;
  34. /**
  35. * Constructs a shipping method read service object.
  36. *
  37. * @param ShippingMethodManagementInterface $shippingMethodManagement
  38. * @param QuoteIdMaskFactory $quoteIdMaskFactory
  39. */
  40. public function __construct(
  41. ShippingMethodManagementInterface $shippingMethodManagement,
  42. QuoteIdMaskFactory $quoteIdMaskFactory
  43. ) {
  44. $this->shippingMethodManagement = $shippingMethodManagement;
  45. $this->quoteIdMaskFactory = $quoteIdMaskFactory;
  46. }
  47. /**
  48. * {@inheritDoc}
  49. */
  50. public function get($cartId)
  51. {
  52. /** @var $quoteIdMask QuoteIdMask */
  53. $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
  54. return $this->shippingMethodManagement->get($quoteIdMask->getQuoteId());
  55. }
  56. /**
  57. * {@inheritDoc}
  58. */
  59. public function getList($cartId)
  60. {
  61. /** @var $quoteIdMask QuoteIdMask */
  62. $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
  63. return $this->shippingMethodManagement->getList($quoteIdMask->getQuoteId());
  64. }
  65. /**
  66. * {@inheritDoc}
  67. */
  68. public function set($cartId, $carrierCode, $methodCode)
  69. {
  70. /** @var $quoteIdMask QuoteIdMask */
  71. $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
  72. return $this->shippingMethodManagement->set($quoteIdMask->getQuoteId(), $carrierCode, $methodCode);
  73. }
  74. /**
  75. * {@inheritDoc}
  76. */
  77. public function estimateByAddress($cartId, \Magento\Quote\Api\Data\EstimateAddressInterface $address)
  78. {
  79. /** @var $quoteIdMask QuoteIdMask */
  80. $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
  81. return $this->shippingMethodManagement->estimateByAddress($quoteIdMask->getQuoteId(), $address);
  82. }
  83. /**
  84. * @inheritdoc
  85. */
  86. public function estimateByExtendedAddress($cartId, AddressInterface $address)
  87. {
  88. /** @var $quoteIdMask QuoteIdMask */
  89. $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
  90. return $this->getShipmentEstimationManagement()
  91. ->estimateByExtendedAddress((int) $quoteIdMask->getQuoteId(), $address);
  92. }
  93. /**
  94. * Get shipment estimation management service
  95. * @return ShipmentEstimationInterface
  96. * @deprecated 100.0.7
  97. */
  98. private function getShipmentEstimationManagement()
  99. {
  100. if ($this->shipmentEstimationManagement === null) {
  101. $this->shipmentEstimationManagement = ObjectManager::getInstance()
  102. ->get(ShipmentEstimationInterface::class);
  103. }
  104. return $this->shipmentEstimationManagement;
  105. }
  106. }