Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove resetCouponAfterCancellation because it's handled by CouponUsagesDecrement plugin #862

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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