如何以编程方式重新索引单个产品?

时间:2017-03-16 13:11:10

标签: magento magento-1.9

单品如何指数? 我试过下面的代码,但它没有用。

Mage::getSingleton('index/indexer')->processEntityAction( $product, Mage_Catalog_Model_Product::ENTITY, Mage_Index_Model_Event::TYPE_SAVE )

还有其他解决方案吗?

3 个答案:

答案 0 :(得分:0)

$process = Mage::getSingleton('index/indexer')->getProcessByCode("cataloginventory_stock");
$process->reindexAll();

根据需要尝试使用此代码:

catalog_product_attribute     Product Attributes
catalog_product_price         Product Prices
catalog_url                   Catalog Url Rewrites
catalog_product_flat          Product Flat Data
catalog_category_flat         Category Flat Data
catalog_category_product      Category Product
catalogsearch_fulltext        Catalog Search Index
cataloginventory_stock        Stock status

答案 1 :(得分:0)

您可以按照以下属性进行产品索引:

$indexer = Mage::getSingleton('index/indexer')->processEntityAction($_product, 'catalog_url', Mage_Index_Model_Event::TYPE_SAVE);

希望,它适合你。

答案 2 :(得分:0)

require_once 'app/Mage.php';
umask(0);
Mage::app();
$childIds = Mage::getModel('catalog/product_type_configurable')->getChildrenIds('121644');
$productsIds = $childIds;
$event = Mage::getModel('index/event');
$event->setNewData(array(
'product_ids' => $productsIds,));
Mage::getResourceSingleton('catalog/category_indexer_product')->catalogProductMassAction($event);
Mage::getResourceModel('catalog/product_indexer_price')->reindexProductIds($productsIds);
Mage::getResourceModel('cataloginventory/indexer_stock')->reindexProducts($productsIds);
Mage::getResourceModel('catalog/product_indexer_eav_source')->reindexEntities($productsIds);
$catalogSearchIndexer = Mage::getResourceModel('catalogsearch/fulltext');
$catalogSearchIndexer->rebuildIndex(null, $productsIds);
echo "Done";exit;