Skip to content

Commit 706af91

Browse files
author
Valeriy Nayda
committed
Merge remote-tracking branch 'origin/2.3-develop' into 55-56-account-mutations
# Conflicts: # app/code/Magento/CustomerGraphQl/etc/schema.graphqls
2 parents 661988b + 80469a6 commit 706af91

File tree

109 files changed

+2289
-1330
lines changed

Some content is hidden

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

109 files changed

+2289
-1330
lines changed

app/code/Magento/Backend/view/adminhtml/templates/system/search.phtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<% if (data.items.length) { %>
4343
<% _.each(data.items, function(value){ %>
4444
<li class="item"
45-
<%- data.optionData(value) %>
45+
<%= data.optionData(value) %>
4646
>
4747
<a href="<%- value.url %>" class="title"><%- value.name %></a>
4848
<span class="type"><%- value.type %></span>

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

+9-4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements
7272

7373
const CACHE_TAG = 'cat_c';
7474

75+
/**
76+
* Category Store Id
77+
*/
78+
const STORE_ID = 'store_id';
79+
7580
/**#@-*/
7681
protected $_eventPrefix = 'catalog_category';
7782

@@ -564,12 +569,12 @@ public function getStoreIds()
564569
*
565570
* If store id is underfined for category return current active store id
566571
*
567-
* @return integer
572+
* @return int
568573
*/
569574
public function getStoreId()
570575
{
571-
if ($this->hasData('store_id')) {
572-
return (int)$this->_getData('store_id');
576+
if ($this->hasData(self::STORE_ID)) {
577+
return (int)$this->_getData(self::STORE_ID);
573578
}
574579
return (int)$this->_storeManager->getStore()->getId();
575580
}
@@ -585,7 +590,7 @@ public function setStoreId($storeId)
585590
if (!is_numeric($storeId)) {
586591
$storeId = $this->_storeManager->getStore($storeId)->getId();
587592
}
588-
$this->setData('store_id', $storeId);
593+
$this->setData(self::STORE_ID, $storeId);
589594
$this->getResource()->setStoreId($storeId);
590595
return $this;
591596
}

app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action/Indexer.php

+19-21
Original file line numberDiff line numberDiff line change
@@ -56,39 +56,36 @@ public function __construct(
5656
* @return \Magento\Catalog\Model\Indexer\Product\Flat
5757
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
5858
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
59+
* @SuppressWarnings(PHPMD.NPathComplexity)
5960
*/
6061
public function write($storeId, $productId, $valueFieldSuffix = '')
6162
{
6263
$flatTable = $this->_productIndexerHelper->getFlatTableName($storeId);
64+
$entityTableName = $this->_productIndexerHelper->getTable('catalog_product_entity');
6365

6466
$attributes = $this->_productIndexerHelper->getAttributes();
6567
$eavAttributes = $this->_productIndexerHelper->getTablesStructure($attributes);
6668
$updateData = [];
6769
$describe = $this->_connection->describeTable($flatTable);
70+
$metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
71+
$linkField = $metadata->getLinkField();
6872

6973
foreach ($eavAttributes as $tableName => $tableColumns) {
7074
$columnsChunks = array_chunk($tableColumns, self::ATTRIBUTES_CHUNK_SIZE, true);
7175

7276
foreach ($columnsChunks as $columns) {
7377
$select = $this->_connection->select();
74-
$selectValue = $this->_connection->select();
75-
$keyColumns = [
76-
'entity_id' => 'e.entity_id',
77-
'attribute_id' => 't.attribute_id',
78-
'value' => $this->_connection->getIfNullSql('`t2`.`value`', '`t`.`value`'),
79-
];
80-
81-
if ($tableName != $this->_productIndexerHelper->getTable('catalog_product_entity')) {
78+
79+
if ($tableName != $entityTableName) {
8280
$valueColumns = [];
8381
$ids = [];
8482
$select->from(
85-
['e' => $this->_productIndexerHelper->getTable('catalog_product_entity')],
86-
$keyColumns
87-
);
88-
89-
$selectValue->from(
90-
['e' => $this->_productIndexerHelper->getTable('catalog_product_entity')],
91-
$keyColumns
83+
['e' => $entityTableName],
84+
[
85+
'entity_id' => 'e.entity_id',
86+
'attribute_id' => 't.attribute_id',
87+
'value' => $this->_connection->getIfNullSql('`t2`.`value`', '`t`.`value`'),
88+
]
9289
);
9390

9491
/** @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */
@@ -97,8 +94,7 @@ public function write($storeId, $productId, $valueFieldSuffix = '')
9794
$ids[$attribute->getId()] = $columnName;
9895
}
9996
}
100-
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
101-
$select->joinLeft(
97+
$select->joinInner(
10298
['t' => $tableName],
10399
sprintf('e.%s = t.%s ', $linkField, $linkField) . $this->_connection->quoteInto(
104100
' AND t.attribute_id IN (?)',
@@ -116,8 +112,6 @@ public function write($storeId, $productId, $valueFieldSuffix = '')
116112
[]
117113
)->where(
118114
'e.entity_id = ' . $productId
119-
)->where(
120-
't.attribute_id IS NOT NULL'
121115
);
122116
$cursor = $this->_connection->query($select);
123117
while ($row = $cursor->fetch(\Zend_Db::FETCH_ASSOC)) {
@@ -157,7 +151,7 @@ public function write($storeId, $productId, $valueFieldSuffix = '')
157151
$columnNames[] = 'attribute_set_id';
158152
$columnNames[] = 'type_id';
159153
$select->from(
160-
['e' => $this->_productIndexerHelper->getTable('catalog_product_entity')],
154+
['e' => $entityTableName],
161155
$columnNames
162156
)->where(
163157
'e.entity_id = ' . $productId
@@ -175,7 +169,9 @@ public function write($storeId, $productId, $valueFieldSuffix = '')
175169

176170
if (!empty($updateData)) {
177171
$updateData += ['entity_id' => $productId];
178-
$updateData += ['row_id' => $productId];
172+
if ($linkField !== $metadata->getIdentifierField()) {
173+
$updateData += [$linkField => $productId];
174+
}
179175
$updateFields = [];
180176
foreach ($updateData as $key => $value) {
181177
$updateFields[$key] = $key;
@@ -187,6 +183,8 @@ public function write($storeId, $productId, $valueFieldSuffix = '')
187183
}
188184

189185
/**
186+
* Get MetadataPool instance
187+
*
190188
* @return \Magento\Framework\EntityManager\MetadataPool
191189
*/
192190
private function getMetadataPool()

app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action/Row.php

+39-30
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@
55
*/
66
namespace Magento\Catalog\Model\Indexer\Product\Flat\Action;
77

8+
use Magento\Catalog\Api\Data\ProductInterface;
89
use Magento\Catalog\Model\Indexer\Product\Flat\FlatTableBuilder;
910
use Magento\Catalog\Model\Indexer\Product\Flat\TableBuilder;
11+
use Magento\Framework\EntityManager\MetadataPool;
1012

1113
/**
12-
* Class Row reindex action
14+
* Class Row reindex action.
15+
*
16+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1317
*/
1418
class Row extends \Magento\Catalog\Model\Indexer\Product\Flat\AbstractAction
1519
{
1620
/**
17-
* @var \Magento\Catalog\Model\Indexer\Product\Flat\Action\Indexer
21+
* @var Indexer
1822
*/
1923
protected $flatItemWriter;
2024

@@ -23,6 +27,11 @@ class Row extends \Magento\Catalog\Model\Indexer\Product\Flat\AbstractAction
2327
*/
2428
protected $flatItemEraser;
2529

30+
/**
31+
* @var MetadataPool
32+
*/
33+
private $metadataPool;
34+
2635
/**
2736
* @param \Magento\Framework\App\ResourceConnection $resource
2837
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
@@ -32,6 +41,7 @@ class Row extends \Magento\Catalog\Model\Indexer\Product\Flat\AbstractAction
3241
* @param FlatTableBuilder $flatTableBuilder
3342
* @param Indexer $flatItemWriter
3443
* @param Eraser $flatItemEraser
44+
* @param MetadataPool|null $metadataPool
3545
*/
3646
public function __construct(
3747
\Magento\Framework\App\ResourceConnection $resource,
@@ -41,7 +51,8 @@ public function __construct(
4151
TableBuilder $tableBuilder,
4252
FlatTableBuilder $flatTableBuilder,
4353
Indexer $flatItemWriter,
44-
Eraser $flatItemEraser
54+
Eraser $flatItemEraser,
55+
MetadataPool $metadataPool = null
4556
) {
4657
parent::__construct(
4758
$resource,
@@ -53,6 +64,8 @@ public function __construct(
5364
);
5465
$this->flatItemWriter = $flatItemWriter;
5566
$this->flatItemEraser = $flatItemEraser;
67+
$this->metadataPool = $metadataPool ?:
68+
\Magento\Framework\App\ObjectManager::getInstance()->get(MetadataPool::class);
5669
}
5770

5871
/**
@@ -61,7 +74,6 @@ public function __construct(
6174
* @param int|null $id
6275
* @return \Magento\Catalog\Model\Indexer\Product\Flat\Action\Row
6376
* @throws \Magento\Framework\Exception\LocalizedException
64-
* @throws \Zend_Db_Statement_Exception
6577
*/
6678
public function execute($id = null)
6779
{
@@ -71,50 +83,47 @@ public function execute($id = null)
7183
);
7284
}
7385
$ids = [$id];
74-
foreach ($this->_storeManager->getStores() as $store) {
86+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
87+
88+
$stores = $this->_storeManager->getStores();
89+
foreach ($stores as $store) {
7590
$tableExists = $this->_isFlatTableExists($store->getId());
7691
if ($tableExists) {
7792
$this->flatItemEraser->removeDeletedProducts($ids, $store->getId());
7893
}
7994

8095
/* @var $status \Magento\Eav\Model\Entity\Attribute */
81-
$status = $this->_productIndexerHelper->getAttribute('status');
96+
$status = $this->_productIndexerHelper->getAttribute(ProductInterface::STATUS);
8297
$statusTable = $status->getBackend()->getTable();
8398
$statusConditions = [
8499
'store_id IN(0,' . (int)$store->getId() . ')',
85100
'attribute_id = ' . (int)$status->getId(),
86-
'entity_id = ' . (int)$id
101+
$linkField . ' = ' . (int)$id,
87102
];
88103
$select = $this->_connection->select();
89-
$select->from(
90-
$statusTable,
91-
['value']
92-
)->where(
93-
implode(' AND ', $statusConditions)
94-
)->order(
95-
'store_id DESC'
96-
);
104+
$select->from($statusTable, ['value'])
105+
->where(implode(' AND ', $statusConditions))
106+
->order('store_id DESC')
107+
->limit(1);
97108
$result = $this->_connection->query($select);
98-
$status = $result->fetch(1);
109+
$status = $result->fetchColumn(0);
99110

100-
if ($status['value'] == \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED) {
101-
if (isset($ids[0])) {
102-
if (!$tableExists) {
103-
$this->_flatTableBuilder->build(
104-
$store->getId(),
105-
[$ids[0]],
106-
$this->_valueFieldSuffix,
107-
$this->_tableDropSuffix,
108-
false
109-
);
110-
}
111-
$this->flatItemWriter->write($store->getId(), $ids[0], $this->_valueFieldSuffix);
111+
if ($status == \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED) {
112+
if (!$tableExists) {
113+
$this->_flatTableBuilder->build(
114+
$store->getId(),
115+
$ids,
116+
$this->_valueFieldSuffix,
117+
$this->_tableDropSuffix,
118+
false
119+
);
112120
}
113-
}
114-
if ($status['value'] == \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED) {
121+
$this->flatItemWriter->write($store->getId(), $id, $this->_valueFieldSuffix);
122+
} else {
115123
$this->flatItemEraser->deleteProductsFromStore($id, $store->getId());
116124
}
117125
}
126+
118127
return $this;
119128
}
120129
}

0 commit comments

Comments
 (0)