Skip to content

Commit

Permalink
Merge pull request magento#3238 from magento-honey-badgers/2.3.0-rele…
Browse files Browse the repository at this point in the history
…ase-merge

Sync 2.3.0 with 2.3-develop
  • Loading branch information
Joan He authored Oct 5, 2018
2 parents 18dcf17 + ba532b3 commit 80469a6
Show file tree
Hide file tree
Showing 48 changed files with 1,022 additions and 1,003 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<% if (data.items.length) { %>
<% _.each(data.items, function(value){ %>
<li class="item"
<%- data.optionData(value) %>
<%= data.optionData(value) %>
>
<a href="<%- value.url %>" class="title"><%- value.name %></a>
<span class="type"><%- value.type %></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,39 +56,36 @@ public function __construct(
* @return \Magento\Catalog\Model\Indexer\Product\Flat
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function write($storeId, $productId, $valueFieldSuffix = '')
{
$flatTable = $this->_productIndexerHelper->getFlatTableName($storeId);
$entityTableName = $this->_productIndexerHelper->getTable('catalog_product_entity');

$attributes = $this->_productIndexerHelper->getAttributes();
$eavAttributes = $this->_productIndexerHelper->getTablesStructure($attributes);
$updateData = [];
$describe = $this->_connection->describeTable($flatTable);
$metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
$linkField = $metadata->getLinkField();

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

foreach ($columnsChunks as $columns) {
$select = $this->_connection->select();
$selectValue = $this->_connection->select();
$keyColumns = [
'entity_id' => 'e.entity_id',
'attribute_id' => 't.attribute_id',
'value' => $this->_connection->getIfNullSql('`t2`.`value`', '`t`.`value`'),
];

if ($tableName != $this->_productIndexerHelper->getTable('catalog_product_entity')) {

if ($tableName != $entityTableName) {
$valueColumns = [];
$ids = [];
$select->from(
['e' => $this->_productIndexerHelper->getTable('catalog_product_entity')],
$keyColumns
);

$selectValue->from(
['e' => $this->_productIndexerHelper->getTable('catalog_product_entity')],
$keyColumns
['e' => $entityTableName],
[
'entity_id' => 'e.entity_id',
'attribute_id' => 't.attribute_id',
'value' => $this->_connection->getIfNullSql('`t2`.`value`', '`t`.`value`'),
]
);

/** @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */
Expand All @@ -97,8 +94,7 @@ public function write($storeId, $productId, $valueFieldSuffix = '')
$ids[$attribute->getId()] = $columnName;
}
}
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
$select->joinLeft(
$select->joinInner(
['t' => $tableName],
sprintf('e.%s = t.%s ', $linkField, $linkField) . $this->_connection->quoteInto(
' AND t.attribute_id IN (?)',
Expand All @@ -116,8 +112,6 @@ public function write($storeId, $productId, $valueFieldSuffix = '')
[]
)->where(
'e.entity_id = ' . $productId
)->where(
't.attribute_id IS NOT NULL'
);
$cursor = $this->_connection->query($select);
while ($row = $cursor->fetch(\Zend_Db::FETCH_ASSOC)) {
Expand Down Expand Up @@ -157,7 +151,7 @@ public function write($storeId, $productId, $valueFieldSuffix = '')
$columnNames[] = 'attribute_set_id';
$columnNames[] = 'type_id';
$select->from(
['e' => $this->_productIndexerHelper->getTable('catalog_product_entity')],
['e' => $entityTableName],
$columnNames
)->where(
'e.entity_id = ' . $productId
Expand All @@ -175,7 +169,9 @@ public function write($storeId, $productId, $valueFieldSuffix = '')

if (!empty($updateData)) {
$updateData += ['entity_id' => $productId];
$updateData += ['row_id' => $productId];
if ($linkField !== $metadata->getIdentifierField()) {
$updateData += [$linkField => $productId];
}
$updateFields = [];
foreach ($updateData as $key => $value) {
$updateFields[$key] = $key;
Expand All @@ -187,6 +183,8 @@ public function write($storeId, $productId, $valueFieldSuffix = '')
}

/**
* Get MetadataPool instance
*
* @return \Magento\Framework\EntityManager\MetadataPool
*/
private function getMetadataPool()
Expand Down
69 changes: 39 additions & 30 deletions app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
*/
namespace Magento\Catalog\Model\Indexer\Product\Flat\Action;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Indexer\Product\Flat\FlatTableBuilder;
use Magento\Catalog\Model\Indexer\Product\Flat\TableBuilder;
use Magento\Framework\EntityManager\MetadataPool;

/**
* Class Row reindex action
* Class Row reindex action.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Row extends \Magento\Catalog\Model\Indexer\Product\Flat\AbstractAction
{
/**
* @var \Magento\Catalog\Model\Indexer\Product\Flat\Action\Indexer
* @var Indexer
*/
protected $flatItemWriter;

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

/**
* @var MetadataPool
*/
private $metadataPool;

/**
* @param \Magento\Framework\App\ResourceConnection $resource
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
Expand All @@ -32,6 +41,7 @@ class Row extends \Magento\Catalog\Model\Indexer\Product\Flat\AbstractAction
* @param FlatTableBuilder $flatTableBuilder
* @param Indexer $flatItemWriter
* @param Eraser $flatItemEraser
* @param MetadataPool|null $metadataPool
*/
public function __construct(
\Magento\Framework\App\ResourceConnection $resource,
Expand All @@ -41,7 +51,8 @@ public function __construct(
TableBuilder $tableBuilder,
FlatTableBuilder $flatTableBuilder,
Indexer $flatItemWriter,
Eraser $flatItemEraser
Eraser $flatItemEraser,
MetadataPool $metadataPool = null
) {
parent::__construct(
$resource,
Expand All @@ -53,6 +64,8 @@ public function __construct(
);
$this->flatItemWriter = $flatItemWriter;
$this->flatItemEraser = $flatItemEraser;
$this->metadataPool = $metadataPool ?:
\Magento\Framework\App\ObjectManager::getInstance()->get(MetadataPool::class);
}

/**
Expand All @@ -61,7 +74,6 @@ public function __construct(
* @param int|null $id
* @return \Magento\Catalog\Model\Indexer\Product\Flat\Action\Row
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Zend_Db_Statement_Exception
*/
public function execute($id = null)
{
Expand All @@ -71,50 +83,47 @@ public function execute($id = null)
);
}
$ids = [$id];
foreach ($this->_storeManager->getStores() as $store) {
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();

$stores = $this->_storeManager->getStores();
foreach ($stores as $store) {
$tableExists = $this->_isFlatTableExists($store->getId());
if ($tableExists) {
$this->flatItemEraser->removeDeletedProducts($ids, $store->getId());
}

/* @var $status \Magento\Eav\Model\Entity\Attribute */
$status = $this->_productIndexerHelper->getAttribute('status');
$status = $this->_productIndexerHelper->getAttribute(ProductInterface::STATUS);
$statusTable = $status->getBackend()->getTable();
$statusConditions = [
'store_id IN(0,' . (int)$store->getId() . ')',
'attribute_id = ' . (int)$status->getId(),
'entity_id = ' . (int)$id
$linkField . ' = ' . (int)$id,
];
$select = $this->_connection->select();
$select->from(
$statusTable,
['value']
)->where(
implode(' AND ', $statusConditions)
)->order(
'store_id DESC'
);
$select->from($statusTable, ['value'])
->where(implode(' AND ', $statusConditions))
->order('store_id DESC')
->limit(1);
$result = $this->_connection->query($select);
$status = $result->fetch(1);
$status = $result->fetchColumn(0);

if ($status['value'] == \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED) {
if (isset($ids[0])) {
if (!$tableExists) {
$this->_flatTableBuilder->build(
$store->getId(),
[$ids[0]],
$this->_valueFieldSuffix,
$this->_tableDropSuffix,
false
);
}
$this->flatItemWriter->write($store->getId(), $ids[0], $this->_valueFieldSuffix);
if ($status == \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED) {
if (!$tableExists) {
$this->_flatTableBuilder->build(
$store->getId(),
$ids,
$this->_valueFieldSuffix,
$this->_tableDropSuffix,
false
);
}
}
if ($status['value'] == \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED) {
$this->flatItemWriter->write($store->getId(), $id, $this->_valueFieldSuffix);
} else {
$this->flatItemEraser->deleteProductsFromStore($id, $store->getId());
}
}

return $this;
}
}
Loading

0 comments on commit 80469a6

Please sign in to comment.