Skip to content

Commit 42d6ed0

Browse files
Chhandak.BaruaChhandak.Barua
Chhandak.Barua
authored and
Chhandak.Barua
committed
Merge remote-tracking branch 'origin/2.4-develop' into ACP2E-3127
2 parents 3a1a00d + 140433c commit 42d6ed0

File tree

17 files changed

+706
-69
lines changed

17 files changed

+706
-69
lines changed

app/code/Magento/Bundle/view/adminhtml/web/js/components/bundle-dynamic-rows-grid.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,13 @@ define([
141141
* @returns {Object} Chainable.
142142
*/
143143
initElements: function (data) {
144-
var newData = this.getNewData(data),
145-
recordIndex;
144+
var newData = this.getNewData(data);
146145

147146
this.parsePagesData(data);
148147

149148
if (newData.length) {
150149
if (this.insertData().length) {
151-
recordIndex = data.length - newData.length - 1;
152-
153-
_.each(newData, function (newRecord) {
154-
this.processingAddChild(newRecord, ++recordIndex, newRecord[this.identificationProperty]);
155-
}, this);
150+
this.parseProcessingAddChild(data, newData);
156151
}
157152
}
158153

@@ -181,6 +176,23 @@ define([
181176
this.reload();
182177
}
183178
}, this);
179+
},
180+
181+
/**
182+
* Parse and processing the add child method to update the latest records if the record index is not a number.
183+
*
184+
* @param {Array} data
185+
* @param {Array} newData
186+
*/
187+
parseProcessingAddChild: function (data, newData) {
188+
let recordIndex;
189+
190+
recordIndex = data.length - newData.length - 1;
191+
if (!isNaN(recordIndex)) {
192+
_.each(newData, function (newRecord) {
193+
this.processingAddChild(newRecord, ++recordIndex, newRecord[this.identificationProperty]);
194+
}, this);
195+
}
184196
}
185197
});
186198
});

