diff --git a/vendor/magento/module-sales-rule/Plugin/CouponUsagesIncrementMultishipping.php b/vendor/magento/module-sales-rule/Plugin/CouponUsagesIncrementMultishipping.php new file mode 100644 index 0000000..ce0c975 --- /dev/null +++ b/vendor/magento/module-sales-rule/Plugin/CouponUsagesIncrementMultishipping.php @@ -0,0 +1,83 @@ +updateCouponUsages = $updateCouponUsages; + $this->cartRepositoryInterface = $cartRepositoryInterface; + } + + /** + * Increments number of coupon usages before placing order + * + * @param PlaceOrderDefault $subject + * @param Closure $proceed + * @param array $order + * @return array + * @throws NoSuchEntityException|Throwable + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function aroundPlace(PlaceOrderDefault $subject, Closure $proceed, array $order): array + { + $quoteId = $order[0]->getQuoteId(); + $quote = $this->cartRepositoryInterface->get($quoteId); + /* if coupon code has been canceled then need to notify the customer */ + if (!$quote->getCouponCode() && $quote->dataHasChangedFor('coupon_code')) { + throw new NoSuchEntityException(__("The coupon code isn't valid. Verify the code and try again.")); + } + + $this->updateCouponUsages->execute($quote, true); + try { + return $proceed($order); + } catch (Throwable $e) { + $this->updateCouponUsages->execute($quote, false); + throw $e; + } + } +} diff --git a/vendor/magento/module-sales-rule/etc/di.xml b/vendor/magento/module-sales-rule/etc/di.xml index daa74d4..ad44637 100644 --- a/vendor/magento/module-sales-rule/etc/di.xml +++ b/vendor/magento/module-sales-rule/etc/di.xml @@ -195,6 +195,9 @@ + + +