Skip to content

Commit 909e713

Browse files
committed
Merge branch 'ACP2E-3536' of https://github.com/adobe-commerce-tier-4/magento2ce into PR-02-11-2025
2 parents 895a765 + 249414e commit 909e713

File tree

5 files changed

+237
-8
lines changed

5 files changed

+237
-8
lines changed

app/code/Magento/Sales/Controller/Adminhtml/Order/Create.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -191,12 +191,13 @@ protected function _processActionData($action = null)
191191
*/
192192
$this->_getOrderCreateModel()->getBillingAddress();
193193

194+
$shippingMethod = $this->_getOrderCreateModel()->getShippingAddress()?->getShippingMethod();
195+
194196
/**
195197
* Flag for using billing address for shipping
196198
*/
197199
if (!$this->_getOrderCreateModel()->getQuote()->isVirtual()) {
198200
$syncFlag = $this->getRequest()->getPost('shipping_as_billing');
199-
$shippingMethod = $this->_getOrderCreateModel()->getShippingAddress()->getShippingMethod();
200201
if ($syncFlag === null
201202
&& $this->_getOrderCreateModel()->getShippingAddress()->getSameAsBilling() && empty($shippingMethod)
202203
) {
@@ -289,6 +290,7 @@ protected function _processActionData($action = null)
289290
$eventData = [
290291
'order_create_model' => $this->_getOrderCreateModel(),
291292
'request' => $this->getRequest()->getPostValue(),
293+
'shipping_method' => $shippingMethod
292294
];
293295

294296
$this->_eventManager->dispatch('adminhtml_sales_order_create_process_data', $eventData);

app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@
440440
*/
441441
setShippingAsBilling: function (flag) {
442442
var data,
443-
areasToLoad = ['billing_method', 'shipping_address', 'shipping_method', 'totals', 'giftmessage'];
443+
areasToLoad = ['items', 'billing_method', 'shipping_address', 'shipping_method', 'totals', 'giftmessage'];
444444

445445
this.disableShippingAddress(flag);
446446
data = this.serializeData(flag ? this.billingAddressContainer : this.shippingAddressContainer);
@@ -507,7 +507,7 @@
507507
loadPaymentMethods: function () {
508508
var data = this.serializeData(this.billingAddressContainer).toObject();
509509

510-
this.loadArea(['billing_method', 'totals'], true, data);
510+
this.loadArea(['items', 'billing_method', 'totals'], true, data);
511511

512512
return false;
513513
},
@@ -524,7 +524,7 @@
524524
this.setPaymentMethod(method);
525525
var data = {};
526526
data['order[payment_method]'] = method;
527-
this.loadArea(['card_validation'], true, data);
527+
this.loadArea(['items', 'card_validation'], true, data);
528528
},
529529

530530
setPaymentMethod: function (method) {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\SalesRule\Observer;
9+
10+
use Magento\Framework\Event\Observer;
11+
use Magento\Framework\Event\ObserverInterface;
12+
13+
/**
14+
* Class for process order for resetting shipping flag.
15+
*/
16+
class ProcessOrderCreationDataObserver implements ObserverInterface
17+
{
18+
/**
19+
* Checking shipping method and resetting it if needed.
20+
*
21+
* @param Observer $observer
22+
* @return $this
23+
*/
24+
public function execute(Observer $observer)
25+
{
26+
$order = $observer->getEvent()->getOrderCreateModel();
27+
$request = $observer->getEvent()->getRequest();
28+
if (array_key_exists('order', $request)) {
29+
$quote = $order->getQuote();
30+
$isVirtualQuote = $quote->isVirtual();
31+
$quoteShippingMethod = $observer->getEvent()->getShippingMethod();
32+
$checkIfCouponExists = array_key_exists('coupon', $request['order']);
33+
if (!$isVirtualQuote && !empty($quoteShippingMethod) && $checkIfCouponExists) {
34+
$shippingAddress = $quote->getShippingAddress();
35+
$shippingAddress->setShippingMethod($quoteShippingMethod);
36+
}
37+
}
38+
return $this;
39+
}
40+
}
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\SalesRule\Test\Unit\Observer;
9+
10+
use Magento\Framework\App\RequestInterface;
11+
use Magento\Framework\Event;
12+
use Magento\Framework\Event\Observer;
13+
use Magento\Quote\Model\Quote;
14+
use Magento\Quote\Model\Quote\Address;
15+
use Magento\Sales\Model\AdminOrder\Create;
16+
use Magento\SalesRule\Observer\ProcessOrderCreationDataObserver;
17+
use PHPUnit\Framework\MockObject\MockObject;
18+
use PHPUnit\Framework\TestCase;
19+
20+
/**
21+
* Test case for process order for resetting shipping flag.
22+
*/
23+
class ProcessOrderCreationDataObserverTest extends TestCase
24+
{
25+
/**
26+
* @var MockObject|Observer
27+
*/
28+
private $observerMock;
29+
30+
/**
31+
* @var Event|MockObject
32+
*/
33+
private $eventMock;
34+
35+
/**
36+
* @var MockObject
37+
*/
38+
private $requestMock;
39+
40+
/**
41+
* @var MockObject
42+
*/
43+
private $quoteMock;
44+
45+
/**
46+
* @var Address|MockObject
47+
*/
48+
private $shippingAddressMock;
49+
50+
/**
51+
* @var Create|MockObject
52+
*/
53+
private $orderCreateModelMock;
54+
55+
/**
56+
* @var ProcessOrderCreationDataObserver|MockObject
57+
*/
58+
private $model;
59+
60+
/**
61+
* @inheritdoc
62+
*/
63+
protected function setUp(): void
64+
{
65+
$this->observerMock = $this->createMock(Observer::class);
66+
$this->quoteMock = $this->getMockBuilder(Quote::class)
67+
->onlyMethods(['isVirtual', 'getShippingAddress'])
68+
->disableOriginalConstructor()
69+
->getMock();
70+
$this->eventMock = $this->getMockBuilder(Event::class)
71+
->disableOriginalConstructor()
72+
->addMethods(['getRequest', 'getOrderCreateModel', 'getShippingMethod'])
73+
->getMock();
74+
$this->shippingAddressMock = $this->getMockBuilder(Address::class)
75+
->addMethods(['setShippingMethod'])
76+
->disableOriginalConstructor()
77+
->getMock();
78+
$this->orderCreateModelMock = $this->getMockBuilder(Create::class)
79+
->onlyMethods(['getQuote'])
80+
->disableOriginalConstructor()
81+
->getMock();
82+
$this->requestMock = $this->getMockForAbstractClass(RequestInterface::class);
83+
$this->model = new ProcessOrderCreationDataObserver();
84+
}
85+
86+
/**
87+
* Test case for processOrderCreationDataObserver::execute
88+
*
89+
* @param bool $isVirtualQuote
90+
* @param array $requestArr
91+
* @param string|null $quoteShippingMethod
92+
* @return void
93+
* @dataProvider executeDataProvider
94+
*/
95+
public function testExecute(
96+
bool $isVirtualQuote,
97+
array $requestArr,
98+
?string $quoteShippingMethod = null,
99+
): void {
100+
$this->observerMock
101+
->expects($this->any())
102+
->method('getEvent')
103+
->willReturn($this->eventMock);
104+
$this->eventMock
105+
->expects($this->any())
106+
->method('getRequest')
107+
->willReturn($requestArr);
108+
$this->eventMock
109+
->expects($this->any())
110+
->method('getOrderCreateModel')
111+
->willReturn($this->orderCreateModelMock);
112+
$this->eventMock
113+
->expects($this->any())
114+
->method('getShippingMethod')
115+
->willReturn($quoteShippingMethod);
116+
$this->orderCreateModelMock
117+
->expects($this->any())
118+
->method('getQuote')
119+
->willReturn($this->quoteMock);
120+
$this->quoteMock
121+
->expects($this->any())
122+
->method('isVirtual')
123+
->willReturn($isVirtualQuote);
124+
$this->quoteMock
125+
->expects($this->any())
126+
->method('getShippingAddress')
127+
->willReturn($this->shippingAddressMock);
128+
$this->shippingAddressMock
129+
->expects($this->any())
130+
->method('setShippingMethod')
131+
->with($quoteShippingMethod)
132+
->willReturn(true);
133+
$this->model->execute($this->observerMock);
134+
}
135+
136+
/**
137+
* Data provider for testExecute
138+
*
139+
* @return array[]
140+
*/
141+
public static function executeDataProvider(): array
142+
{
143+
return [
144+
[
145+
'isVirtualQuote' => false,
146+
'requestArr' =>
147+
[
148+
'order' => ['coupon' => 'coupon_code'],
149+
'reset_shipping' => true,
150+
'collect_shipping_rates' => true
151+
],
152+
'quoteShippingMethod' => 'flatrate_flatrate',
153+
],
154+
[
155+
'isVirtualQuote' => true,
156+
'requestArr' =>
157+
[
158+
'order' => ['coupon' => 'coupon_code'],
159+
'reset_shipping' => false
160+
],
161+
'quoteShippingMethod' => 'freeshipping_freeshipping',
162+
],
163+
[
164+
'isVirtualQuote' => false,
165+
'requestArr' =>
166+
[
167+
'order' => ['coupon' => ''],
168+
'collect_shipping_rates' => true
169+
],
170+
'quoteShippingMethod' => null,
171+
],
172+
[
173+
'isVirtualQuote' => false,
174+
'requestArr' =>
175+
[
176+
'order' => ['coupon' => 'coupon_code'],
177+
'reset_shipping' => false,
178+
'collect_shipping_rates' => true
179+
],
180+
'quoteShippingMethod' => 'flatrate_flatrate'
181+
]
182+
];
183+
}
184+
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0"?>
22
<!--
33
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
4+
* Copyright 2011 Adobe
5+
* All rights reserved.
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
@@ -12,4 +12,7 @@
1212
<event name="catalog_entity_attribute_save_after">
1313
<observer name="salesrule" instance="Magento\SalesRule\Observer\CatalogAttributeSaveAfterObserver" />
1414
</event>
15+
<event name="adminhtml_sales_order_create_process_data">
16+
<observer name="magento_salesrule" instance="Magento\SalesRule\Observer\ProcessOrderCreationDataObserver"/>
17+
</event>
1518
</config>

0 commit comments

Comments
 (0)