Skip to content

Commit 7404d9d

Browse files
authored
Merge pull request #5288 from magento-tsg/2.4-develop-pr7
[TSG] Fixes for 2.4 (pr7) (2.4-develop)
2 parents 1eef9bd + 7482c5e commit 7404d9d

File tree

20 files changed

+723
-63
lines changed

20 files changed

+723
-63
lines changed

app/code/Magento/Catalog/Model/Product/ProductFrontendAction/Synchronizer.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,16 @@ private function filterNewestActions(array $productsData, $typeId)
125125
$lifetime = $this->getLifeTimeByNamespace($typeId);
126126
$actionsNumber = $lifetime * self::TIME_TO_DO_ONE_ACTION;
127127

128-
uasort($productsData, function (array $firstProduct, array $secondProduct) {
129-
return $firstProduct['added_at'] > $secondProduct['added_at'];
130-
});
128+
uasort(
129+
$productsData,
130+
function (array $firstProduct, array $secondProduct) {
131+
if (isset($firstProduct['added_at'], $secondProduct['added_at'])) {
132+
return $firstProduct['added_at'] > $secondProduct['added_at'];
133+
}
134+
135+
return false;
136+
}
137+
);
131138

132139
return array_slice($productsData, 0, $actionsNumber, true);
133140
}
@@ -185,15 +192,17 @@ public function syncActions(array $productsData, $typeId)
185192

