Skip to content

Commit d20f927

Browse files
authored
🔃 [EngCom] Public Pull Requests - 2.2-develop
Accepted Public Pull Requests: - #20082: [Backport] issue resolved:Undefined Variable $itemsOrderItemId (by @milindsingh) - #19423: Fixed bug, when exception occurred on order with coupons cancel, made by guest after creating of customer account. (by @Winfle) - #19927: [Backport] [Framework] New Link is not correctly shown as Current if contains default parts (by @eduard13) Fixed GitHub Issues: - #19940: Exception undefined variable itemsOrderItemId while creating shipment through MSI (reported by @mohammadzakir) has been fixed in #20082 by @milindsingh in 2.2-develop branch Related commits: 1. 4802e00 2. cb15b01 - #19230: Can't Cancel Order (reported by @friendscottn) has been fixed in #19423 by @Winfle in 2.2-develop branch Related commits: 1. cede04f 2. 11480e8 3. 10fbf40 4. 1e2f3fb 5. 5ea6e72 6. 9a63dad 7. 36c2329 8. fdf7da4 - #19099: New Link is not correctly shown as Current if contains default parts (reported by @eduard13) has been fixed in #19927 by @eduard13 in 2.2-develop branch Related commits: 1. 0e027a0 2. 1357888 3. 83cbf32 4. 02bc6fa 5. cf1e877 6. a03c156
2 parents 56b9c6c + a132cac commit d20f927

File tree

9 files changed

+484
-42
lines changed

9 files changed

+484
-42
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Sales\Model\Order;
9+
10+
use Magento\Sales\Api\Data\OrderInterface;
11+
use Magento\Sales\Api\OrderRepositoryInterface;
12+
use Magento\Customer\Api\Data\CustomerInterface;
13+
use Magento\Framework\Event\ManagerInterface;
14+
15+
class CustomerAssignment
16+
{
17+
/**
18+
* @var ManagerInterface
19+
*/
20+
private $eventManager;
21+
22+
/**
23+
* @var OrderRepositoryInterface
24+
*/
25+
private $orderRepository;
26+
27+
/**
28+
* CustomerAssignment constructor.
29+
*
30+
* @param ManagerInterface $eventManager
31+
* @param OrderRepositoryInterface $orderRepository
32+
*/
33+
public function __construct(
34+
ManagerInterface $eventManager,
35+
OrderRepositoryInterface $orderRepository
36+
) {
37+
$this->eventManager = $eventManager;
38+
$this->orderRepository = $orderRepository;
39+
}
40+
41+
/**
42+
* @param OrderInterface $order
43+
* @param CustomerInterface $customer
44+
*/
45+
public function execute(OrderInterface $order, CustomerInterface $customer)/*: void*/
46+
{
47+
$order->setCustomerId($customer->getId());
48+
$order->setCustomerIsGuest(false);
49+
$this->orderRepository->save($order);
50+
51+
$this->eventManager->dispatch(
52+
'sales_order_customer_assign_after',
53+
[
54+
'order' => $order,
55+
'customer' => $customer
56+
]
57+
);
58+
}
59+
}

app/code/Magento/Sales/Observer/AssignOrderToCustomerObserver.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\Event\Observer;
1313
use Magento\Framework\Event\ObserverInterface;
1414
use Magento\Sales\Api\OrderRepositoryInterface;
15+
use Magento\Sales\Model\Order\CustomerAssignment;
1516

1617
/**
1718
* Assign order to customer created after issuing guest order.
@@ -24,11 +25,22 @@ class AssignOrderToCustomerObserver implements ObserverInterface
2425
private $orderRepository;
2526

2627
/**
28+
* @var CustomerAssignment
29+
*/
30+
private $assignmentService;
31+
32+
/**
33+
* AssignOrderToCustomerObserver constructor.
34+
*
2735
* @param OrderRepositoryInterface $orderRepository
36+
* @param CustomerAssignment $assignmentService
2837
*/
29-
public function __construct(OrderRepositoryInterface $orderRepository)
30-
{
38+
public function __construct(
39+
OrderRepositoryInterface $orderRepository,
40+
CustomerAssignment $assignmentService
41+
) {
3142
$this->orderRepository = $orderRepository;
43+
$this->assignmentService = $assignmentService;
3244
}
3345

3446
/**
@@ -44,11 +56,8 @@ public function execute(Observer $observer)
4456
if (array_key_exists('__sales_assign_order_id', $delegateData)) {
4557
$orderId = $delegateData['__sales_assign_order_id'];
4658
$order = $this->orderRepository->get($orderId);
47-
if (!$order->getCustomerId()) {
48-
//if customer ID wasn't already assigned then assigning.
49-
$order->setCustomerId($customer->getId());
50-
$order->setCustomerIsGuest(0);
51-
$this->orderRepository->save($order);
59+
if (!$order->getCustomerId() && $customer->getId()) {
60+
$this->assignmentService->execute($order, $customer);
5261
}
5362
}
5463
}

app/code/Magento/Sales/Test/Unit/Observer/AssignOrderToCustomerObserverTest.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\Event\Observer;
1313
use Magento\Sales\Api\Data\OrderInterface;
1414
use Magento\Sales\Api\OrderRepositoryInterface;
15+
use Magento\Sales\Model\Order\CustomerAssignment;
1516
use Magento\Sales\Observer\AssignOrderToCustomerObserver;
1617
use PHPUnit\Framework\TestCase;
1718
use PHPUnit_Framework_MockObject_MockObject;
@@ -27,6 +28,9 @@ class AssignOrderToCustomerObserverTest extends TestCase
2728
/** @var OrderRepositoryInterface|PHPUnit_Framework_MockObject_MockObject */
2829
protected $orderRepositoryMock;
2930

31+
/** @var CustomerAssignment | PHPUnit_Framework_MockObject_MockObject */
32+
protected $assignmentMock;
33+
3034
/**
3135
* Set Up
3236
*/
@@ -35,7 +39,12 @@ protected function setUp()
3539
$this->orderRepositoryMock = $this->getMockBuilder(OrderRepositoryInterface::class)
3640
->disableOriginalConstructor()
3741
->getMock();
38-
$this->sut = new AssignOrderToCustomerObserver($this->orderRepositoryMock);
42+
43+
$this->assignmentMock = $this->getMockBuilder(CustomerAssignment::class)
44+
->disableOriginalConstructor()
45+
->getMock();
46+
47+
$this->sut = new AssignOrderToCustomerObserver($this->orderRepositoryMock, $this->assignmentMock);
3948
}
4049

