Skip to content

Commit f2a562c

Browse files
committed
Fix issue 16315: Fix code standard & write unit test
1 parent fe02648 commit f2a562c

File tree

2 files changed

+36
-9
lines changed
  • app/code/Magento/Catalog
    • Model/Indexer/Product/Flat/Action
    • Test/Unit/Model/Indexer/Product/Flat/Action

2 files changed

+36
-9
lines changed

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,7 @@ public function execute($id = null)
8585
$ids = [$id];
8686
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
8787

88-
$select = $this->_connection->select();
89-
$select->from(['e' => $this->_productIndexerHelper->getTable('store')], ['e.store_id'])
90-
->where('c.product_id = ' . $id)
91-
->joinLeft(
92-
['c' => $this->_productIndexerHelper->getTable('catalog_product_website')],
93-
'e.website_id = c.website_id',
94-
[]
95-
);
96-
$storeIds = $this->_connection->fetchCol($select);
88+
$storeIds = $this->getProductAvailableStores($id);
9789

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

144136
return $this;
145137
}
138+
139+
/**
140+
* Get list store id where product is enable
141+
*
142+
* @param int $productId
143+
* @return array
144+
*/
145+
private function getProductAvailableStores($productId)
146+
{
147+
$select = $this->_connection->select();
148+
$select->from(['e' => $this->_productIndexerHelper->getTable('store')], ['e.store_id'])
149+
->where('c.product_id = ' . $productId)
150+
->joinLeft(
151+
['c' => $this->_productIndexerHelper->getTable('catalog_product_website')],
152+
'e.website_id = c.website_id',
153+
[]
154+
);
155+
return $this->_connection->fetchCol($select);
156+
}
146157
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,24 @@ public function testExecuteWithExistingFlatTablesCreatesTables()
160160
->willReturn('store_flat_table');
161161
$this->connection->expects($this->any())->method('isTableExists')->with('store_flat_table')
162162
->willReturn(true);
163+
$this->connection->expects($this->any())->method('fetchCol')
164+
->willReturn(['store_id_1']);
163165
$this->flatItemEraser->expects($this->once())->method('removeDeletedProducts');
164166
$this->flatTableBuilder->expects($this->never())->method('build')->with('store_id_1', ['product_id_1']);
165167
$this->model->execute('product_id_1');
166168
}
169+
170+
public function testExecuteWithExistingFlatTablesRemoveProductFromStore()
171+
{
172+
$this->productIndexerHelper->expects($this->any())->method('getFlatTableName')
173+
->willReturn('store_flat_table');
174+
$this->connection->expects($this->any())->method('isTableExists')->with('store_flat_table')
175+
->willReturn(true);
176+
$this->connection->expects($this->any())->method('fetchCol')
177+
->willReturn([1]);
178+
$this->flatItemEraser->expects($this->once())->method('deleteProductsFromStore');
179+
$this->flatItemEraser->expects($this->never())->method('removeDeletedProducts');
180+
$this->flatTableBuilder->expects($this->never())->method('build')->with('store_id_1', ['product_id_1']);
181+
$this->model->execute('product_id_1');
182+
}
167183
}

0 commit comments

Comments
 (0)