-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-3784: Fixed bug, when exception occurred on order with coupons…
… cancel, made by guest after creating of customer account. #19423
- Loading branch information
Showing
6 changed files
with
436 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Sales\Model\Order; | ||
|
||
use Magento\Sales\Api\Data\OrderInterface; | ||
use Magento\Sales\Api\OrderRepositoryInterface; | ||
use Magento\Customer\Api\Data\CustomerInterface; | ||
use Magento\Framework\Event\ManagerInterface; | ||
|
||
class CustomerAssignment | ||
{ | ||
/** | ||
* @var ManagerInterface | ||
*/ | ||
private $eventManager; | ||
|
||
/** | ||
* @var OrderRepositoryInterface | ||
*/ | ||
private $orderRepository; | ||
|
||
/** | ||
* CustomerAssignment constructor. | ||
* | ||
* @param ManagerInterface $eventManager | ||
* @param OrderRepositoryInterface $orderRepository | ||
*/ | ||
public function __construct( | ||
ManagerInterface $eventManager, | ||
OrderRepositoryInterface $orderRepository | ||
) { | ||
$this->eventManager = $eventManager; | ||
$this->orderRepository = $orderRepository; | ||
} | ||
|
||
/** | ||
* @param OrderInterface $order | ||
* @param CustomerInterface $customer | ||
*/ | ||
public function execute(OrderInterface $order, CustomerInterface $customer)/*: void*/ | ||
{ | ||
$order->setCustomerId($customer->getId()); | ||
$order->setCustomerIsGuest(false); | ||
$this->orderRepository->save($order); | ||
|
||
$this->eventManager->dispatch( | ||
'sales_order_customer_assign_after', | ||
[ | ||
'order' => $order, | ||
'customer' => $customer | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
app/code/Magento/SalesRule/Observer/AssignCouponDataAfterOrderCustomerAssignObserver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\SalesRule\Observer; | ||
|
||
use Magento\Framework\Event\Observer; | ||
use Magento\SalesRule\Model\Coupon\UpdateCouponUsages; | ||
use Magento\Sales\Api\Data\OrderInterface; | ||
use Magento\Framework\Event\ObserverInterface; | ||
|
||
class AssignCouponDataAfterOrderCustomerAssignObserver implements ObserverInterface | ||
{ | ||
const EVENT_KEY_CUSTOMER = 'customer'; | ||
|
||
const EVENT_KEY_ORDER = 'order'; | ||
|
||
/** | ||
* @var UpdateCouponUsages | ||
*/ | ||
private $updateCouponUsages; | ||
|
||
/** | ||
* AssignCouponDataAfterOrderCustomerAssign constructor. | ||
* | ||
* @param UpdateCouponUsages $updateCouponUsages | ||
*/ | ||
public function __construct( | ||
UpdateCouponUsages $updateCouponUsages | ||
) { | ||
$this->updateCouponUsages = $updateCouponUsages; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function execute(Observer $observer) | ||
{ | ||
$event = $observer->getEvent(); | ||
/** @var OrderInterface $order */ | ||
$order = $event->getData(self::EVENT_KEY_ORDER); | ||
|
||
if ($order->getCustomerId()) { | ||
$this->updateCouponUsages->execute($order, true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.