4150
/**
@@ -69,13 +78,14 @@ public function testAssignOrderToCustomerAfterGuestOrder($customerId)
6978
$orderMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
7079
$this->orderRepositoryMock->expects($this->once())->method('get')->with($orderId)
7180
->willReturn($orderMock);
72-
if (!$customerId) {
73-
$this->orderRepositoryMock->expects($this->once())->method('save')->with($orderMock);
81+
82+
if ($customerId) {
83+
$this->assignmentMock->expects($this->once())->method('execute')->with($orderMock, $customerMock);
7484
$this->sut->execute($observerMock);
75-
return ;
85+
return;
7686
}
7787

78-
$this->orderRepositoryMock->expects($this->never())->method('save')->with($orderMock);
88+
$this->assignmentMock->expects($this->never())->method('execute');
7989
$this->sut->execute($observerMock);
8090
}
8191

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Magento\SalesRule\Observer;
11+
12+
use Magento\Framework\Event\Observer;
13+
use Magento\SalesRule\Model\Coupon\UpdateCouponUsages;
14+
use Magento\Sales\Api\Data\OrderInterface;
15+
use Magento\Framework\Event\ObserverInterface;
16+
17+
class AssignCouponDataAfterOrderCustomerAssignObserver implements ObserverInterface
18+
{
19+
const EVENT_KEY_CUSTOMER = 'customer';
20+
21+
const EVENT_KEY_ORDER = 'order';
22+
23+
/**
24+
* @var UpdateCouponUsages
25+
*/
26+
private $updateCouponUsages;
27+
28+
/**
29+
* AssignCouponDataAfterOrderCustomerAssign constructor.
30+
*
31+
* @param UpdateCouponUsages $updateCouponUsages
32+
*/
33+
public function __construct(
34+
UpdateCouponUsages $updateCouponUsages
35+
) {
36+
$this->updateCouponUsages = $updateCouponUsages;
37+
}
38+
39+
/**
40+
* @inheritDoc
41+
*/
42+
public function execute(Observer $observer)
43+
{
44+
$event = $observer->getEvent();
45+
/** @var OrderInterface $order */
46+
$order = $event->getData(self::EVENT_KEY_ORDER);
47+
48+
if ($order->getCustomerId()) {
49+
$this->updateCouponUsages->execute($order, true);
50+
}
51+
}
52+
}

app/code/Magento/SalesRule/etc/events.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@
2424
<event name="magento_salesrule_api_data_ruleinterface_load_after">
2525
<observer name="legacy_model_load" instance="Magento\Framework\EntityManager\Observer\AfterEntityLoad" />
2626
</event>
27+
<event name="sales_order_customer_assign_after">
28+
<observer name="sales_order_assign_customer_after" instance="Magento\SalesRule\Observer\AssignCouponDataAfterOrderCustomerAssignObserver" />
29+
</event>
2730
</config>

app/code/Magento/Shipping/Block/Adminhtml/Order/Packaging.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public function getShipment()
7474
* Configuration for popup window for packaging
7575
*
7676
* @return string
77+
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
7778
*/
7879
public function getConfigDataJson()
7980
{
@@ -86,7 +87,7 @@ public function getConfigDataJson()
8687
$itemsName = [];
8788
$itemsWeight = [];
8889
$itemsProductId = [];
89-
90+
$itemsOrderItemId = [];
9091
if ($shipmentId) {
9192
$urlParams['shipment_id'] = $shipmentId;
9293
$createLabelUrl = $this->getUrl('adminhtml/order_shipment/createLabel', $urlParams);

0 commit comments

Comments
 (0)