Skip to content

Commit a52ff98

Browse files
Merge pull request #9589 from adobe-commerce-tier-4/PR-02-11-2025
[Support Tier-4 chittima] 02-11-2025 Regular delivery of bugfixes and improvements
2 parents 1d33c93 + e18763f commit a52ff98

File tree

22 files changed

+502
-140
lines changed

22 files changed

+502
-140
lines changed

app/code/Magento/CatalogInventory/Model/StockStateProvider.php

+3-3
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 2014 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\CatalogInventory\Model;
@@ -159,7 +159,7 @@ public function checkQuoteItemQty(StockItemInterface $stockItem, $qty, $summaryQ
159159
if (!$stockItem->getIsInStock()) {
160160
$result->setHasError(true)
161161
->setErrorCode('out_stock')
162-
->setMessage(__('This product is out of stock.'))
162+
->setMessage(__('Product %name is out of stock.', ['name' => $stockItem->getProductName()]))
163163
->setQuoteMessage(__('Some of the products are out of stock.'))
164164
->setQuoteMessageIndex('stock');
165165
$result->setItemUseOldQty(true);

app/code/Magento/CatalogInventory/i18n/en_US.csv

+1
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,4 @@ Stock,Stock
7777
"Only %s of %s available","Only %s of %s available"
7878
"Not enough items for sale","Not enough items for sale"
7979
"The requested qty. is not available","The requested qty. is not available"
80+
"Product %name is out of stock.","Product %name is out of stock."

app/code/Magento/Csp/Test/Unit/Plugin/StoreAssetIntegrityHashesTest.php

+2-3
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 2024 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -62,7 +62,6 @@ protected function setUp(): void
6262
* Test After Deploy method of plugin
6363
*
6464
* @return void
65-
* @doesNotPerformAssertions
6665
*/
6766
public function testAfterDeploy(): void
6867
{

app/code/Magento/Customer/Test/Unit/Model/AccountManagementApiTest.php

+2-4
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 2023 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -433,8 +433,6 @@ public function testBeforeCreateAccount(
433433
): void {
434434
if ($willThrowException) {
435435
$this->expectException(AuthorizationException::class);
436-
} else {
437-
$this->expectNotToPerformAssertions();
438436
}
439437
$this->authorizationMock
440438
->expects($this->once())

app/code/Magento/Customer/Test/Unit/Plugin/AsyncRequestCustomerGroupAuthorizationTest.php

+2-3
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 2023 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -86,7 +86,6 @@ public function testBeforePublishMass(
8686
[$customer, 'Password1', '']
8787
];
8888
$this->authorizationMock
89-
->expects($this->once())
9089
->method('isAllowed')
9190
->with('Magento_Customer::manage')
9291
->willReturn($isAllowed);

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

+5-3
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/Model/AdminOrder/Create.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,7 @@ protected function _initShippingAddressFromOrder(\Magento\Sales\Model\Order $ord
708708
* @param int $qty
709709
* @return \Magento\Quote\Model\Quote\Item|string|$this
710710
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
711+
* @throws LocalizedException
711712
*/
712713
public function initFromOrderItem(\Magento\Sales\Model\Order\Item $orderItem, $qty = null)
713714
{
@@ -733,9 +734,14 @@ public function initFromOrderItem(\Magento\Sales\Model\Order\Item $orderItem, $q
733734

734735
$this->formattedOptions($product, $buyRequest, $productOptions);
735736

736-
$item = $this->getQuote()->addProduct($product, $buyRequest);
737-
if (is_string($item)) {
738-
return $item;
737+
try {
738+
$item = $this->getQuote()->addProduct($product, $buyRequest);
739+
if (is_string($item)) {
740+
return $item;
741+
}
742+
} catch (LocalizedException $e) {
743+
$this->messageManager->addErrorMessage(__($e->getMessage()));
744+
return $this;
739745
}
740746

741747
if ($additionalOptions = $orderItem->getProductOptionByCode('additional_options')) {

app/code/Magento/Sales/Test/Unit/Model/AdminOrder/CreateTest.php

+70-13
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 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -18,6 +18,9 @@
1818
use Magento\Customer\Model\Metadata\FormFactory;
1919
use Magento\Framework\Api\DataObjectHelper;
2020
use Magento\Framework\App\RequestInterface;
21+
use Magento\Framework\Exception\LocalizedException;
22+
use Magento\Framework\Message\ManagerInterface;
23+
use Magento\Framework\ObjectManagerInterface;
2124
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
2225
use Magento\Quote\Api\CartRepositoryInterface;
2326
use Magento\Quote\Model\Quote;
@@ -44,57 +47,67 @@ class CreateTest extends TestCase
4447
/**
4548
* @var Create
4649
*/
47-
private $adminOrderCreate;
50+
private Create $adminOrderCreate;
4851

4952
/**
5053
* @var CartRepositoryInterface|MockObject
5154
*/
52-
private $quoteRepository;
55+
private CartRepositoryInterface $quoteRepository;
5356

5457
/**
5558
* @var QuoteFactory|MockObject
5659
*/
57-
private $quoteFactory;
60+
private QuoteFactory $quoteFactory;
5861

5962
/**
6063
* @var SessionQuote|MockObject
6164
*/
62-
private $sessionQuote;
65+
private SessionQuote $sessionQuote;
6366

6467
/**
6568
* @var FormFactory|MockObject
6669
*/
67-
private $formFactory;
70+
private FormFactory $formFactory;
6871

6972
/**
7073
* @var CustomerInterfaceFactory|MockObject
7174
*/
72-
private $customerFactory;
75+
private CustomerInterfaceFactory $customerFactory;
7376

7477
/**
7578
* @var Updater|MockObject
7679
*/
77-
private $itemUpdater;
80+
private Updater $itemUpdater;
7881

7982
/**
8083
* @var Mapper|MockObject
8184
*/
82-
private $customerMapper;
85+
private Mapper $customerMapper;
8386

8487
/**
8588
* @var GroupRepositoryInterface|MockObject
8689
*/
87-
private $groupRepository;
90+
private GroupRepositoryInterface $groupRepository;
8891

8992
/**
9093
* @var DataObjectHelper|MockObject
9194
*/
92-
private $dataObjectHelper;
95+
private DataObjectHelper $dataObjectHelper;
9396

9497
/**
9598
* @var Order|MockObject
9699
*/
97-
private $orderMock;
100+
private Order $orderMock;
101+
102+
/**
103+
* @var ObjectManagerInterface|ObjectManagerInterface&MockObject|MockObject
104+
*/
105+
private ObjectManagerInterface $objectManager;
106+
107+
/**
108+
* @var ManagerInterface|ManagerInterface&MockObject|MockObject
109+
*/
110+
private ManagerInterface $messageManager;
98111

99112
/**
100113
* @inheritdoc
@@ -166,10 +179,14 @@ protected function setUp(): void
166179
)
167180
->getMock();
168181

182+
$this->objectManager = $this->createMock(ObjectManagerInterface::class);
183+
$this->messageManager = $this->createMock(ManagerInterface::class);
169184
$objectManagerHelper = new ObjectManagerHelper($this);
170185
$this->adminOrderCreate = $objectManagerHelper->getObject(
171186
Create::class,
172187
[
188+
'_objectManager' => $this->objectManager,
189+
'messageManager' => $this->messageManager,
173190
'quoteSession' => $this->sessionQuote,
174191
'metadataFormFactory' => $this->formFactory,
175192
'customerFactory' => $this->customerFactory,
@@ -183,6 +200,46 @@ protected function setUp(): void
183200
);
184201
}
185202

203+
/**
204+
* @return void
205+
* @throws \PHPUnit\Framework\MockObject\Exception|LocalizedException
206+
*/
207+
public function testInitFromOrderItemNoExceptionThrownOnAddProduct(): void
208+
{
209+
$orderItemId = $productId = 1;
210+
$exceptionMessage = 'Exception message';
211+
212+
$buyRequest = $this->createMock(\Magento\Framework\DataObject::class);
213+
214+
$orderItem = $this->createMock(\Magento\Sales\Model\Order\Item::class);
215+
$orderItem->expects($this->once())->method('getId')->willReturn($orderItemId);
216+
$orderItem->expects($this->once())->method('getProductId')->willReturn($productId);
217+
$orderItem->expects($this->once())->method('getBuyRequest')->willReturn($buyRequest);
218+
$orderItem->expects($this->once())->method('getProductOptions')->willReturn(null);
219+
220+
$product = $this->createMock(\Magento\Catalog\Model\Product::class);
221+
$product->expects($this->once())->method('setStoreId')->willReturnSelf();
222+
$product->expects($this->once())->method('load')->willReturnSelf();
223+
$product->expects($this->once())->method('getId')->willReturn($productId);
224+
$this->objectManager->expects($this->once())->method('create')->willReturn($product);
225+
226+
$exception = new LocalizedException(__($exceptionMessage));
227+
$quote = $this->createMock(Quote::class);
228+
$quote->expects($this->once())
229+
->method('addProduct')
230+
->with($product, $buyRequest)
231+
->willThrowException($exception);
232+
$this->sessionQuote->method('getQuote')
233+
->willReturn($quote);
234+
235+
$this->messageManager->expects($this->once())
236+
->method('addErrorMessage')
237+
->with(__($exceptionMessage))
238+
->willReturnSelf();
239+
240+
$this->adminOrderCreate->initFromOrderItem($orderItem);
241+
}
242+
186243
public function testSetAccountData()
187244
{
188245
$taxClassId = 1;

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

+3-3
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) {
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+
}

0 commit comments

Comments
 (0)