/** * Reindex affected products * * @param int $storeId * @param string $attrCode * @param \Zend_Db_Expr $attrConditionValue * @return void */ protected function _refreshSpecialPriceByStore($storeId, $attrCode, $attrConditionValue) { $attribute = $this->_eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $attrCode); $attributeId = $attribute->getAttributeId(); $connection = $this->_getConnection(); $select = $connection->select()->from($this->_resource->getTableName(['catalog_product_entity', 'datetime']), ['entity_id'])->where('attribute_id = ?', $attributeId)->where('store_id = ?', $storeId)->where('value = ?', $attrConditionValue); $this->_processor->getIndexer()->reindexList($connection->fetchCol($select, ['entity_id'])); }
/** * @magentoDataFixture Magento/Catalog/_files/products.php * @magentoAppIsolation enabled */ public function testAddPriceDataOnSave() { $this->processor->getIndexer()->setScheduled(false); $this->assertFalse($this->processor->getIndexer()->isScheduled()); $productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Api\\ProductRepositoryInterface'); /** @var \Magento\Catalog\Api\Data\ProductInterface $product */ $product = $productRepository->get('simple'); $this->assertNotEquals(15, $product->getPrice()); $product->setPrice(15); $productRepository->save($product); $this->collection->addPriceData(0, 1); $this->collection->load(); /** @var \Magento\Catalog\Api\Data\ProductInterface[] $product */ $items = $this->collection->getItems(); /** @var \Magento\Catalog\Api\Data\ProductInterface $product */ $product = reset($items); $this->assertCount(2, $items); $this->assertEquals(15, $product->getPrice()); }
/** * @magentoDbIsolation enabled * @magentoAppIsolation enabled * @magentoDataFixture Magento/Catalog/_files/price_row_fixture.php */ public function testProductUpdate() { $categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('\\Magento\\Catalog\\Model\\CategoryFactory'); $listProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('\\Magento\\Catalog\\Block\\Product\\ListProduct'); $this->_processor->getIndexer()->setScheduled(false); $this->assertFalse($this->_processor->getIndexer()->isScheduled()); $this->_product->load(1); $this->_product->setPrice(1); $this->_product->save(); $category = $categoryFactory->create()->load(9); $layer = $listProduct->getLayer(); $layer->setCurrentCategory($category); $productCollection = $layer->getProductCollection(); $this->assertEquals(1, $productCollection->count()); /** @var $product \Magento\Catalog\Model\Product */ foreach ($productCollection as $product) { $this->assertEquals($this->_product->getId(), $product->getId()); $this->assertEquals($this->_product->getPrice(), $product->getPrice()); } }
/** * Reindex affected products * * @param int $storeId * @param string $attrCode * @param \Zend_Db_Expr $attrConditionValue * @return void */ protected function _refreshSpecialPriceByStore($storeId, $attrCode, $attrConditionValue) { $attribute = $this->_eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $attrCode); $attributeId = $attribute->getAttributeId(); $linkField = $this->getMetadataPool()->getMetadata(CategoryInterface::class)->getLinkField(); $identifierField = $this->getMetadataPool()->getMetadata(CategoryInterface::class)->getIdentifierField(); $connection = $this->_getConnection(); $select = $connection->select()->from(['attr' => $this->_resource->getTableName(['catalog_product_entity', 'datetime'])], [$identifierField => 'cat.' . $identifierField])->joinLeft(['cat' => $this->_resource->getTableName('catalog_product_entity')], 'cat.' . $linkField . '= attr.' . $linkField, '')->where('attr.attribute_id = ?', $attributeId)->where('attr.store_id = ?', $storeId)->where('attr.value = ?', $attrConditionValue); $selectData = $connection->fetchCol($select, $identifierField); if (!empty($selectData)) { $this->_processor->getIndexer()->reindexList($selectData); } }