1818
1919namespace Magento \SalesRule \Plugin ;
2020
21+ use Closure ;
2122use Magento \Framework \Exception \NoSuchEntityException ;
22- use Magento \Quote \Model \QuoteRepository ;
2323use Magento \SalesRule \Model \Coupon \Quote \UpdateCouponUsages ;
2424use Magento \Multishipping \Model \Checkout \Type \Multishipping \PlaceOrderDefault ;
25+ use Throwable ;
26+ use Magento \Quote \Api \CartRepositoryInterface ;
2527
2628/**
2729 * Increments number of coupon usages before placing order
@@ -32,37 +34,37 @@ class CouponUsagesIncrementMultishipping
3234 /**
3335 * @var UpdateCouponUsages
3436 */
35- private $ updateCouponUsages ;
37+ private UpdateCouponUsages $ updateCouponUsages ;
3638
3739 /**
38- * @var QuoteRepository
40+ * @var CartRepositoryInterface
3941 */
40- private QuoteRepository $ quoteRepository ;
42+ private CartRepositoryInterface $ cartRepositoryInterface ;
4143
4244 /**
4345 * @param UpdateCouponUsages $updateCouponUsages
44- * @param QuoteRepository $quoteRepository
46+ * @param CartRepositoryInterface $cartRepositoryInterface
4547 */
46- public function __construct (UpdateCouponUsages $ updateCouponUsages , QuoteRepository $ quoteRepository )
48+ public function __construct (UpdateCouponUsages $ updateCouponUsages , CartRepositoryInterface $ cartRepositoryInterface )
4749 {
4850 $ this ->updateCouponUsages = $ updateCouponUsages ;
49- $ this ->quoteRepository = $ quoteRepository ;
51+ $ this ->cartRepositoryInterface = $ cartRepositoryInterface ;
5052 }
5153
5254 /**
5355 * Increments number of coupon usages before placing order
5456 *
5557 * @param PlaceOrderDefault $subject
56- * @param \ Closure $proceed
58+ * @param Closure $proceed
5759 * @param array $order
58- * @return void
59- * @throws NoSuchEntityException
60+ * @return array
61+ * @throws NoSuchEntityException|Throwable
6062 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
6163 */
62- public function aroundPlace (PlaceOrderDefault $ subject , \ Closure $ proceed , array $ order )
64+ public function aroundPlace (PlaceOrderDefault $ subject , Closure $ proceed , array $ order ): array
6365 {
6466 $ quoteId = $ order [0 ]->getQuoteId ();
65- $ quote = $ this ->quoteRepository ->get ($ quoteId );
67+ $ quote = $ this ->cartRepositoryInterface ->get ($ quoteId );
6668 /* if coupon code has been canceled then need to notify the customer */
6769 if (!$ quote ->getCouponCode () && $ quote ->dataHasChangedFor ('coupon_code ' )) {
6870 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
7173 $ this ->updateCouponUsages ->execute ($ quote , true );
7274 try {
7375 return $ proceed ($ order );
74- } catch (\ Throwable $ e ) {
76+ } catch (Throwable $ e ) {
7577 $ this ->updateCouponUsages ->execute ($ quote , false );
7678 throw $ e ;
7779 }
0 commit comments