18
18
19
19
namespace Magento \SalesRule \Plugin ;
20
20
21
+ use Closure ;
21
22
use Magento \Framework \Exception \NoSuchEntityException ;
22
- use Magento \Quote \Model \QuoteRepository ;
23
23
use Magento \SalesRule \Model \Coupon \Quote \UpdateCouponUsages ;
24
24
use Magento \Multishipping \Model \Checkout \Type \Multishipping \PlaceOrderDefault ;
25
+ use Throwable ;
26
+ use Magento \Quote \Api \CartRepositoryInterface ;
25
27
26
28
/**
27
29
* Increments number of coupon usages before placing order
@@ -32,37 +34,37 @@ class CouponUsagesIncrementMultishipping
32
34
/**
33
35
* @var UpdateCouponUsages
34
36
*/
35
- private $ updateCouponUsages ;
37
+ private UpdateCouponUsages $ updateCouponUsages ;
36
38
37
39
/**
38
- * @var QuoteRepository
40
+ * @var CartRepositoryInterface
39
41
*/
40
- private QuoteRepository $ quoteRepository ;
42
+ private CartRepositoryInterface $ cartRepositoryInterface ;
41
43
42
44
/**
43
45
* @param UpdateCouponUsages $updateCouponUsages
44
- * @param QuoteRepository $quoteRepository
46
+ * @param CartRepositoryInterface $cartRepositoryInterface
45
47
*/
46
- public function __construct (UpdateCouponUsages $ updateCouponUsages , QuoteRepository $ quoteRepository )
48
+ public function __construct (UpdateCouponUsages $ updateCouponUsages , CartRepositoryInterface $ cartRepositoryInterface )
47
49
{
48
50
$ this ->updateCouponUsages = $ updateCouponUsages ;
49
- $ this ->quoteRepository = $ quoteRepository ;
51
+ $ this ->cartRepositoryInterface = $ cartRepositoryInterface ;
50
52
}
51
53
52
54
/**
53
55
* Increments number of coupon usages before placing order
54
56
*
55
57
* @param PlaceOrderDefault $subject
56
- * @param \ Closure $proceed
58
+ * @param Closure $proceed
57
59
* @param array $order
58
- * @return void
59
- * @throws NoSuchEntityException
60
+ * @return array
61
+ * @throws NoSuchEntityException|Throwable
60
62
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
61
63
*/
62
- public function aroundPlace (PlaceOrderDefault $ subject , \ Closure $ proceed , array $ order )
64
+ public function aroundPlace (PlaceOrderDefault $ subject , Closure $ proceed , array $ order ): array
63
65
{
64
66
$ quoteId = $ order [0 ]->getQuoteId ();
65
- $ quote = $ this ->quoteRepository ->get ($ quoteId );
67
+ $ quote = $ this ->cartRepositoryInterface ->get ($ quoteId );
66
68
/* if coupon code has been canceled then need to notify the customer */
67
69
if (!$ quote ->getCouponCode () && $ quote ->dataHasChangedFor ('coupon_code ' )) {
68
70
throw new NoSuchEntityException (__ ("The coupon code isn't valid. Verify the code and try again. " ));
@@ -71,7 +73,7 @@ public function aroundPlace(PlaceOrderDefault $subject, \Closure $proceed, array
71
73
$ this ->updateCouponUsages ->execute ($ quote , true );
72
74
try {
73
75
return $ proceed ($ order );
74
- } catch (\ Throwable $ e ) {
76
+ } catch (Throwable $ e ) {
75
77
$ this ->updateCouponUsages ->execute ($ quote , false );
76
78
throw $ e ;
77
79
}
0 commit comments