File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed
app/code/Magento/QuoteGraphQl/Model Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change 18
18
19
19
use Magento \Framework \Api \SearchCriteriaBuilder ;
20
20
use Magento \Framework \Exception \LocalizedException ;
21
+ use Magento \Framework \ObjectManager \ResetAfterRequestInterface ;
21
22
use Magento \Quote \Api \Data \CartInterface ;
22
23
use Magento \Quote \Model \Quote ;
23
24
use Magento \SalesRule \Api \CouponRepositoryInterface ;
24
25
use Magento \SalesRule \Api \Data \CouponInterface ;
25
26
use Magento \SalesRule \Api \Data \RuleDiscountInterface ;
26
27
27
- class GetDiscounts
28
+ class GetDiscounts implements ResetAfterRequestInterface
28
29
{
30
+ private array $ couponsByCode = [];
31
+
29
32
/**
30
33
* @param CouponRepositoryInterface $couponRepository
31
34
* @param SearchCriteriaBuilder $criteriaBuilder
@@ -96,12 +99,24 @@ private function getCoupon(CartInterface $quote): ?CouponInterface
96
99
if (!$ couponCode ) {
97
100
return null ;
98
101
}
102
+ if (isset ($ this ->couponsByCode [$ couponCode ])) {
103
+ return $ this ->couponsByCode [$ couponCode ];
104
+ }
99
105
$ couponModels = $ this ->couponRepository ->getList (
100
106
$ this ->criteriaBuilder ->addFilter ('code ' , $ couponCode )->create ()
101
107
)->getItems ();
102
108
if (empty ($ couponModels )) {
103
109
return null ;
104
110
}
105
- return reset ($ couponModels );
111
+ $ this ->couponsByCode [$ couponCode ] = reset ($ couponModels );
112
+ return $ this ->couponsByCode [$ couponCode ];
113
+ }
114
+
115
+ /**
116
+ * @inheritdoc
117
+ */
118
+ public function _resetState (): void
119
+ {
120
+ $ this ->couponsByCode = [];
106
121
}
107
122
}
You can’t perform that action at this time.
0 commit comments