Skip to content

Commit

Permalink
Merge remote-tracking branch 'github-magento/2.3-develop' into EPAM-P…
Browse files Browse the repository at this point in the history
…R-12
  • Loading branch information
nikshostko committed Oct 8, 2018
2 parents 4fb3271 + 80469a6 commit 3880bce
Show file tree
Hide file tree
Showing 109 changed files with 2,288 additions and 1,329 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
13 changes: 9 additions & 4 deletions app/code/Magento/Catalog/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements

const CACHE_TAG = 'cat_c';

/**
* Category Store Id
*/
const STORE_ID = 'store_id';

/**#@-*/
protected $_eventPrefix = 'catalog_category';

Expand Down Expand Up @@ -564,12 +569,12 @@ public function getStoreIds()
*
* If store id is underfined for category return current active store id
*
* @return integer
* @return int
*/
public function getStoreId()
{
if ($this->hasData('store_id')) {
return (int)$this->_getData('store_id');
if ($this->hasData(self::STORE_ID)) {
return (int)$this->_getData(self::STORE_ID);
}
return (int)$this->_storeManager->getStore()->getId();
}
Expand All @@ -585,7 +590,7 @@ public function setStoreId($storeId)
if (!is_numeric($storeId)) {
$storeId = $this->_storeManager->getStore($storeId)->getId();
}
$this->setData('store_id', $storeId);
$this->setData(self::STORE_ID, $storeId);
$this->getResource()->setStoreId($storeId);
return $this;
}
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,51 +83,48 @@ 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());
$this->flatItemEraser->removeDisabledProducts($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 3880bce

Please sign in to comment.