Skip to content

Commit 44cd539

Browse files
authored
Merge branch '2.4-develop' into B2B-2033
2 parents 5846a93 + 62d8061 commit 44cd539

File tree

5 files changed

+119
-161
lines changed

5 files changed

+119
-161
lines changed

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/CatalogInventory/Model/ResourceModel/Indexer/Stock/DefaultStock.php

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,25 @@
66

77
namespace Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock;
88

9+
use Exception;
10+
use Magento\Catalog\Api\Data\ProductInterface;
911
use Magento\Catalog\Model\ResourceModel\Product\Indexer\AbstractIndexer;
12+
use Magento\CatalogInventory\Model\Configuration;
1013
use Magento\CatalogInventory\Model\Stock;
14+
use Magento\Eav\Model\Config;
15+
use Magento\Framework\App\Config\ScopeConfigInterface;
1116
use Magento\Framework\App\ObjectManager;
1217
use Magento\Framework\DB\Adapter\AdapterInterface;
1318
use Magento\CatalogInventory\Api\StockConfigurationInterface;
1419
use Magento\CatalogInventory\Model\Indexer\Stock\Action\Full;
1520
use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
21+
use Magento\Framework\DB\Select;
22+
use Magento\Framework\Exception\LocalizedException;
23+
use Magento\Framework\Indexer\Table\StrategyInterface;
24+
use Magento\Framework\Model\ResourceModel\Db\Context;
25+
use Magento\Store\Model\ScopeInterface;
26+
use PDO;
27+
use Zend_Db;
1628

1729
/**
1830
* CatalogInventory Default Stock Status Indexer Resource Model
@@ -37,7 +49,7 @@ class DefaultStock extends AbstractIndexer implements StockInterface
3749
protected $_isComposite = false;
3850

3951
/**
40-
* @var \Magento\Framework\App\Config\ScopeConfigInterface
52+
* @var ScopeConfigInterface
4153
*/
4254
protected $_scopeConfig;
4355

@@ -63,27 +75,35 @@ class DefaultStock extends AbstractIndexer implements StockInterface
6375
private $getStatusExpression;
6476

6577
/**
66-
* Class constructor
67-
*
68-
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
69-
* @param \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy
70-
* @param \Magento\Eav\Model\Config $eavConfig
71-
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
78+
* @param Context $context
79+
* @param StrategyInterface $tableStrategy
80+
* @param Config $eavConfig
81+
* @param ScopeConfigInterface $scopeConfig
7282
* @param string $connectionName
73-
* @param \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\GetStatusExpression|null $getStatusExpression
83+
* @param GetStatusExpression|null $getStatusExpression
84+
* @param StockConfigurationInterface|null $stockConfiguration
85+
* @param QueryProcessorComposite|null $queryProcessorComposite
7486
*/
7587
public function __construct(
76-
\Magento\Framework\Model\ResourceModel\Db\Context $context,
77-
\Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy,
78-
\Magento\Eav\Model\Config $eavConfig,
79-
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
88+
Context $context,
89+
StrategyInterface $tableStrategy,
90+
Config $eavConfig,
91+
ScopeConfigInterface $scopeConfig,
8092
$connectionName = null,
81-
\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\GetStatusExpression $getStatusExpression = null
93+
GetStatusExpression $getStatusExpression = null,
94+
StockConfigurationInterface $stockConfiguration = null,
95+
QueryProcessorComposite $queryProcessorComposite = null
8296
) {
8397
$this->_scopeConfig = $scopeConfig;
8498
parent::__construct($context, $tableStrategy, $eavConfig, $connectionName);
8599
$this->getStatusExpression = $getStatusExpression ?: ObjectManager::getInstance()->get(
86-
\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\GetStatusExpression::class
100+
GetStatusExpression::class
101+
);
102+
$this->stockConfiguration = $stockConfiguration ?: ObjectManager::getInstance()->get(
103+
StockConfigurationInterface::class
104+
);
105+
$this->queryProcessorComposite = $queryProcessorComposite ?: ObjectManager::getInstance()->get(
106+
QueryProcessorComposite::class
87107
);
88108
}
89109

