Skip to content

Commit 4298a99

Browse files
committed
Merge remote-tracking branch 'commerce/2.4-develop' into ph-delivery
2 parents 7bb21fe + f3e2166 commit 4298a99

File tree

38 files changed

+1101
-235
lines changed

38 files changed

+1101
-235
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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\Product;
9+
10+
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
11+
use Magento\Eav\Model\ReservedAttributeCheckerInterface;
12+
13+
/**
14+
* Adapter for \Magento\Catalog\Model\Product\ReservedAttributeList
15+
*
16+
* Is created to implement proper interface and to use api class ReservedAttributeList
17+
* while keeping it backward compatible
18+
* @see \Magento\Catalog\Model\Product\ReservedAttributeList
19+
*/
20+
class ReservedAttributeCheckerAdapter implements ReservedAttributeCheckerInterface
21+
{
22+
/**
23+
* @var ReservedAttributeList
24+
*/
25+
private $reservedAttributeList;
26+
27+
/**
28+
* @param ReservedAttributeList $reservedAttributeList
29+
*/
30+
public function __construct(
31+
ReservedAttributeList $reservedAttributeList
32+
) {
33+
$this->reservedAttributeList = $reservedAttributeList;
34+
}
35+
36+
/**
37+
* @inheritdoc
38+
*/
39+
public function isReservedAttribute(AbstractAttribute $attribute): bool
40+
{
41+
return $this->reservedAttributeList->isReservedAttribute($attribute);
42+
}
43+
}

app/code/Magento/Catalog/Model/ResourceModel/Category.php

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Category extends AbstractResource
5555
protected $_isActiveAttributeId = null;
5656

5757
/**
58-
* Store id
58+
* Id of store
5959
*
6060
* @var int
6161
*/
@@ -69,14 +69,14 @@ class Category extends AbstractResource
6969
protected $_eventManager = null;
7070

7171
/**
72-
* Category collection factory
72+
* Collection factory of category
7373
*
7474
* @var \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory
7575
*/
7676
protected $_categoryCollectionFactory;
7777

7878
/**
79-
* Category tree factory
79+
* Tree factory of category
8080
*
8181
* @var \Magento\Catalog\Model\ResourceModel\Category\TreeFactory
8282
*/
@@ -103,7 +103,6 @@ class Category extends AbstractResource
103103
private $metadataPool;
104104