app/code/Magento/Bundle/view/adminhtml/web/js/components/bundle-dynamic-rows.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ define([
7474
let bundleSelections = registry.get(this.name + '.' + index + '.' + this.bundleSelectionsName);
7575

7676
bundleSelections.destroyChildren();
77+
bundleSelections._elems.clear();
7778
},
7879

7980
/**

app/code/Magento/CatalogGraphQl/Model/Resolver/Products.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1616
use Magento\Catalog\Model\Layer\Resolver;
1717
use Magento\CatalogGraphQl\DataProvider\Product\SearchCriteriaBuilder;
18+
use Magento\Framework\GraphQl\Query\Uid;
19+
use Magento\Framework\App\ObjectManager;
1820

1921
/**
2022
* Products field resolver, used for GraphQL request processing.
@@ -31,17 +33,23 @@ class Products implements ResolverInterface
3133
*/
3234
private $searchApiCriteriaBuilder;
3335

36+
/** @var Uid */
37+
private $uidEncoder;
38+
3439
/**
3540
* @param ProductQueryInterface $searchQuery
3641
* @param SearchCriteriaBuilder|null $searchApiCriteriaBuilder
42+
* @param Uid|null $uidEncoder
3743
*/
3844
public function __construct(
3945
ProductQueryInterface $searchQuery,
40-
SearchCriteriaBuilder $searchApiCriteriaBuilder = null
46+
SearchCriteriaBuilder $searchApiCriteriaBuilder = null,
47+
Uid $uidEncoder = null
4148
) {
4249
$this->searchQuery = $searchQuery;
4350
$this->searchApiCriteriaBuilder = $searchApiCriteriaBuilder ??
44-
\Magento\Framework\App\ObjectManager::getInstance()->get(SearchCriteriaBuilder::class);
51+
ObjectManager::getInstance()->get(SearchCriteriaBuilder::class);
52+
$this->uidEncoder = $uidEncoder ?: ObjectManager::getInstance()->get(Uid::class);
4553
}
4654

4755
/**
@@ -80,6 +88,10 @@ public function resolve(
8088
'layer_type' => isset($args['search']) ? Resolver::CATALOG_LAYER_SEARCH : Resolver::CATALOG_LAYER_CATEGORY,
8189
];
8290

91+
if (isset($args['filter']['category_uid'])) {
92+
$args['filter']['category_id'] = $this->getFilterCategoryIdFromCategoryUid($args['filter']['category_uid']);
93+
}
94+
8395
if (isset($args['filter']['category_id'])) {
8496
$data['categories'] = $args['filter']['category_id']['eq'] ?? $args['filter']['category_id']['in'];
8597
$data['categories'] = is_array($data['categories']) ? $data['categories'] : [$data['categories']];
@@ -88,6 +100,26 @@ public function resolve(
88100
return $data;
89101
}
90102

103+
/**
104+
* Get filter category_id by category_uid
105+
*
106+
* @param array $filterCategoryUid
107+
* @return array|null
108+
*/
109+
private function getFilterCategoryIdFromCategoryUid(array $filterCategoryUid): ?array
110+
{
111+
$filterCategoryId = null;
112+
if (isset($filterCategoryUid['eq'])) {
113+
$filterCategoryId['eq'] = $this->uidEncoder
114+
->decode((string)$filterCategoryUid['eq']);
115+
} elseif (!empty($filterCategoryUid['in'])) {
116+
foreach ($filterCategoryUid['in'] as $uid) {
117+
$filterCategoryId['in'][] = $this->uidEncoder->decode((string) $uid);
118+
}
119+
}
120+
return $filterCategoryId;
121+
}
122+
91123
/**
92124
* Validate input arguments
93125
*

app/code/Magento/Quote/Model/Cart/ProductReader.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ProductReader implements ProductReaderInterface
2525
/**
2626
* @var ProductInterface[]
2727
*/
28-
private $productsBySku;
28+
private array $productsBySku;
2929

3030
/**
3131
* @var Config
@@ -65,7 +65,7 @@ public function loadProducts(array $skus, int $storeId): void
6565
$this->productCollection->addOptionsToResult();
6666
$this->productCollection->load();
6767
foreach ($this->productCollection->getItems() as $productItem) {
68-
$this->productsBySku[$productItem->getData(ProductInterface::SKU)] = $productItem;
68+
$this->productsBySku[strtolower($productItem->getData(ProductInterface::SKU))] = $productItem;
6969
}
7070
}
7171

@@ -74,6 +74,6 @@ public function loadProducts(array $skus, int $storeId): void
7474
*/
7575
public function getProductBySku(string $sku) : ?ProductInterface
7676
{
77-
return $this->productsBySku[$sku] ?? null;
77+
return $this->productsBySku[strtolower($sku)] ?? null;
7878
}
7979
}

app/code/Magento/QuoteGraphQl/Model/Resolver/UpdateCartItems.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
8787

8888
try {
8989
$this->updateCartItems->processCartItems($cart, $cartItems);
90-
$this->cartRepository->save($cart);
90+
$updatedCart = $this->getCartForUser->execute($maskedCartId, $context->getUserId(), $storeId);
91+
$this->cartRepository->save($updatedCart);
9192
} catch (NoSuchEntityException $e) {
9293
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
9394
} catch (LocalizedException $e) {
@@ -96,7 +97,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
9697

9798
return [
9899
'cart' => [
99-
'model' => $cart,
100+
'model' => $updatedCart,
100101
],
101102
];
102103
}

app/code/Magento/Sales/Model/Service/OrderService.php

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Framework\App\ObjectManager;
99
use Magento\Payment\Gateway\Command\CommandException;
1010
use Magento\Sales\Api\OrderManagementInterface;
11+
use Magento\Sales\Model\Order\Config;
1112
use Magento\Sales\Model\OrderMutexInterface;
1213
use Psr\Log\LoggerInterface;
1314

@@ -66,6 +67,11 @@ class OrderService implements OrderManagementInterface
6667
*/
6768
private $orderMutex;
6869

