2010-03-18 47 views
8

我正在使用cron每晚導入庫存更改。當我試圖改變產品的信息(價格等),我收到以下錯誤:Magento:以編程方式重建平面目錄

Column not found: 1054 Unknown column 'e.display_price_group_0' in 'field list' 

我可以通過點擊緩存管理面板「重建平板目錄產品」解決這個問題。我設置一個cron來做到這一點編程方式使用下面的代碼:

Mage :: getResourceModel('catalog/product_flat_indexer') -> rebuild(); 

當我運行該腳本,我沒有得到任何錯誤,但「列未找到」錯誤仍然存​​在。

有誰知道我可以通過管理界面重建平面目錄嗎?

回答

4

一張我說,要做到這一點:

Mage::getModel('catalog/product_flat_indexer')->rebuild(); 
Note: it's getModel and NOT getResourceModel. 

這是不正確的。要麼工作。然而,我發現通過一個相當痛苦的試驗和錯誤過程,平面產品表不能正確重建,除非我也重建整個目錄。這是我終於解決了我的問題:

Mage::getSingleton('catalog/index')->rebuild(); 
Mage::getResourceModel('catalog/product_flat_indexer')->rebuild(); 
Mage::getSingleton('catalog/url')->refreshRewrites(); 
Mage::getModel('catalog/product_image')->clearCache(); 
Mage::getSingleton('catalogsearch/fulltext')->rebuildIndex(); 
Mage::getSingleton('cataloginventory/stock_status')->rebuild(); 
$flag = Mage::getModel('catalogindex/catalog_index_flag')->loadSelf(); 
if ($flag->getState() == Mage_CatalogIndex_Model_Catalog_Index_Flag::STATE_RUNNING) { 
    $kill = Mage::getModel('catalogindex/catalog_index_kill_flag')->loadSelf(); 
    $kill->setFlagData($flag->getFlagData())->save(); 
} 
$flag->setState(Mage_CatalogIndex_Model_Catalog_Index_Flag::STATE_QUEUED)->save(); 
Mage::getSingleton('catalogindex/indexer')->plainReindex(); 

基本上,只是重建一切。不要擔心優化。就像有人曾經說過的那樣:「不成熟的優化是萬惡之源。」

1

看到這個script。 我個人有些麻煩,但其他人似乎對此很滿意。
如果你不想要所有的東西,你可以輕鬆地取出重建平面目錄產品的部分,並指出一個cron作業。

+0

這是我從上面得到的代碼的腳本。它似乎並沒有爲我工作。 – karnage 2010-03-25 18:56:28

+0

Laizer,是你的麻煩,你得到的錯誤「異常'Zend_Db_Statement_Exception'消息'SQLSTATE [42S22]:未找到列:1054未知列'e.display_price_group_0'在'字段列表'/ var/www/releases/20101019/lib/Zend/Db/Statement/Pdo.php:238「在重建平面目錄後更新產品?如果是這樣,你是如何解決它的?謝謝! – fdierre 2010-10-29 08:38:57

+0

害怕我不能幫你在這裏。我不認爲我見過這個問題。 – Laizer 2010-11-14 22:11:08

0

我也無法讓它正常工作。

當我重建重建從管理扁平目錄產品能正常工作,我沒有得到的SQL列錯誤,但是當我做編程它不通過工作:

法師:: getResourceModel ( '目錄/ product_flat_indexer') - >重建();

+0

我很高興知道我不是唯一一個,我以爲我失去了我的想法。 – karnage 2010-03-29 18:08:16

1
* Rebuild Catalog Index 

    Mage::getSingleton('catalog/index')->rebuild(); 

* Rebuild Flat Catalog Product 

    Mage::getResourceModel('catalog/product_flat_indexer')->rebuild(); 

* Inventory Stock 

    Mage::getSingleton('cataloginventory/stock_status')->rebuild(); 
2

我發現有一個更有效的方法來只更新特定的產品屬性。

Mage::getModel('catalog/product_flat_indexer')->updateAttribute($attributeCode, null, $productIds); 

或者你可以更新平表整個產品:

Mage::getModel('catalog/product_flat_indexer')->updateProduct($productIds, null); 

其中$ productIds是產品實體ID數組進行更新。這些功能還會更新與您更新的產品相關的其他索引數據。希望這可以幫助。

0

我剛剛編寫了基於Shell reindex腳本的代碼。 我已經在Magento 1.5.1中使用web腳本(長max_execution_time)對其進行了測試。

if (!empty($_SERVER['HTTP_HOST'])) 
{ 
    header('Content-Type: text/plain'); 
}  

$oIndexer = Mage::getSingleton('index/indexer');    
/* @var $oIndexer Mage_Index_Model_Indexer */ 
$oProcessCollection = $oIndexer->getProcessesCollection(); 
/* @var $oProcessCollection Mage_Index_Model_Mysql4_Process_Collection */ 

foreach ($oProcessCollection as $oProcess) 
{ 
    /* @var $oProcess Mage_Index_Model_Process */ 
    echo 'Rebuilding ' . $oProcess->getIndexer()->getName() . ' index...'; 
    outputFlush(); 
    $oProcess->reindexEverything(); 
} 

echo 'Done.'; 
outputFlush() 

function outputFlush() 
{ 
    while (ob_get_length()) 
    { 
     ob_end_flush(); 
    } 
    if (!empty($_SERVER['HTTP_HOST'])) 
    { 
     echo str_repeat(' ',4096); 
    } 
    echo "\n"; 
    flush(); 
} 
1
public function rebuildIndexes(){ 
    $processes = array(); 
    $collection = Mage::getSingleton('index/indexer')->getProcessesCollection(); 
    foreach ($collection as $process) { 
     try { 
      $process->reindexEverything(); 
      $this->_message($process->getIndexer()->getName() . " index was rebuilt successfully"); 
     } catch (Mage_Core_Exception $e) { 
      $this->_throwException($e->getMessage()); 
     } catch (Exception $e) { 
      $this->_throwException($process->getIndexer()->getName() . " index process unknown error:\n" . $e); 
     } 
    } 
} 

人你爲什麼不研究後somethig不起作用,打開外殼/ indexer.php,裏面你會發現所有相關的索引答案之前一點點。

相關問題