CartCollectionPointManagement.php 3.6 KB

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