Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 47 additions & 11 deletions app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

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

/**
* Class Row reindex action
Expand All @@ -22,6 +24,10 @@ class Row extends \Magento\Catalog\Model\Indexer\Product\Flat\AbstractAction
* @var Eraser
*/
protected $flatItemEraser;
/**
* @var MetadataPool
*/
private $metadataPool;

/**
* @param \Magento\Framework\App\ResourceConnection $resource
Expand All @@ -32,6 +38,7 @@ class Row extends \Magento\Catalog\Model\Indexer\Product\Flat\AbstractAction
* @param FlatTableBuilder $flatTableBuilder
* @param Indexer $flatItemWriter
* @param Eraser $flatItemEraser
* @param MetadataPool $metadataPool
*/
public function __construct(
\Magento\Framework\App\ResourceConnection $resource,
Expand All @@ -41,7 +48,8 @@ public function __construct(
TableBuilder $tableBuilder,
FlatTableBuilder $flatTableBuilder,
Indexer $flatItemWriter,
Eraser $flatItemEraser
Eraser $flatItemEraser,
MetadataPool $metadataPool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lewisvoncken, due to Magento backward-compatible guide we can't add a new required dependency to the constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VladimirZaets thanks for the feedback. The dependency incorrect and I have just removed it.

) {
parent::__construct(
$resource,
Expand All @@ -53,6 +61,7 @@ public function __construct(
);
$this->flatItemWriter = $flatItemWriter;
$this->flatItemEraser = $flatItemEraser;
$this->metadataPool = $metadataPool;
}

/**
Expand All @@ -75,18 +84,45 @@ public function execute($id = null)
if ($tableExists) {
$this->flatItemEraser->removeDeletedProducts($ids, $store->getId());
}
if (isset($ids[0])) {
if (!$tableExists) {
$this->_flatTableBuilder->build(
$store->getId(),
[$ids[0]],
$this->_valueFieldSuffix,
$this->_tableDropSuffix,
false
);

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

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);
}
$this->flatItemWriter->write($store->getId(), $ids[0], $this->_valueFieldSuffix);
} else {
$this->flatItemEraser->deleteProductsFromStore($id, $store->getId());
}


}
return $this;
}
Expand Down