我想在更新后为单个产品重新编制索引。
现在我使用:
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', 'foobar');
// edit something
$product->save();
$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId());
$stockItem->setForceReindexRequired(true);
Mage::getSingleton('index/indexer')->processEntityAction(
$stockItem,
Mage_CatalogInventory_Model_Stock_Item::ENTITY,
Mage_Index_Model_Event::TYPE_SAVE
);
$product
->setForceReindexRequired(true)
->setIsChangedCategories(true);
Mage::getSingleton('index/indexer')->processEntityAction(
$product,
Mage_Catalog_Model_Product::ENTITY,
Mage_Index_Model_Event::TYPE_SAVE
);
但这行不通,有什么主意吗?
PS:
$product->getId()
存在并且正确。