105105
/**
106-
* Category constructor.
107106
* @param \Magento\Eav\Model\Entity\Context $context
108107
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
109108
* @param \Magento\Catalog\Model\Factory $modelFactory
@@ -114,6 +113,8 @@ class Category extends AbstractResource
114113
* @param array $data
115114
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
116115
* @param MetadataPool|null $metadataPool
116+
* @param EntityManager|null $entityManager
117+
* @param Category\AggregateCount|null $aggregateCount
117118
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
118119
*/
119120
public function __construct(
@@ -126,7 +127,9 @@ public function __construct(
126127
Processor $indexerProcessor,
127128
$data = [],
128129
\Magento\Framework\Serialize\Serializer\Json $serializer = null,
129-
MetadataPool $metadataPool = null
130+
MetadataPool $metadataPool = null,
131+
\Magento\Framework\EntityManager\EntityManager $entityManager = null,
132+
\Magento\Catalog\Model\ResourceModel\Category\AggregateCount $aggregateCount = null
130133
) {
131134
parent::__construct(
132135
$context,
@@ -142,6 +145,10 @@ public function __construct(
142145
$this->serializer = $serializer ?: ObjectManager::getInstance()
143146
->get(\Magento\Framework\Serialize\Serializer\Json::class);
144147
$this->metadataPool = $metadataPool ?: ObjectManager::getInstance()->get(MetadataPool::class);
148+
$this->entityManager = $entityManager ?: ObjectManager::getInstance()
149+
->get(\Magento\Framework\EntityManager\EntityManager::class);
150+
$this->aggregateCount = $aggregateCount ?: ObjectManager::getInstance()
151+
->get(\Magento\Catalog\Model\ResourceModel\Category\AggregateCount::class);
145152
}
146153

147154
/**
@@ -220,7 +227,7 @@ protected function _getTree()
220227
protected function _beforeDelete(\Magento\Framework\DataObject $object)
221228
{
222229
parent::_beforeDelete($object);
223-
$this->getAggregateCount()->processDelete($object);
230+
$this->aggregateCount->processDelete($object);
224231
$this->deleteChildren($object);
225232
}
226233

@@ -1092,8 +1099,8 @@ public function load($object, $entityId, $attributes = [])
10921099
}
10931100

10941101
$this->loadAttributesForObject($attributes, $object);
1095-
$object = $this->getEntityManager()->load($object, $entityId);
1096-
if (!$this->getEntityManager()->has($object)) {
1102+
$object = $this->entityManager->load($object, $entityId);
1103+
if (!$this->entityManager->has($object)) {
10971104
$object->isObjectNew(true);
10981105
}
10991106
return $this;
@@ -1104,7 +1111,7 @@ public function load($object, $entityId, $attributes = [])
11041111
*/
11051112
public function delete($object)
11061113
{
1107-
$this->getEntityManager()->delete($object);
1114+
$this->entityManager->delete($object);
11081115
$this->_eventManager->dispatch(
11091116
'catalog_category_delete_after_done',
11101117
['product' => $object, 'category' => $object]
@@ -1121,38 +1128,10 @@ public function delete($object)
11211128
*/
11221129
public function save(\Magento\Framework\Model\AbstractModel $object)
11231130
{
1124-
$this->getEntityManager()->save($object);
1131+
$this->entityManager->save($object);
11251132
return $this;
11261133
}
11271134

1128-
/**
1129-
* Returns EntityManager object
1130-
*
1131-
* @return EntityManager
1132-
*/
1133-
private function getEntityManager()
1134-
{
1135-
if (null === $this->entityManager) {
1136-
$this->entityManager = \Magento\Framework\App\ObjectManager::getInstance()
1137-
->get(\Magento\Framework\EntityManager\EntityManager::class);
1138-
}
1139-
return $this->entityManager;
1140-
}
1141-
1142-
/**
1143-
* Returns AggregateCount object
1144-
*
1145-
* @return Category\AggregateCount
1146-
*/
1147-
private function getAggregateCount()
1148-
{
1149-
if (null === $this->aggregateCount) {
1150-
$this->aggregateCount = \Magento\Framework\App\ObjectManager::getInstance()
1151-
->get(\Magento\Catalog\Model\ResourceModel\Category\AggregateCount::class);
1152-
}
1153-
return $this->aggregateCount;
1154-
}
1155-
11561135
/**
11571136
* Get category with children.
11581137
*

app/code/Magento/Catalog/etc/di.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
<preference for="Magento\Catalog\Model\Indexer\Product\Price\UpdateIndexInterface" type="Magento\Catalog\Model\Indexer\Product\Price\InvalidateIndex" />
7474
<preference for="Magento\Catalog\Model\Product\Gallery\ImagesConfigFactoryInterface" type="Magento\Catalog\Model\Product\Gallery\ImagesConfigFactory" />
7575
<preference for="Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface" type="Magento\Catalog\Model\Product\Configuration\Item\ItemResolverComposite" />
76-
<preference for="Magento\Catalog\Api\Data\MassActionInterface" type="\Magento\Catalog\Model\MassAction" />
76+
<preference for="Magento\Catalog\Api\Data\MassActionInterface" type="Magento\Catalog\Model\MassAction" />
7777
<preference for="Magento\Catalog\Model\ProductLink\Data\ListCriteriaInterface" type="Magento\Catalog\Model\ProductLink\Data\ListCriteria" />
7878
<preference for="Magento\Catalog\Api\CategoryListDeleteBySkuInterface" type="Magento\Catalog\Model\CategoryLinkRepository"/>
7979
<type name="Magento\Customer\Model\ResourceModel\Visitor">
@@ -1333,4 +1333,13 @@
13331333
<argument name="imageResizeScheduler" xsi:type="object">Magento\MediaStorage\Service\ImageResizeScheduler\Proxy</argument>
13341334
</arguments>
13351335
</type>
1336+
<type name="Magento\Eav\Model\ReservedAttributeChecker">
1337+
<arguments>
1338+
<argument name="validators" xsi:type="array">
1339+
<item name="catalog_product" xsi:type="array">
1340+
<item name="product_reserved_attribute_codes" xsi:type="object">\Magento\Catalog\Model\Product\ReservedAttributeCheckerAdapter</item>
1341+
</item>
1342+
</argument>
1343+
</arguments>
1344+
</type>
13361345
</config>

0 commit comments

Comments
 (0)