GuestCartTotalRepository.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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\CartTotalRepositoryInterface;
  8. use Magento\Quote\Api\GuestCartTotalRepositoryInterface;
  9. use Magento\Quote\Model\QuoteIdMask;
  10. use Magento\Quote\Model\QuoteIdMaskFactory;
  11. /**
  12. * Cart totals repository class for guest carts.
  13. */
  14. class GuestCartTotalRepository implements GuestCartTotalRepositoryInterface
  15. {
  16. /**
  17. * @var QuoteIdMaskFactory
  18. */
  19. private $quoteIdMaskFactory;
  20. /**
  21. * @var CartTotalRepositoryInterface
  22. */
  23. private $cartTotalRepository;
  24. /**
  25. * Constructs a cart totals data object.
  26. *
  27. * @param CartTotalRepositoryInterface $cartTotalRepository
  28. * @param QuoteIdMaskFactory $quoteIdMaskFactory
  29. */
  30. public function __construct(
  31. CartTotalRepositoryInterface $cartTotalRepository,
  32. QuoteIdMaskFactory $quoteIdMaskFactory
  33. ) {
  34. $this->cartTotalRepository = $cartTotalRepository;
  35. $this->quoteIdMaskFactory = $quoteIdMaskFactory;
  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->cartTotalRepository->get($quoteIdMask->getQuoteId());
  45. }
  46. }