GuestCartRepository.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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\Quote\Api\GuestCartRepositoryInterface;
  8. use Magento\Quote\Model\QuoteIdMask;
  9. use Magento\Quote\Api\CartRepositoryInterface;
  10. use Magento\Quote\Model\QuoteIdMaskFactory;
  11. /**
  12. * Cart Repository class for guest carts.
  13. */
  14. class GuestCartRepository implements GuestCartRepositoryInterface
  15. {
  16. /**
  17. * @var QuoteIdMaskFactory
  18. */
  19. protected $quoteIdMaskFactory;
  20. /**
  21. * @var CartRepositoryInterface
  22. */
  23. protected $quoteRepository;
  24. /**
  25. * Initialize dependencies.
  26. *
  27. * @param CartRepositoryInterface $quoteRepository
  28. * @param QuoteIdMaskFactory $quoteIdMaskFactory
  29. */
  30. public function __construct(
  31. CartRepositoryInterface $quoteRepository,
  32. QuoteIdMaskFactory $quoteIdMaskFactory
  33. ) {
  34. $this->quoteIdMaskFactory = $quoteIdMaskFactory;
  35. $this->quoteRepository = $quoteRepository;
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function get($cartId)
  41. {
  42. /** @var $quoteIdMask QuoteIdMask */
  43. $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
  44. return $this->quoteRepository->get($quoteIdMask->getQuoteId());
  45. }
  46. }