2012-01-30 53 views
4

我試圖在Magento社區版1.4中的索引管理下創建一個自定義索引器,這個自定義索引器的主要目的是根據一組計算來更新自定義產品屬性。Magento CE 1.4索引器 - 索引管理

我看着magento核心代碼,並且做了類似於我需要的東西,但是我找不到有關該主題的足夠的文檔。

這是我走到這一步:

config.xml中

<?xml version="1.0"?> 
<config> 
<!-- configuration --> 
    <global> 
     <index> 
      <indexer> 
       <custom_product_price> 
       <model>custom/indexer_price</model> 
       </custom_product_price> 
      </indexer> 
     </index> 
    </global> 
<!-- configuration --> 
</config> 

然後,我創建了一個模型

class MyModule_Custom_Model_Indexer_Price extends Mage_Index_Model_Indexer_Abstract 
{ 
protected $_matchedEntities = array(
    Mage_Catalog_Model_Product::ENTITY => array(
     Mage_Index_Model_Event::TYPE_SAVE, 
     Mage_Index_Model_Event::TYPE_DELETE, 
     Mage_Index_Model_Event::TYPE_MASS_ACTION 
    ) 
); 

/** 
* Initialize resource model 
* 
*/ 
protected function _construct() 
{ 
    $this->_init('custome/indexer_price'); 
} 

public function getName() 
{ 
    return Mage::helper('customizer')->__('Customizable Products'); 
} 

public function getDescription() 
{ 
    return Mage::helper('customizer')->__('Index Customizable Product Prices'); 
} 

public function matchEvent(Mage_Index_Model_Event $event) { 
    Mage::log("Should I match an event: ".$event->getEntity() . '|'. $event->getType()); 
    return true; 
} 

protected function _registerEvent(Mage_Index_Model_Event $event) { 
    Mage::log("Should I register an event: ".$event->getEntity() . '|'. $event->getType()); 
} 

protected function _processEvent(Mage_Index_Model_Event $event) { 
    Mage::log("Should I process an event: ".$event->getEntity() . '|'. $event->getType()); 
} 

public function reindexAll() { 

    Mage::log('Do my processing to reindex'); 
} 
} 

實現這個代碼,我能看到我的新的自定義索引之後item在索引管理網格下,但是當我運行reindex動作時,它只是解僱了reindexAll()方法。

任何想法將有所幫助,並提前感謝。

+0

不確定你真的在這裏問什麼? – edmondscommerce 2013-08-16 15:17:00

回答

2

這是正確的Magento行爲。這裏有一個解釋:

 
Mage::getSingleton('index/indexer')->processEntityAction($this, self::ENTITY, Mage_Index_Model_Event::TYPE_SAVE); 

產品保存後,重新索引在下面的調用引發Mage_Catalog_Model_Product :: afterCommitCallback()(代碼示例是從Magento的CE 1.4.0.0拍攝)如果您將看看processEntityAction,您會看到如果您的索引匹配,並且索引模式不是「手動」,則magento會運行索引器模型的_processEvent方法。 當Magento完成運行時,它會從「index_process_event」表中刪除待定條目。

當您從管理面板重新索引,Magento的檢查是否有在「index_process_event」表索引待定參賽,如果是的話 - Magento的運行模型的 _processEvent方法,否則運行reindexAll。 因此,就你而言,magento運行reindexAll是完全正確的。 如果您希望Magento運行_processEvent而不是reindexAll,則應通過管理面板將索引模式更改爲「手動」。