70+
/**
71+
* @var Config
72+
*/
73+
private $orderConfig;
74+
6975
/**
7076
* Constructor
7177
*
@@ -79,6 +85,7 @@ class OrderService implements OrderManagementInterface
7985
* @param \Magento\Sales\Api\PaymentFailuresInterface $paymentFailures
8086
* @param LoggerInterface $logger
8187
* @param OrderMutexInterface|null $orderMutex
88+
* @param Config|null $orderConfig
8289
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8390
*/
8491
public function __construct(
@@ -91,7 +98,8 @@ public function __construct(
9198
\Magento\Sales\Model\Order\Email\Sender\OrderCommentSender $orderCommentSender,
9299
\Magento\Sales\Api\PaymentFailuresInterface $paymentFailures,
93100
LoggerInterface $logger,
94-
?OrderMutexInterface $orderMutex = null
101+
?OrderMutexInterface $orderMutex = null,
102+
?Config $orderConfig = null
95103
) {
96104
$this->orderRepository = $orderRepository;
97105
$this->historyRepository = $historyRepository;
@@ -103,6 +111,7 @@ public function __construct(
103111
$this->paymentFailures = $paymentFailures;
104112
$this->logger = $logger;
105113
$this->orderMutex = $orderMutex ?: ObjectManager::getInstance()->get(OrderMutexInterface::class);
114+
$this->orderConfig = $orderConfig ?: ObjectManager::getInstance()->get(Config::class);
106115
}
107116

108117
/**
@@ -165,16 +174,26 @@ public function getCommentsList($id)
165174
public function addComment($id, \Magento\Sales\Api\Data\OrderStatusHistoryInterface $statusHistory)
166175
{
167176
$order = $this->orderRepository->get($id);
168-
169-
/**
170-
* change order status is not allowed during add comment to the order
171-
*/
172-
if ($statusHistory->getStatus() && $statusHistory->getStatus() != $order->getStatus()) {
173-
throw new \Magento\Framework\Exception\LocalizedException(
174-
__('Unable to add comment: The status "%1" is not part of the order
175-
status history.', $statusHistory->getStatus())
176-
);
177+
$statuses = $this->orderConfig->getStateStatuses($order->getState());
178+
$orderStatus = $order->getStatus();
179+
$orderStatusHistory = $statusHistory->getStatus();
180+
if ($orderStatusHistory) {
181+
/**
182+
* change order status in the scope of different state is not allowed during add comment to the order
183+
*/
184+
if (!array_key_exists($orderStatusHistory, $statuses)) {
185+
throw new \Magento\Framework\Exception\LocalizedException(
186+
__(
187+
'Unable to add comment: The status "%1" is not part of the order status history.',
188+
$orderStatusHistory
189+
)
190+
);
191+
}
192+
$orderStatus = $orderStatusHistory;
177193
}
194+
$statusHistory->setStatus($orderStatus);
195+
$order->setStatus($orderStatus);
196+
178197
$order->addStatusHistory($statusHistory);
179198
$this->orderRepository->save($order);
180199
$notify = $statusHistory['is_customer_notified'] ?? false;

app/code/Magento/Sales/Test/Unit/Model/Service/OrderServiceTest.php

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Magento\Sales\Api\OrderStatusHistoryRepositoryInterface;
2121
use Magento\Sales\Api\PaymentFailuresInterface;
2222
use Magento\Sales\Model\Order;
23+
use Magento\Sales\Model\Order\Config;
2324
use Magento\Sales\Model\Order\Email\Sender\OrderCommentSender;
2425
use Magento\Sales\Model\Order\Status\History;
2526
use Magento\Sales\Model\OrderMutex;
@@ -28,12 +29,12 @@
2829
use PHPUnit\Framework\MockObject\MockObject;
2930
use PHPUnit\Framework\TestCase;
3031
use Psr\Log\LoggerInterface;
31-
use Magento\Framework\Phrase;
3232
use Magento\Framework\Exception\LocalizedException;
3333

3434
/**
3535
*
3636
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
37+
* @SuppressWarnings(PHPMD.TooManyFields)
3738
*/
3839
class OrderServiceTest extends TestCase
3940
{
@@ -112,6 +113,11 @@ class OrderServiceTest extends TestCase
112113
*/
113114
private $resourceConnectionMock;
114115

116+
/**
117+
* @var MockObject|Config
118+
*/
119+
private $orderConfigMock;
120+
115121
protected function setUp(): void
116122
{
117123
$this->orderRepositoryMock = $this->getMockBuilder(
@@ -189,6 +195,10 @@ protected function setUp(): void
189195
->disableOriginalConstructor()
190196
->getMock();
191197

198+
$this->orderConfigMock = $this->getMockBuilder(Config::class)
199+
->disableOriginalConstructor()
200+
->getMock();
201+
192202
$this->orderService = new OrderService(
193203
$this->orderRepositoryMock,
194204
$this->orderStatusHistoryRepositoryMock,
@@ -199,7 +209,8 @@ protected function setUp(): void
199209
$this->orderCommentSender,
200210
$paymentFailures,
201211
$logger,
202-
new OrderMutex($this->resourceConnectionMock)
212+
new OrderMutex($this->resourceConnectionMock),
213+
$this->orderConfigMock
203214
);
204215
}
205216

@@ -276,11 +287,15 @@ public function testGetCommentsList()
276287

277288
public function testAddComment()
278289
{
290+
$orderId = 123;
279291
$clearComment = "Comment text here...";
280-
$this->orderRepositoryMock->expects($this->once())
281-
->method('get')
282-
->with(123)
283-
->willReturn($this->orderMock);
292+
$this->mockCommentStatuses($orderId, Order::STATUS_FRAUD);
293+
$this->orderMock->expects($this->once())
294+
->method('setStatus')
295+
->willReturn(Order::STATUS_FRAUD);
296+
$this->orderStatusHistoryMock->expects($this->once())
297+
->method('setStatus')
298+
->willReturn(Order::STATUS_FRAUD);
284299
$this->orderMock->expects($this->once())
285300
->method('addStatusHistory')
286301
->with($this->orderStatusHistoryMock)
@@ -294,23 +309,52 @@ public function testAddComment()
294309
$this->orderCommentSender->expects($this->once())
295310
->method('send')
296311
->with($this->orderMock, false, $clearComment);
297-
$this->assertTrue($this->orderService->addComment(123, $this->orderStatusHistoryMock));
312+
$this->assertTrue($this->orderService->addComment($orderId, $this->orderStatusHistoryMock));
298313
}
299314

300315
/**
301316
* test for add comment with order status change case
302317
*/
303318
public function testAddCommentWithStatus()
304319
{
305-
$params = ['status' => 'holded'];
306-
$inputException = new LocalizedException(
307-
new Phrase('Unable to add comment: The status "%1" is not part of the order
308-
status history.', $params)
320+
$orderId = 123;
321+
$inputException = __(
322+
'Unable to add comment: The status "%1" is not part of the order status history.',
323+
Order::STATE_NEW
309324
);
310-
$this->orderStatusHistoryMock->method('getStatus')
311-
->willThrowException($inputException);
325+
$this->mockCommentStatuses($orderId, Order::STATE_NEW);
312326
$this->expectException(LocalizedException::class);
313-
$this->orderService->addComment(123, $this->orderStatusHistoryMock);
327+
$this->expectExceptionMessage((string)$inputException);
328+
$this->orderService->addComment($orderId, $this->orderStatusHistoryMock);
329+
}
330+
331+
/**
332+
* @param $orderId
333+
* @param $orderStatusHistory
334+
*/
335+
private function mockCommentStatuses($orderId, $orderStatusHistory): void
336+
{
337+
$this->orderRepositoryMock->expects($this->once())
338+
->method('get')
339+
->with($orderId)
340+
->willReturn($this->orderMock);
341+
$this->orderMock->expects($this->once())
342+
->method('getState')
343+
->willReturn(Order::STATE_PROCESSING);
344+
$this->orderConfigMock->expects($this->once())
345+
->method('getStateStatuses')
346+
->with(Order::STATE_PROCESSING)
347+
->willReturn([
348+
Order::STATE_PROCESSING => 'Processing',
349+
Order::STATUS_FRAUD => 'Suspected Fraud',
350+
'test' => 'Tests'
351+
]);
352+
$this->orderMock->expects($this->once())
353+
->method('getStatus')
354+
->willReturn(Order::STATE_PROCESSING);
355+
$this->orderStatusHistoryMock->expects($this->once())
356+
->method('getStatus')
357+
->willReturn($orderStatusHistory);
314358
}
315359

316360
public function testNotify()

0 commit comments

Comments
 (0)