186193
foreach ($productsData as $productId => $productData) {
187194
/** @var ProductFrontendActionInterface $action */
188-
$action = $this->productFrontendActionFactory->create([
189-
'data' => [
190-
'visitor_id' => $customerId ? null : $visitorId,
191-
'customer_id' => $this->session->getCustomerId(),
192-
'added_at' => $productData['added_at'],
193-
'product_id' => $productId,
194-
'type_id' => $typeId
195+
$action = $this->productFrontendActionFactory->create(
196+
[
197+
'data' => [
198+
'visitor_id' => $customerId ? null : $visitorId,
199+
'customer_id' => $this->session->getCustomerId(),
200+
'added_at' => $productData['added_at'],
201+
'product_id' => $productId,
202+
'type_id' => $typeId
203+
]
195204
]
196-
]);
205+
);
197206

198207
$this->entityManager->save($action);
199208
}

app/code/Magento/Catalog/Setup/Patch/Data/UpdateDefaultAttributeValue.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Catalog\Setup\Patch\Data;
89

910
use Magento\Catalog\Setup\CategorySetup;
1011
use Magento\Catalog\Setup\CategorySetupFactory;
11-
use Magento\Framework\App\ResourceConnection;
1212
use Magento\Framework\Setup\ModuleDataSetupInterface;
1313
use Magento\Framework\Setup\Patch\DataPatchInterface;
1414
use Magento\Framework\Setup\Patch\PatchVersionInterface;
1515

1616
/**
17-
* Class UpdateDefaultAttributeValue
18-
* @package Magento\Catalog\Setup\Patch
17+
* Updates 'is_anchor' attribute default value.
1918
*/
2019
class UpdateDefaultAttributeValue implements DataPatchInterface, PatchVersionInterface
2120
{
@@ -30,7 +29,6 @@ class UpdateDefaultAttributeValue implements DataPatchInterface, PatchVersionInt
3029
private $categorySetupFactory;
3130

3231
/**
33-
* PatchInitial constructor.
3432
* @param ModuleDataSetupInterface $moduleDataSetup
3533
* @param CategorySetupFactory $categorySetupFactory
3634
*/
@@ -43,17 +41,24 @@ public function __construct(
4341
}
4442

4543
/**
46-
* {@inheritdoc}
44+
* @inheritdoc
4745
*/
4846
public function apply()
4947
{
5048
/** @var CategorySetup $categorySetup */
5149
$categorySetup = $this->categorySetupFactory->create(['setup' => $this->moduleDataSetup]);
52-
$categorySetup->updateAttribute(3, 54, 'default_value', 1);
50+
$categorySetup->updateAttribute(
51+
CategorySetup::CATEGORY_ENTITY_TYPE_ID,
52+
'is_anchor',
53+
'default_value',
54+
1
55+
);
56+
57+
return $this;
5358
}
5459

5560
/**
56-
* {@inheritdoc}
61+
* @inheritdoc
5762
*/
5863
public static function getDependencies()
5964
{
@@ -63,15 +68,15 @@ public static function getDependencies()
6368
}
6469

6570
/**
66-
* {@inheritdoc}
71+
* @inheritdoc
6772
*/
6873
public static function getVersion()
6974
{
7075
return '2.0.3';
7176
}
7277

7378
/**
74-
* {@inheritdoc}
79+
* @inheritdoc
7580
*/
7681
public function getAliases()
7782
{

app/code/Magento/Catalog/view/frontend/layout/default.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
<item name="updateRequestConfig" xsi:type="array">
2727
<item name="url" xsi:type="serviceUrl" path="/products-render-info"/>
2828
</item>
29+
<item name="requestConfig" xsi:type="array">
30+
<item name="syncUrl" xsi:type="url" path="catalog/product/frontend_action_synchronize"/>
31+
</item>
2932
</item>
3033
</argument>
3134
</arguments>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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\CatalogInventory\Model\Stock;
9+
10+
use Magento\CatalogInventory\Api\StockItemRepositoryInterface;
11+
use Magento\Framework\Stdlib\ArrayUtils;
12+
use Magento\CatalogInventory\Model\Stock\Item as StockItem;
13+
14+
/**
15+
* Verifies Stock item model changes.
16+
*/
17+
class StockItemChecker
18+
{
19+
/**
20+
* @var StockItemRepositoryInterface
21+
*/
22+
private $stockItemRepository;
23+
24+
/**
25+
* @var ArrayUtils
26+
*/
27+
private $arrayUtils;
28+
29+
/**
30+
* @var string[]
31+
*/
32+
private $skippedAttributes;
33+
34+
/**
35+
* @param StockItemRepositoryInterface $stockItemRepository
36+
* @param ArrayUtils $arrayUtils
37+
* @param string[] $skippedAttributes
38+
*/
39+
public function __construct(
40+
StockItemRepositoryInterface $stockItemRepository,
41+
ArrayUtils $arrayUtils,
42+
array $skippedAttributes = []
43+
) {
44+
$this->stockItemRepository = $stockItemRepository;
45+
$this->arrayUtils = $arrayUtils;
46+
$this->skippedAttributes = $skippedAttributes;
47+
}
48+
49+
/**
50+
* Check if stock item is modified.
51+
*
52+
* @param StockItem $model
53+
* @return bool
54+
*/
55+
public function isModified($model): bool
56+
{
57+
if (!$model->getId()) {
58+
return true;
59+
}
60+
$stockItem = $this->stockItemRepository->get($model->getId());
61+
$stockItemData = $stockItem->getData();
62+
$modelData = $model->getData();
63+
foreach ($this->skippedAttributes as $attribute) {
64+
unset($stockItemData[$attribute], $modelData[$attribute]);
65+
}
66+
$diff = $this->arrayUtils->recursiveDiff($stockItemData, $modelData);
67+
68+
return !empty($diff);
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminCatalogInventoryChangeManageStockActionGroup">
12+
<annotations>
13+
<description>Opens advanced inventory modal if it has not opened yet. Sets Manage stock value.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="manageStock" type="string" defaultValue="Yes"/>
17+
</arguments>
18+
<conditionalClick selector="{{AdminProductFormSection.advancedInventoryLink}}" dependentSelector="{{AdminProductFormAdvancedInventorySection.advancedInventoryModal}}" visible="false" stepKey="openAdvancedInventoryWindow"/>
19+
<waitForElementVisible selector="{{AdminProductFormAdvancedInventorySection.useConfigSettings}}" stepKey="waitForAdvancedInventoryModalWindowOpen"/>
20+
<uncheckOption selector="{{AdminProductFormAdvancedInventorySection.useConfigSettings}}" stepKey="uncheckManageStockConfigSetting"/>
21+
<selectOption selector="{{AdminProductFormAdvancedInventorySection.manageStock}}" userInput="{{manageStock}}" stepKey="changeManageStock"/>
22+
<click selector="{{AdminProductFormAdvancedInventorySection.doneButton}}" stepKey="clickDoneButton"/>
23+
</actionGroup>
24+
</actionGroups>
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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\CatalogInventory\Test\Unit\Model\Stock;
9+
10+
use Magento\CatalogInventory\Api\Data\StockItemInterface;
11+
use Magento\CatalogInventory\Model\Stock\StockItemChecker;
12+
use Magento\CatalogInventory\Model\Stock\Item as StockItem;
13+
use Magento\CatalogInventory\Model\Stock\StockItemRepository;
14+
use Magento\Framework\Stdlib\ArrayUtils;
15+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
16+
use PHPUnit\Framework\MockObject\MockObject;
17+
use PHPUnit\Framework\TestCase;
18+
19+
/**
20+
* Unit test for StockItemChecker.
21+
* @see StockItemChecker
22+
*/
23+
class StockItemCheckerTest extends TestCase
24+
{
25+
/**
26+
* @var StockItemChecker
27+
*/
28+
private $model;
29+
30+
/**
31+
* @var StockItemRepository|MockObject
32+
*/
33+
private $stockItemRepository;
34+
35+
/**
36+
* @var StockItem|MockObject
37+
*/
38+
private $stockItemModel;
39+
40+
/**
41+
* @var ArrayUtils
42+
*/
43+
private $arrayUtils;
44+
45+
/**
46+
* @inheritdoc
47+
*/
48+
protected function setUp()
49+
{
50+
$objectManager = new ObjectManager($this);
51+
52+
$this->stockItemRepository = $this->createPartialMock(StockItemRepository::class, ['get']);
53+
$this->arrayUtils = $objectManager->getObject(ArrayUtils::class);
54+
$this->stockItemModel = $this->createPartialMock(StockItem::class, ['getId', 'getData']);
55+
56+
$this->model = $objectManager->getObject(
57+
StockItemChecker::class,
58+
[
59+
'stockItemRepository' => $this->stockItemRepository,
60+
'arrayUtils' => $this->arrayUtils,
61+
'skippedAttributes' => [StockItemInterface::LOW_STOCK_DATE],
62+
]
63+
);
64+
}
65+
66+
/**
67+
* Test for isModified method when model is new.
68+
*
69+
* @return void
70+
*/
71+
public function testIsModifiedWhenModelIsNew(): void
72+
{
73+
$this->stockItemModel->expects($this->once())->method('getId')->willReturn(null);
74+
$this->stockItemRepository->expects($this->never())->method('get');
75+
76+
$this->assertTrue($this->model->isModified($this->stockItemModel));
77+
}
78+
79+
/**
80+
* Test for isModified method when found difference between data.
81+
*
82+
* @param array $itemFromRepository
83+
* @param array $model
84+
* @param bool $expectedResult
85+
* @return void
86+
* @dataProvider stockItemModelDataProvider
87+
*/
88+
public function testIsModified(
89+
array $itemFromRepository,
90+
array $model,
91+
bool $expectedResult
92+
): void {
93+
$this->stockItemModel->expects($this->exactly(2))->method('getId')->willReturn($model['id']);
94+
$this->stockItemRepository->expects($this->once())->method('get')->willReturn($this->stockItemModel);
95+
$this->stockItemModel->expects($this->exactly(2))
96+
->method('getData')
97+
->willReturnOnConsecutiveCalls($itemFromRepository, $model);
98+
99+
$this->assertEquals($expectedResult, $this->model->isModified($this->stockItemModel));
100+
}
101+
102+
/**
103+
* Data provider for testIsModified.
104+
*
105+
* @return array
106+
*/
107+
public function stockItemModelDataProvider(): array
108+
{
109+
return [
110+
'Model is modified' => [
111+
'stockItemFromRepository' => [
112+
'id' => 1,
113+
'low_stock_date' => '01.01.2020',
114+
'qty' => 100,
115+
],
116+
'model' => [
117+
'id' => 1,
118+
'low_stock_date' => '01.01.2021',
119+
'qty' => 99,
120+
],
121+
'expectedResult' => true,
122+
],
123+
'Model is not modified' => [
124+
'stockItemFromRepository' => [
125+
'id' => 1,
126+
'low_stock_date' => '01.01.2020',
127+
'qty' => 100,
128+
],
129+
'model' => [
130+
'id' => 1,
131+
'low_stock_date' => '01.01.2021',
132+
'qty' => 100,
133+
],
134+
'expectedResult' => false,
135+
],
136+
];
137+
}
138+
}

app/code/Magento/CatalogInventory/Ui/DataProvider/Product/Form/Modifier/AdvancedInventory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ private function prepareMeta()
242242
'handleChanges' => '${$.provider}:data.product.stock_data.is_qty_decimal',
243243
],
244244
'sortOrder' => 10,
245+
'disabled' => $this->locator->getProduct()->isLockedAttribute($fieldCode),
245246
];
246247
$advancedInventoryButton['arguments']['data']['config'] = [
247248
'displayAsLink' => true,

0 commit comments

Comments
 (0)