/** * Test reindex for configurable product with both disabled and enabled variations. * * @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php */ public function testReindexEntitiesForConfigurableProduct() { /** @var ProductRepositoryInterface $productRepository */ $productRepository = Bootstrap::getObjectManager()->create(ProductRepositoryInterface::class); /** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attr **/ $attr = Bootstrap::getObjectManager()->get('Magento\\Eav\\Model\\Config')->getAttribute('catalog_product', 'test_configurable'); $attr->setIsFilterable(1)->save(); $this->_eavIndexerProcessor->reindexAll(); /** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection $options **/ $options = Bootstrap::getObjectManager()->create('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Option\\Collection'); $options->setAttributeFilter($attr->getId())->load(); $optionIds = $options->getAllIds(); $connection = $this->productResource->getConnection(); $select = $connection->select()->from($this->productResource->getTable('catalog_product_index_eav'))->where('entity_id = ?', 1)->where('attribute_id = ?', $attr->getId())->where('value IN (?)', $optionIds); $result = $connection->fetchAll($select); $this->assertCount(2, $result); /** @var \Magento\Catalog\Model\Product $product1 **/ $product1 = $productRepository->getById(10); $product1->setStatus(Status::STATUS_DISABLED); $productRepository->save($product1); /** @var \Magento\Catalog\Model\Product $product2 **/ $product2 = $productRepository->getById(20); $product2->setStatus(Status::STATUS_DISABLED); $productRepository->save($product2); $result = $connection->fetchAll($select); $this->assertCount(0, $result); }
/** * @magentoDataFixture Magento/Catalog/_files/products_with_multiselect_attribute.php */ public function testReindexMultiselectAttribute() { /** @var ProductRepositoryInterface $productRepository */ $productRepository = Bootstrap::getObjectManager()->create(ProductRepositoryInterface::class); /** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attr **/ $attr = Bootstrap::getObjectManager()->get('Magento\\Eav\\Model\\Config')->getAttribute('catalog_product', 'multiselect_attribute'); $attr->setIsFilterable(1)->save(); /** @var $options \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection */ $options = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Option\\Collection'); $options->setAttributeFilter($attr->getId()); $optionIds = $options->getAllIds(); $product1Id = $optionIds[0] * 10; $product2Id = $optionIds[1] * 10; /** @var \Magento\Catalog\Model\Product $product1 **/ $product1 = $productRepository->getById($product1Id); $product1->setSpecialFromDate(date('Y-m-d H:i:s')); $product1->setNewsFromDate(date('Y-m-d H:i:s')); $productRepository->save($product1); /** @var \Magento\Catalog\Model\Product $product2 **/ $product2 = $productRepository->getById($product2Id); $product1->setSpecialFromDate(date('Y-m-d H:i:s')); $product1->setNewsFromDate(date('Y-m-d H:i:s')); $productRepository->save($product2); $this->_eavIndexerProcessor->reindexAll(); $connection = $this->productResource->getConnection(); $select = $connection->select()->from($this->productResource->getTable('catalog_product_index_eav'))->where('entity_id in (?)', [$product1Id, $product2Id])->where('attribute_id = ?', $attr->getId()); $result = $connection->fetchAll($select); $this->assertCount(3, $result); }
/** * Clear index data */ protected function clearIndex() { $this->productResource->getConnection()->delete( $this->productResource->getTable('catalog_category_product_index') ); $actualResult = $this->productResource->getConnection()->fetchOne( $this->productResource->getConnection()->select()->from( $this->productResource->getTable('catalog_category_product_index'), 'product_id' ) ); $this->assertFalse($actualResult); }
/** * Get attribute set id for product * * @param int $productId * @return string */ protected function _getAttributeSetId($productId) { return $this->_productResource->getConnection()->fetchOne($this->_productResource->getConnection()->select()->distinct()->from($this->_productResource->getTable('catalog_product_entity'), ['attribute_set_id'])->where('entity_id = ?', $productId)); }
/** * {@inheritdoc} */ public function getTable($alias) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getTable'); if (!$pluginInfo) { return parent::getTable($alias); } else { return $this->___callPlugins('getTable', func_get_args(), $pluginInfo); } }