GuestCartPickupLocationManagement.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Model\Checkout\Delivery;
  6. use Magento\Framework\Exception\CouldNotSaveException;
  7. use Magento\Framework\Exception\NoSuchEntityException;
  8. use Magento\Quote\Model\GuestCart\GuestShippingAddressManagementInterface;
  9. use Temando\Shipping\Api\Data\Delivery\QuotePickupLocationInterface;
  10. use Temando\Shipping\Api\Checkout\GuestCartPickupLocationManagementInterface;
  11. /**
  12. * Manage Pickup Location Searches
  13. *
  14. * @package Temando\Shipping\Model
  15. * @author Sebastian Ertner <sebastian.ertner@netresearch.de>
  16. * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  17. * @link https://www.temando.com/
  18. */
  19. class GuestCartPickupLocationManagement implements GuestCartPickupLocationManagementInterface
  20. {
  21. /**
  22. * @var GuestShippingAddressManagementInterface
  23. */
  24. private $addressManagement;
  25. /**
  26. * @var PickupLocationManagement
  27. */
  28. private $pickupLocationManagement;
  29. /**
  30. * GuestCartPickupLocationManagement constructor.
  31. *
  32. * @param GuestShippingAddressManagementInterface $addressManagement
  33. * @param PickupLocationManagement $pickupLocationManagement
  34. */
  35. public function __construct(
  36. GuestShippingAddressManagementInterface $addressManagement,
  37. PickupLocationManagement $pickupLocationManagement
  38. ) {
  39. $this->addressManagement = $addressManagement;
  40. $this->pickupLocationManagement = $pickupLocationManagement;
  41. }
  42. /**
  43. * Retrieve pickup locations matching the customer's search parameters.
  44. *
  45. * @param string $cartId
  46. * @return QuotePickupLocationInterface[]
  47. * @throws NoSuchEntityException
  48. */
  49. public function getPickupLocations(string $cartId): array
  50. {
  51. $shippingAddress = $this->addressManagement->get($cartId);
  52. return $this->pickupLocationManagement->getPickupLocations($shippingAddress->getId());
  53. }
  54. /**
  55. * Select a given pickup location for checkout.
  56. *
  57. * @param string $cartId
  58. * @param string $pickupLocationId
  59. * @return bool
  60. * @throws NoSuchEntityException
  61. * @throws CouldNotSaveException
  62. */
  63. public function selectPickupLocation(string $cartId, string $pickupLocationId): bool
  64. {
  65. $shippingAddress = $this->addressManagement->get($cartId);
  66. return $this->pickupLocationManagement->selectPickupLocation($shippingAddress->getId(), $pickupLocationId);
  67. }
  68. }