Skip to content

Commit ba0d0f1

Browse files
Chhandak.BaruaChhandak.Barua
authored andcommitted
ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping.
1 parent c905c73 commit ba0d0f1

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818

1919
namespace Magento\SalesRule\Plugin;
2020

21+
use Closure;
2122
use Magento\Framework\Exception\NoSuchEntityException;
22-
use Magento\Quote\Model\QuoteRepository;
2323
use Magento\SalesRule\Model\Coupon\Quote\UpdateCouponUsages;
2424
use 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

Comments
 (0)