GuestCouponManagement.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Quote\Model\GuestCart;
  8. use Magento\Quote\Api\GuestCouponManagementInterface;
  9. use Magento\Quote\Api\CouponManagementInterface;
  10. use Magento\Quote\Model\QuoteIdMask;
  11. use Magento\Quote\Model\QuoteIdMaskFactory;
  12. /**
  13. * Coupon management class for guest carts.
  14. */
  15. class GuestCouponManagement implements GuestCouponManagementInterface
  16. {
  17. /**
  18. * @var QuoteIdMaskFactory
  19. */
  20. private $quoteIdMaskFactory;
  21. /**
  22. * @var CouponManagementInterface
  23. */
  24. private $couponManagement;
  25. /**
  26. * Constructs a coupon read service object.
  27. *
  28. * @param CouponManagementInterface $couponManagement
  29. * @param QuoteIdMaskFactory $quoteIdMaskFactory
  30. */
  31. public function __construct(
  32. CouponManagementInterface $couponManagement,
  33. QuoteIdMaskFactory $quoteIdMaskFactory
  34. ) {
  35. $this->quoteIdMaskFactory = $quoteIdMaskFactory;
  36. $this->couponManagement = $couponManagement;
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function get($cartId)
  42. {
  43. /** @var $quoteIdMask QuoteIdMask */
  44. $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
  45. return $this->couponManagement->get($quoteIdMask->getQuoteId());
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function set($cartId, $couponCode)
  51. {
  52. /** @var $quoteIdMask QuoteIdMask */
  53. $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
  54. return $this->couponManagement->set($quoteIdMask->getQuoteId(), $couponCode);
  55. }
  56. /**
  57. * {@inheritdoc}
  58. */
  59. public function remove($cartId)
  60. {
  61. /** @var $quoteIdMask QuoteIdMask */
  62. $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
  63. return $this->couponManagement->remove($quoteIdMask->getQuoteId());
  64. }
  65. }