Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GuestCouponManagement.php
Go to the documentation of this file.
1 <?php
8 
12 use Magento\Quote\Model\QuoteIdMaskFactory;
13 
18 {
22  private $quoteIdMaskFactory;
23 
27  private $couponManagement;
28 
35  public function __construct(
36  CouponManagementInterface $couponManagement,
37  QuoteIdMaskFactory $quoteIdMaskFactory
38  ) {
39  $this->quoteIdMaskFactory = $quoteIdMaskFactory;
40  $this->couponManagement = $couponManagement;
41  }
42 
46  public function get($cartId)
47  {
49  $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
50  return $this->couponManagement->get($quoteIdMask->getQuoteId());
51  }
52 
56  public function set($cartId, $couponCode)
57  {
59  $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
60  return $this->couponManagement->set($quoteIdMask->getQuoteId(), $couponCode);
61  }
62 
66  public function remove($cartId)
67  {
69  $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
70  return $this->couponManagement->remove($quoteIdMask->getQuoteId());
71  }
72 }
$cartId
Definition: quote.php:22
__construct(CouponManagementInterface $couponManagement, QuoteIdMaskFactory $quoteIdMaskFactory)