2010-03-18 49 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,里面你会发现所有相关的索引答案之前一点点。

相关问题