@@ -101,7 +121,7 @@ protected function _construct()
101121
* Reindex all stock status data for default logic product type
102122
*
103123
* @return $this
104-
* @throws \Exception
124+
* @throws Exception
105125
*/
106126
public function reindexAll()
107127
{
@@ -110,7 +130,7 @@ public function reindexAll()
110130
try {
111131
$this->_prepareIndexTable();
112132
$this->commit();
113-
} catch (\Exception $e) {
133+
} catch (Exception $e) {
114134
$this->rollBack();
115135
throw $e;
116136
}
@@ -175,12 +195,12 @@ public function setTypeId($typeId)
175195
* Retrieve active Product Type Id
176196
*
177197
* @return string
178-
* @throws \Magento\Framework\Exception\LocalizedException
198+
* @throws LocalizedException
179199
*/
180200
public function getTypeId()
181201
{
182202
if ($this->_typeId === null) {
183-
throw new \Magento\Framework\Exception\LocalizedException(__('Undefined product type'));
203+
throw new LocalizedException(__('Undefined product type'));
184204
}
185205
return $this->_typeId;
186206
}
@@ -216,8 +236,8 @@ public function getIsComposite()
216236
protected function _isManageStock()
217237
{
218238
return $this->_scopeConfig->isSetFlag(
219-
\Magento\CatalogInventory\Model\Configuration::XML_PATH_MANAGE_STOCK,
220-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
239+
Configuration::XML_PATH_MANAGE_STOCK,
240+
ScopeInterface::SCOPE_STORE
221241
);
222242
}
223243

@@ -226,14 +246,14 @@ protected function _isManageStock()
226246
*
227247
* @param int|array $entityIds
228248
* @param bool $usePrimaryTable use primary or temporary index table
229-
* @return \Magento\Framework\DB\Select
249+
* @return Select
230250
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
231251
*/
232252
protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = false)
233253
{
234254
$connection = $this->getConnection();
235255
$qtyExpr = $connection->getCheckSql('cisi.qty > 0', 'cisi.qty', 0);
236-
$metadata = $this->getMetadataPool()->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
256+
$metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
237257
$linkField = $metadata->getLinkField();
238258

239259
$select = $connection->select()->from(
@@ -255,20 +275,20 @@ protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = f
255275
. ' AND mcpei.value = ' . ProductStatus::STATUS_ENABLED,
256276
[]
257277
)->joinLeft(
258-
['css' => 'cataloginventory_stock_status'],
278+
['css' => $this->getTable('cataloginventory_stock_status')],
259279
'css.product_id = e.entity_id',
260280
[]
261281
)->columns(
262282
['qty' => $qtyExpr]
263283
)->where(
264284
'cis.website_id = ?',
265-
$this->getStockConfiguration()->getDefaultScopeId()
285+
$this->stockConfiguration->getDefaultScopeId()
266286
)->where('e.type_id = ?', $this->getTypeId())
267287
->group(['e.entity_id', 'cis.website_id', 'cis.stock_id']);
268288

269289
$select->columns(['status' => $this->getStatusExpression($connection, true)]);
270290
if ($entityIds !== null) {
271-
$select->where('e.entity_id IN(?)', $entityIds, \Zend_Db::INT_TYPE);
291+
$select->where('e.entity_id IN(?)', $entityIds, Zend_Db::INT_TYPE);
272292
}
273293

274294
return $select;
@@ -284,7 +304,7 @@ protected function _prepareIndexTable($entityIds = null)
284304
{
285305
$connection = $this->getConnection();
286306
$select = $this->_getStockStatusSelect($entityIds, true);
287-
$select = $this->getQueryProcessorComposite()->processQuery($select, $entityIds);
307+
$select = $this->queryProcessorComposite->processQuery($select, $entityIds);
288308
$query = $select->insertFromSelect($this->getIdxTable());
289309
$connection->query($query);
290310

@@ -301,13 +321,13 @@ protected function _updateIndex($entityIds)
301321
{
302322
$connection = $this->getConnection();
303323
$select = $this->_getStockStatusSelect($entityIds, true);
304-
$select = $this->getQueryProcessorComposite()->processQuery($select, $entityIds, true);
324+
$select = $this->queryProcessorComposite->processQuery($select, $entityIds, true);
305325
$query = $connection->query($select);
306326

307327
$i = 0;
308328
$data = [];
309329
$savedEntityIds = [];
310-
while ($row = $query->fetch(\PDO::FETCH_ASSOC)) {
330+
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
311331
$i++;
312332
$data[] = [
313333
'product_id' => (int)$row['entity_id'],
@@ -336,7 +356,7 @@ protected function _updateIndex($entityIds)
336356
*
337357
* @param array $ids
338358
* @return void
339-
* @throws \Magento\Framework\Exception\LocalizedException
359+
* @throws LocalizedException
340360
*/
341361
private function deleteOldRecords(array $ids)
342362
{
@@ -398,24 +418,6 @@ protected function getStatusExpression(AdapterInterface $connection, $isAggregat
398418
*/
399419
protected function getStockConfiguration()
400420
{
401-
if ($this->stockConfiguration === null) {
402-
$this->stockConfiguration = \Magento\Framework\App\ObjectManager::getInstance()
403-
->get(\Magento\CatalogInventory\Api\StockConfigurationInterface::class);
404-
}
405421
return $this->stockConfiguration;
406422
}
407-
408-
/**
409-
* Get query processor composite
410-
*
411-
* @return QueryProcessorComposite
412-
*/
413-
private function getQueryProcessorComposite()
414-
{
415-
if (null === $this->queryProcessorComposite) {
416-
$this->queryProcessorComposite = \Magento\Framework\App\ObjectManager::getInstance()
417-
->get(\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\QueryProcessorComposite::class);
418-
}
419-
return $this->queryProcessorComposite;
420-
}
421423
}

app/code/Magento/CatalogUrlRewrite/Observer/AfterImportDataObserver.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class AfterImportDataObserver implements ObserverInterface
4646
/**
4747
* Url Key Attribute
4848
*/
49-
const URL_KEY_ATTRIBUTE_CODE = 'url_key';
49+
public const URL_KEY_ATTRIBUTE_CODE = 'url_key';
5050

5151
/**
5252
* @var StoreViewService
@@ -210,9 +210,10 @@ public function __construct(
210210
$this->storeManager = $storeManager;
211211
$this->urlRewriteFactory = $urlRewriteFactory;
212212
$this->urlFinder = $urlFinder;
213-
if (!isset($mergeDataProviderFactory)) {
214-
$mergeDataProviderFactory = ObjectManager::getInstance()->get(MergeDataProviderFactory::class);
215-
}
213+
214+
$mergeDataProviderFactory = $mergeDataProviderFactory ?: ObjectManager::getInstance()->get(
215+
MergeDataProviderFactory::class
216+
);
216217
$this->mergeDataProviderPrototype = $mergeDataProviderFactory->create();
217218
$this->categoryCollectionFactory = $categoryCollectionFactory ?:
218219
ObjectManager::getInstance()->get(CategoryCollectionFactory::class);

0 commit comments

Comments
 (0)