Skip to content

Commit

Permalink
Fix issue 16315: Fix code standard & write unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
tna274 committed Mar 20, 2020
1 parent fe02648 commit f2a562c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
29 changes: 20 additions & 9 deletions app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,7 @@ public function execute($id = null)
$ids = [$id];
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();

$select = $this->_connection->select();
$select->from(['e' => $this->_productIndexerHelper->getTable('store')], ['e.store_id'])
->where('c.product_id = ' . $id)
->joinLeft(
['c' => $this->_productIndexerHelper->getTable('catalog_product_website')],
'e.website_id = c.website_id',
[]
);
$storeIds = $this->_connection->fetchCol($select);
$storeIds = $this->getProductAvailableStores($id);

$stores = $this->_storeManager->getStores();
foreach ($stores as $store) {
Expand Down Expand Up @@ -143,4 +135,23 @@ public function execute($id = null)

return $this;
}

/**
* Get list store id where product is enable
*
* @param int $productId
* @return array
*/
private function getProductAvailableStores($productId)
{
$select = $this->_connection->select();
$select->from(['e' => $this->_productIndexerHelper->getTable('store')], ['e.store_id'])
->where('c.product_id = ' . $productId)
->joinLeft(
['c' => $this->_productIndexerHelper->getTable('catalog_product_website')],
'e.website_id = c.website_id',
[]
);
return $this->_connection->fetchCol($select);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,24 @@ public function testExecuteWithExistingFlatTablesCreatesTables()
->willReturn('store_flat_table');
$this->connection->expects($this->any())->method('isTableExists')->with('store_flat_table')
->willReturn(true);
$this->connection->expects($this->any())->method('fetchCol')
->willReturn(['store_id_1']);
$this->flatItemEraser->expects($this->once())->method('removeDeletedProducts');
$this->flatTableBuilder->expects($this->never())->method('build')->with('store_id_1', ['product_id_1']);
$this->model->execute('product_id_1');
}

public function testExecuteWithExistingFlatTablesRemoveProductFromStore()
{
$this->productIndexerHelper->expects($this->any())->method('getFlatTableName')
->willReturn('store_flat_table');
$this->connection->expects($this->any())->method('isTableExists')->with('store_flat_table')
->willReturn(true);
$this->connection->expects($this->any())->method('fetchCol')
->willReturn([1]);
$this->flatItemEraser->expects($this->once())->method('deleteProductsFromStore');
$this->flatItemEraser->expects($this->never())->method('removeDeletedProducts');
$this->flatTableBuilder->expects($this->never())->method('build')->with('store_id_1', ['product_id_1']);
$this->model->execute('product_id_1');
}
}

0 comments on commit f2a562c

Please sign in to comment.