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 1818
1919use Magento \Framework \Api \SearchCriteriaBuilder ;
2020use Magento \Framework \Exception \LocalizedException ;
21+ use Magento \Framework \ObjectManager \ResetAfterRequestInterface ;
2122use Magento \Quote \Api \Data \CartInterface ;
2223use Magento \Quote \Model \Quote ;
2324use Magento \SalesRule \Api \CouponRepositoryInterface ;
2425use Magento \SalesRule \Api \Data \CouponInterface ;
2526use Magento \SalesRule \Api \Data \RuleDiscountInterface ;
2627
27- class GetDiscounts
28+ class GetDiscounts implements ResetAfterRequestInterface
2829{
30+ private array $ couponsByCode = [];
31+
2932 /**
3033 * @param CouponRepositoryInterface $couponRepository
3134 * @param SearchCriteriaBuilder $criteriaBuilder
@@ -96,12 +99,24 @@ private function getCoupon(CartInterface $quote): ?CouponInterface
9699 if (!$ couponCode ) {
97100 return null ;
98101 }
102+ if (isset ($ this ->couponsByCode [$ couponCode ])) {
103+ return $ this ->couponsByCode [$ couponCode ];
104+ }
99105 $ couponModels = $ this ->couponRepository ->getList (
100106 $ this ->criteriaBuilder ->addFilter ('code ' , $ couponCode )->create ()
101107 )->getItems ();
102108 if (empty ($ couponModels )) {
103109 return null ;
104110 }
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 = [];
106121 }
107122}
You can’t perform that action at this time.
0 commit comments