Skip to content

Commit a80350a

Browse files
committed
Merge remote-tracking branch 'origin/2.4-develop' into MC-34292
2 parents 98f0643 + 68c903f commit a80350a

File tree

55 files changed

+1003
-183
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1003
-183
lines changed

app/code/Magento/AdminNotification/Block/ToolbarEntry.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
* Toolbar entry that shows latest notifications
1111
*
1212
* @api
13-
* @author Magento Core Team <[email protected]>
1413
* @since 100.0.2
1514
*/
1615
class ToolbarEntry extends \Magento\Backend\Block\Template

app/code/Magento/AdminNotification/Model/Feed.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
/**
1313
* AdminNotification Feed model
1414
*
15-
* @author Magento Core Team <[email protected]>
1615
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1716
* @api
1817
* @since 100.0.2

app/code/Magento/AdminNotification/Model/InboxInterface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
/**
99
* AdminNotification Inbox interface
1010
*
11-
* @author Magento Core Team <[email protected]>
1211
* @api
1312
* @since 100.0.2
1413
*/

app/code/Magento/AdminNotification/Model/NotificationService.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
/**
99
* Notification service model
1010
*
11-
* @author Magento Core Team <[email protected]>
1211
* @api
1312
* @since 100.0.2
1413
*/

app/code/Magento/AdminNotification/Model/ResourceModel/Grid/Collection.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
/**
88
* AdminNotification Inbox model
9-
*
10-
* @author Magento Core Team <[email protected]>
119
*/
1210
namespace Magento\AdminNotification\Model\ResourceModel\Grid;
1311

app/code/Magento/AdminNotification/Model/ResourceModel/Inbox/Collection.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* AdminNotification Inbox model
1010
*
1111
* @api
12-
* @author Magento Core Team <[email protected]>
13-
* @api
1412
* @since 100.0.2
1513
*/
1614
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection

app/code/Magento/AdminNotification/Model/ResourceModel/Inbox/Collection/Unread.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
/**
88
* Collection of unread notifications
9-
*
10-
* @author Magento Core Team <[email protected]>
119
*/
1210
namespace Magento\AdminNotification\Model\ResourceModel\Inbox\Collection;
1311

