Skip to content

Commit

Permalink
remove resetCouponAfterCancellation because it's handled by CouponUsa…
Browse files Browse the repository at this point in the history
…gesDecrement plugin
  • Loading branch information
Sander Jongsma committed Feb 11, 2025
1 parent 4aad9bf commit be32441
Showing 1 changed file with 0 additions and 36 deletions.
36 changes: 0 additions & 36 deletions Service/Order/CancelOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\StatusResolver;
use Magento\SalesRule\Model\Coupon;
use Magento\SalesRule\Model\ResourceModel\Coupon\Usage;
use Mollie\Payment\Config;

class CancelOrder
Expand All @@ -38,16 +36,6 @@ class CancelOrder
*/
private $orderRepository;

/**
* @var Coupon
*/
private $coupon;

/**
* @var Usage
*/
private $couponUsage;

/**
* @var StatusResolver
*/
Expand All @@ -63,17 +51,13 @@ public function __construct(
OrderCommentHistory $orderCommentHistory,
OrderManagementInterface $orderManagement,
OrderRepositoryInterface $orderRepository,
Coupon $coupon,
Usage $couponUsage,
StatusResolver $statusResolver,
ResourceConnection $resource
) {
$this->config = $config;
$this->orderCommentHistory = $orderCommentHistory;
$this->orderManagement = $orderManagement;
$this->orderRepository = $orderRepository;
$this->coupon = $coupon;
$this->couponUsage = $couponUsage;
$this->statusResolver = $statusResolver;
$this->resource = $resource;
}
Expand Down Expand Up @@ -101,29 +85,9 @@ public function execute(OrderInterface $order, $reason = null): bool

$this->orderManagement->cancel($order->getId());

if ($order->getCouponCode()) {
$this->resetCouponAfterCancellation($order);
}

return true;
}

public function resetCouponAfterCancellation(OrderInterface $order)
{
$this->coupon->load($order->getCouponCode(), 'code');
if (!$this->coupon->getId()) {
return;
}

$this->coupon->setTimesUsed($this->coupon->getTimesUsed() - 1);
$this->coupon->save();

$customerId = $order->getCustomerId();
if ($customerId) {
$this->couponUsage->updateCustomerCouponTimesUsed($customerId, $this->coupon->getId(), false);
}
}

/**
* It is possible that the order is cancelled in process A, and we are checking here in process B. So always check
* the latest status in the database so we are sure we have the most recent status available.
Expand Down

0 comments on commit be32441

Please sign in to comment.