public function testDeleteProductsFromStoreForAllStores() { $store1 = $this->getMock('Magento\\Store\\Model\\Store', array(), array(), '', false); $store1->expects($this->any())->method('getId')->will($this->returnValue(1)); $store2 = $this->getMock('Magento\\Store\\Model\\Store', array(), array(), '', false); $store2->expects($this->any())->method('getId')->will($this->returnValue(2)); $this->storeManager->expects($this->once())->method('getStores')->will($this->returnValue(array($store1, $store2))); $this->connection->expects($this->at(0))->method('delete')->with('store_1_flat', array('entity_id IN(?)' => array(1))); $this->connection->expects($this->at(1))->method('delete')->with('store_2_flat', array('entity_id IN(?)' => array(1))); $this->model->deleteProductsFromStore(1); }
/** * Execute multiple rows reindex action * * @param array $ids * * @return \Magento\Catalog\Model\Indexer\Product\Flat\Action\Rows * @throws \Magento\Framework\Model\Exception */ public function execute($ids) { if (empty($ids)) { throw new \Magento\Framework\Model\Exception(__('Bad value was supplied.')); } foreach ($this->_storeManager->getStores() as $store) { $idsBatches = array_chunk($ids, \Magento\Catalog\Helper\Product\Flat\Indexer::BATCH_SIZE); foreach ($idsBatches as $changedIds) { $this->flatItemEraser->removeDeletedProducts($changedIds, $store->getId()); if (!empty($changedIds)) { $this->_reindex($store->getId(), $changedIds); } } } return $this; }
/** * Execute row reindex action * * @param int|null $id * @return \Magento\Catalog\Model\Indexer\Product\Flat\Action\Row * @throws \Magento\Framework\Model\Exception */ public function execute($id = null) { if (!isset($id) || empty($id)) { throw new \Magento\Framework\Model\Exception(__('Could not rebuild index for undefined product')); } $ids = array($id); foreach ($this->_storeManager->getStores() as $store) { $tableExists = $this->_isFlatTableExists($store->getId()); if ($tableExists) { $this->flatItemEraser->removeDeletedProducts($ids, $store->getId()); } if (isset($ids[0])) { if (!$tableExists) { $this->_flatTableBuilder->build($store->getId(), array($ids[0]), $this->_valueFieldSuffix, $this->_tableDropSuffix, false); } $this->flatItemWriter->write($store->getId(), $ids[0], $this->_valueFieldSuffix); } } return $this; }