app/code/Magento/AdminNotification/Observer/PredispatchAdminActionControllerObserver.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
/**
1111
* AdminNotification observer
12-
*
13-
* @author Magento Core Team <[email protected]>
12+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1413
*/
1514
class PredispatchAdminActionControllerObserver implements ObserverInterface
1615
{

app/code/Magento/AdvancedSearch/Block/Adminhtml/Search/Edit.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* Search queries relations grid container
1010
*
1111
* @api
12-
* @author Magento Core Team <[email protected]>
1312
* @since 100.0.2
1413
*/
1514
class Edit extends \Magento\Backend\Block\Widget\Grid\Container

app/code/Magento/AdvancedSearch/Block/Adminhtml/Search/Grid.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* Search query relations edit grid
1010
*
1111
* @api
12-
* @author Magento Core Team <[email protected]>
1312
* @since 100.0.2
1413
*/
1514
class Grid extends \Magento\Backend\Block\Widget\Grid

app/code/Magento/AdvancedSearch/Model/ResourceModel/Recommendations.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
/**
99
* Catalog search recommendations resource model
1010
*
11-
* @author Magento Core Team <[email protected]>
1211
* @api
1312
* @since 100.0.2
1413
*/

app/code/Magento/Catalog/Model/CategoryRepository.php

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77

88
namespace Magento\Catalog\Model;
99

10+
use Magento\Catalog\Model\CategoryRepository\PopulateWithValues;
11+
use Magento\Catalog\Model\ResourceModel\Category as CategoryResource;
12+
use Magento\Framework\Api\ExtensibleDataObjectConverter;
13+
use Magento\Framework\App\ObjectManager;
14+
use Magento\Framework\EntityManager\MetadataPool;
1015
use Magento\Framework\Exception\CouldNotSaveException;
1116
use Magento\Framework\Exception\NoSuchEntityException;
1217
use Magento\Framework\Exception\StateException;
1318
use Magento\Catalog\Api\Data\CategoryInterface;
19+
use Magento\Store\Model\StoreManagerInterface;
1420

1521
/**
1622
* Repository for categories.
@@ -25,27 +31,27 @@ class CategoryRepository implements \Magento\Catalog\Api\CategoryRepositoryInter
2531
protected $instances = [];
2632

2733
/**
28-
* @var \Magento\Store\Model\StoreManagerInterface
34+
* @var StoreManagerInterface
2935
*/
3036
protected $storeManager;
3137

3238
/**
33-
* @var \Magento\Catalog\Model\CategoryFactory
39+
* @var CategoryFactory
3440
*/
3541
protected $categoryFactory;
3642

3743
/**
38-
* @var \Magento\Catalog\Model\ResourceModel\Category
44+
* @var CategoryResource
3945
*/
4046
protected $categoryResource;
4147

4248
/**
43-
* @var \Magento\Framework\EntityManager\MetadataPool
49+
* @var MetadataPool
4450
*/
4551
protected $metadataPool;
4652

4753
/**
48-
* @var \Magento\Framework\Api\ExtensibleDataObjectConverter
54+
* @var ExtensibleDataObjectConverter
4955
*/
5056
private $extensibleDataObjectConverter;
5157

@@ -57,28 +63,37 @@ class CategoryRepository implements \Magento\Catalog\Api\CategoryRepositoryInter
5763
protected $useConfigFields = ['available_sort_by', 'default_sort_by', 'filter_price_range'];
5864

5965
/**
60-
* @param \Magento\Catalog\Model\CategoryFactory $categoryFactory
61-
* @param \Magento\Catalog\Model\ResourceModel\Category $categoryResource
62-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
66+
* @var PopulateWithValues
67+
*/
68+
private $populateWithValues;
69+
70+
/**
71+
* @param CategoryFactory $categoryFactory
72+
* @param CategoryResource $categoryResource
73+
* @param StoreManagerInterface $storeManager
74+
* @param PopulateWithValues|null $populateWithValues
6375
*/
6476
public function __construct(
65-
\Magento\Catalog\Model\CategoryFactory $categoryFactory,
66-
\Magento\Catalog\Model\ResourceModel\Category $categoryResource,
67-
\Magento\Store\Model\StoreManagerInterface $storeManager
77+
CategoryFactory $categoryFactory,
78+
CategoryResource $categoryResource,
79+
StoreManagerInterface $storeManager,
80+
?PopulateWithValues $populateWithValues
6881
) {
6982
$this->categoryFactory = $categoryFactory;
7083
$this->categoryResource = $categoryResource;
7184
$this->storeManager = $storeManager;
85+
$objectManager = ObjectManager::getInstance();
86+
$this->populateWithValues = $populateWithValues ?? $objectManager->get(PopulateWithValues::class);
7287
}
7388

7489
/**
7590
* @inheritdoc
7691
*/
77-
public function save(\Magento\Catalog\Api\Data\CategoryInterface $category)
92+
public function save(CategoryInterface $category)
7893
{
7994
$storeId = (int)$this->storeManager->getStore()->getId();
8095
$existingData = $this->getExtensibleDataObjectConverter()
81-
->toNestedArray($category, [], \Magento\Catalog\Api\Data\CategoryInterface::class);
96+
->toNestedArray($category, [], CategoryInterface::class);
8297
$existingData = array_diff_key($existingData, array_flip(['path', 'level', 'parent_id']));
8398
$existingData['store_id'] = $storeId;
8499

@@ -110,7 +125,7 @@ public function save(\Magento\Catalog\Api\Data\CategoryInterface $category)
110125
$existingData['parent_id'] = $parentId;
111126
$existingData['level'] = null;
112127
}
113-
$category->addData($existingData);
128+
$this->populateWithValues->execute($category, $existingData);
114129
try {
115130
$this->validateCategory($category);
116131
$this->categoryResource->save($category);
@@ -151,7 +166,7 @@ public function get($categoryId, $storeId = null)
151166
/**
152167
* @inheritdoc
153168
*/
154-
public function delete(\Magento\Catalog\Api\Data\CategoryInterface $category)
169+
public function delete(CategoryInterface $category)
155170
{
156171
try {
157172
$categoryId = $category->getId();
@@ -213,29 +228,29 @@ protected function validateCategory(Category $category)
213228
/**
214229
* Lazy loader for the converter.
215230
*
216-
* @return \Magento\Framework\Api\ExtensibleDataObjectConverter
231+
* @return ExtensibleDataObjectConverter
217232
*
218233
* @deprecated 101.0.0
219234
*/
220235
private function getExtensibleDataObjectConverter()
221236
{
222237
if ($this->extensibleDataObjectConverter === null) {
223-
$this->extensibleDataObjectConverter = \Magento\Framework\App\ObjectManager::getInstance()
224-
->get(\Magento\Framework\Api\ExtensibleDataObjectConverter::class);
238+
$this->extensibleDataObjectConverter = ObjectManager::getInstance()
239+
->get(ExtensibleDataObjectConverter::class);
225240
}
226241
return $this->extensibleDataObjectConverter;
227242
}
228243

229244
/**
230245
* Lazy loader for the metadata pool.
231246
*
232-
* @return \Magento\Framework\EntityManager\MetadataPool
247+
* @return MetadataPool
233248
*/
234249
private function getMetadataPool()
235250
{
236251
if (null === $this->metadataPool) {
237-
$this->metadataPool = \Magento\Framework\App\ObjectManager::getInstance()
238-
->get(\Magento\Framework\EntityManager\MetadataPool::class);
252+
$this->metadataPool = ObjectManager::getInstance()
253+
->get(MetadataPool::class);
239254
}
240255
return $this->metadataPool;
241256
}
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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\Catalog\Model\CategoryRepository;
9+
10+
use Magento\Catalog\Api\Data\CategoryInterface;
11+
use Magento\Catalog\Model\Attribute\ScopeOverriddenValue;
12+
use Magento\Catalog\Model\Category;
13+
use Magento\Catalog\Api\CategoryAttributeRepositoryInterface as AttributeRepository;
14+
use Magento\Eav\Api\Data\AttributeInterface;
15+
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
16+
use Magento\Framework\Api\FilterBuilder;
17+
use Magento\Framework\Api\SearchCriteriaBuilder;
18+
use Magento\Store\Model\Store;
19+
20+
/**
21+
* Add data to category entity and populate with default values
22+
*/
23+
class PopulateWithValues
24+
{
25+
/**
26+
* @var ScopeOverriddenValue
27+
*/
28+
private $scopeOverriddenValue;
29+
30+
/**
31+
* @var AttributeRepository
32+
*/
33+
private $attributeRepository;
34+
35+
/**
36+
* @var SearchCriteriaBuilder
37+
*/
38+
private $searchCriteriaBuilder;
39+
40+
/**
41+
* @var FilterBuilder
42+
*/
43+
private $filterBuilder;
44+
45+
/**
46+
* @var AttributeInterface[]
47+
*/
48+
private $attributes;
49+
50+
/**
51+
* @param ScopeOverriddenValue $scopeOverriddenValue
52+
* @param AttributeRepository $attributeRepository
53+
* @param SearchCriteriaBuilder $searchCriteriaBuilder
54+
* @param FilterBuilder $filterBuilder
55+
*/
56+
public function __construct(
57+
ScopeOverriddenValue $scopeOverriddenValue,
58+
AttributeRepository $attributeRepository,
59+
SearchCriteriaBuilder $searchCriteriaBuilder,
60+
FilterBuilder $filterBuilder
61+
) {
62+
$this->scopeOverriddenValue = $scopeOverriddenValue;
63+
$this->attributeRepository = $attributeRepository;
64+
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
65+
$this->filterBuilder = $filterBuilder;
66+
}
67+
68+
/**
69+
* Set null to entity default values
70+
*
71+
* @param CategoryInterface $category
72+
* @param array $existingData
73+
* @return void
74+
*/
75+
public function execute(CategoryInterface $category, array $existingData): void
76+
{
77+
$storeId = $existingData['store_id'] ?? Store::DEFAULT_STORE_ID;
78+
if ((int)$storeId !== Store::DEFAULT_STORE_ID) {
79+
$overriddenValues = array_filter(
80+
$category->getData(),
81+
function ($key) use ($category, $storeId) {
82+
/** @var Category $category */
83+
return $this->scopeOverriddenValue->containsValue(
84+
CategoryInterface::class,
85+
$category,
86+
$key,
87+
$storeId
88+
);
89+
},
90+
ARRAY_FILTER_USE_KEY
91+
);
92+
$defaultValues = array_diff_key($category->getData(), $overriddenValues);
93+
array_walk(
94+
$defaultValues,
95+
function (&$value, $key) {
96+
$attributes = $this->getAttributes();
97+
if (isset($attributes[$key]) && !$attributes[$key]->isStatic()) {
98+
$value = null;
99+
}
100+
}
101+
);
102+
$category->addData($defaultValues);
103+
}
104+
105+
$category->addData($existingData);
106+
$useDefaultAttributes = array_filter(
107+
$category->getData(),
108+
function ($attributeValue) {
109+
return null === $attributeValue;
110+
}
111+
);
112+
$category->setData(
113+
'use_default',
114+
array_map(
115+
function () {
116+
return true;
117+
},
118+
$useDefaultAttributes
119+
)
120+
);
121+
}
122+
123+
/**
124+
* Returns entity attributes.
125+
*
126+
* @return AttributeInterface[]
127+
*/
128+
private function getAttributes(): array
129+
{
130+
if ($this->attributes) {
131+
return $this->attributes;
132+
}
133+
134+
$searchResult = $this->attributeRepository->getList(
135+
$this->searchCriteriaBuilder->addFilters(
136+
[
137+
$this->filterBuilder
138+
->setField('is_global')
139+
->setConditionType('in')
140+
->setValue([ScopedAttributeInterface::SCOPE_STORE, ScopedAttributeInterface::SCOPE_WEBSITE])
141+
->create()
142+
]
143+
)->create()
144+
);
145+
146+
$this->attributes = [];
147+
foreach ($searchResult->getItems() as $attribute) {
148+
$this->attributes[$attribute->getAttributeCode()] = $attribute;
149+
}
150+
151+
return $this->attributes;
152+
}
153+
}

0 commit comments

Comments
 (0)