GuestCartCollectionPointManagement.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Model\Delivery;
  6. use Magento\Framework\Exception\CouldNotDeleteException;
  7. use Magento\Framework\Exception\CouldNotSaveException;
  8. use Magento\Framework\Exception\NoSuchEntityException;
  9. use Magento\Quote\Model\GuestCart\GuestShippingAddressManagementInterface;
  10. use Temando\Shipping\Api\Data\Delivery\CollectionPointSearchRequestInterface;
  11. use Temando\Shipping\Api\Delivery\GuestCartCollectionPointManagementInterface;
  12. use Temando\Shipping\Api\Checkout\GuestCartCollectionPointManagementInterface as CheckoutGuestCartCollectionPointManagement;
  13. /**
  14. * Manage Collection Point Searches
  15. *
  16. * @deprecated since 1.5.1
  17. * @see \Temando\Shipping\Model\Checkout\Delivery\GuestCartCollectionPointManagement
  18. *
  19. * @package Temando\Shipping\Model
  20. * @author Benjamin Heuer <benjamin.heuer@netresearch.de>
  21. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  22. * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  23. * @link https://www.temando.com/
  24. */
  25. class GuestCartCollectionPointManagement implements GuestCartCollectionPointManagementInterface
  26. {
  27. /**
  28. * @var CheckoutGuestCartCollectionPointManagement
  29. */
  30. private $guestCartCollectionPointManagement;
  31. /**
  32. * @var GuestShippingAddressManagementInterface
  33. */
  34. private $addressManagement;
  35. /**
  36. * @var CollectionPointManagement
  37. */
  38. private $collectionPointManagement;
  39. /**
  40. * GuestCartCollectionPointManagement constructor.
  41. *
  42. * @param CheckoutGuestCartCollectionPointManagement $guestCartCollectionPointManagement
  43. * @param GuestShippingAddressManagementInterface $addressManagement
  44. * @param CollectionPointManagement $collectionPointManagement
  45. */
  46. public function __construct(
  47. CheckoutGuestCartCollectionPointManagement $guestCartCollectionPointManagement,
  48. GuestShippingAddressManagementInterface $addressManagement,
  49. CollectionPointManagement $collectionPointManagement
  50. ) {
  51. $this->guestCartCollectionPointManagement = $guestCartCollectionPointManagement;
  52. $this->addressManagement = $addressManagement;
  53. $this->collectionPointManagement = $collectionPointManagement;
  54. }
  55. /**
  56. * @param string $cartId
  57. * @param string $countryId
  58. * @param string $postcode
  59. * @return CollectionPointSearchRequestInterface
  60. * @throws CouldNotSaveException
  61. */
  62. public function saveSearchRequest($cartId, $countryId, $postcode)
  63. {
  64. return $this->guestCartCollectionPointManagement->saveSearchRequest($cartId, $countryId, $postcode);
  65. }
  66. /**
  67. * @param string $cartId
  68. * @return bool
  69. * @throws CouldNotDeleteException
  70. */
  71. public function deleteSearchRequest($cartId)
  72. {
  73. return $this->guestCartCollectionPointManagement->deleteSearchRequest($cartId);
  74. }
  75. /**
  76. * @param string $cartId
  77. * @return \Temando\Shipping\Api\Data\Delivery\QuoteCollectionPointInterface[]
  78. */
  79. public function getCollectionPoints($cartId)
  80. {
  81. return $this->guestCartCollectionPointManagement->getCollectionPoints($cartId);
  82. }
  83. /**
  84. * @param string $cartId
  85. * @param int $entityId
  86. * @return bool
  87. * @throws CouldNotSaveException
  88. */
  89. public function selectCollectionPoint($cartId, $entityId)
  90. {
  91. try {
  92. $shippingAddress = $this->addressManagement->get($cartId);
  93. } catch (NoSuchEntityException $exception) {
  94. throw new CouldNotSaveException(__('Unable to load shipping address for specified quote.'));
  95. }
  96. return $this->collectionPointManagement->selectCollectionPoint($shippingAddress->getId(), $entityId);
  97. }
  98. }