/** * Mark Product flat indexer as invalid * * @return void */ public function markIndexerAsInvalid() { if (!$this->_state->isFlatEnabled()) { return; } $this->getIndexer()->invalidate(); }
/** * Around get handler * * @param \Magento\Indexer\Model\Config\Data $subject * @param callable $proceed * @param string $path * @param string $default * * @return mixed|null * @SuppressWarnings(PHPMD.UnusedFormalParameter) * */ public function aroundGet(\Magento\Indexer\Model\Config\Data $subject, \Closure $proceed, $path = null, $default = null) { $data = $proceed($path, $default); if (!$this->_state->isFlatEnabled()) { $indexerId = \Magento\Catalog\Model\Indexer\Product\Flat\Processor::INDEXER_ID; if (!$path && isset($data[$indexerId])) { unset($data[$indexerId]); } elseif ($path) { list($firstKey, ) = explode('/', $path); if ($firstKey == $indexerId) { $data = $default; } } } return $data; }
/** * @magentoDbIsolation enabled * @magentoAppIsolation enabled * @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1 * @magentoDataFixture Magento/Catalog/_files/product_simple.php */ public function testReindexAll() { $this->assertTrue($this->_state->isFlatEnabled()); $this->_processor->reindexAll(); $categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Model\\CategoryFactory'); $listProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Block\\Product\\ListProduct'); $category = $categoryFactory->create()->load(2); $layer = $listProduct->getLayer(); $layer->setCurrentCategory($category); $productCollection = $layer->getProductCollection(); $this->assertCount(1, $productCollection); /** @var $product \Magento\Catalog\Model\Product */ foreach ($productCollection as $product) { $this->assertEquals('Simple Product', $product->getName()); $this->assertEquals('Short description', $product->getShortDescription()); } }
/** * @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1 */ public function testIsEnabled() { $this->assertTrue($this->_state->isFlatEnabled()); }
/** * @magentoDbIsolation enabled * @magentoAppIsolation enabled * @magentoAppArea adminhtml * @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1 */ public function testEnableProductFlat() { $this->assertTrue($this->_state->isFlatEnabled()); $this->assertTrue($this->_processor->getIndexer()->isInvalid()); }