CartCollectionPointManagement.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Model\CollectionPoint;
  6. use Magento\Framework\EntityManager\HydratorInterface;
  7. use Magento\Framework\Exception\CouldNotDeleteException;
  8. use Magento\Framework\Exception\CouldNotSaveException;
  9. use Temando\Shipping\Api\CollectionPoint\CartCollectionPointManagementInterface as LegacyManagementInterface;
  10. use Temando\Shipping\Api\Data\CollectionPoint\QuoteCollectionPointInterfaceFactory as LegacyCollectionPointFactory;
  11. use Temando\Shipping\Api\Data\CollectionPoint\SearchRequestInterfaceFactory as LegacySearchRequestFactory;
  12. use Temando\Shipping\Api\Delivery\CartCollectionPointManagementInterface;
  13. /**
  14. * Manage Collection Point Searches
  15. *
  16. * @deprecated since 1.4.0
  17. * @see \Temando\Shipping\Model\Delivery\CartCollectionPointManagement
  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 CartCollectionPointManagement implements LegacyManagementInterface
  26. {
  27. /**
  28. * @var HydratorInterface
  29. */
  30. private $hydrator;
  31. /**
  32. * @var LegacySearchRequestFactory
  33. */
  34. private $searchRequestFactory;
  35. /**
  36. * @var LegacyCollectionPointFactory
  37. */
  38. private $collectionPointFactory;
  39. /**
  40. * @var CartCollectionPointManagementInterface
  41. */
  42. private $collectionPointManagement;
  43. /**
  44. * CartCollectionPointManagement constructor.
  45. *
  46. * @param HydratorInterface $hydrator
  47. * @param LegacySearchRequestFactory $searchRequestFactory
  48. * @param LegacyCollectionPointFactory $collectionPointFactory
  49. * @param CartCollectionPointManagementInterface $collectionPointManagement
  50. */
  51. public function __construct(
  52. HydratorInterface $hydrator,
  53. LegacySearchRequestFactory $searchRequestFactory,
  54. LegacyCollectionPointFactory $collectionPointFactory,
  55. CartCollectionPointManagementInterface $collectionPointManagement
  56. ) {
  57. $this->hydrator = $hydrator;
  58. $this->searchRequestFactory = $searchRequestFactory;
  59. $this->collectionPointFactory = $collectionPointFactory;
  60. $this->collectionPointManagement = $collectionPointManagement;
  61. }
  62. /**
  63. * @param int $cartId
  64. * @param string $countryId
  65. * @param string $postcode
  66. * @return \Temando\Shipping\Api\Data\CollectionPoint\SearchRequestInterface
  67. * @throws CouldNotSaveException
  68. */
  69. public function saveSearchRequest($cartId, $countryId, $postcode)
  70. {
  71. $legacySearchRequest = $this->searchRequestFactory->create();
  72. $searchRequest = $this->collectionPointManagement->saveSearchRequest($cartId, $countryId, $postcode);
  73. $searchRequestData = $this->hydrator->extract($searchRequest);
  74. $this->hydrator->hydrate($legacySearchRequest, $searchRequestData);
  75. return $legacySearchRequest;
  76. }
  77. /**
  78. * @param int $cartId
  79. * @return bool
  80. * @throws CouldNotDeleteException
  81. */
  82. public function deleteSearchRequest($cartId)
  83. {
  84. return $this->collectionPointManagement->deleteSearchRequest($cartId);
  85. }
  86. /**
  87. * @param int $cartId
  88. * @return \Temando\Shipping\Api\Data\CollectionPoint\QuoteCollectionPointInterface[]
  89. */
  90. public function getCollectionPoints($cartId)
  91. {
  92. $legacyCollectionPoints = [];
  93. $collectionPoints = $this->collectionPointManagement->getCollectionPoints($cartId);
  94. foreach ($collectionPoints as $collectionPoint) {
  95. $legacyCollectionPoint = $this->collectionPointFactory->create();
  96. $collectionPointData = $this->hydrator->extract($collectionPoint);
  97. $this->hydrator->hydrate($legacyCollectionPoint, $collectionPointData);
  98. $legacyCollectionPoints[]= $legacyCollectionPoint;
  99. }
  100. return $legacyCollectionPoints;
  101. }
  102. /**
  103. * @param int $cartId
  104. * @param int $entityId
  105. * @return bool
  106. * @throws CouldNotSaveException
  107. */
  108. public function selectCollectionPoint($cartId, $entityId)
  109. {
  110. return $this->collectionPointManagement->selectCollectionPoint($cartId, $entityId);
  111. }
  112. }