doulin6448 2015-02-13 15:40
浏览 8

too long

my situation: 1-column.phml

 echo $this->getLayout()
    ->createBlock('catalog/product_list')
    ->setTemplate('page/html/home-block-top.phtml')
    ->toHtml(); 

then home-block-top.phtml

$_productCollection2 = Mage::getResourceModel('reports/product_collection')->addViewsCount();
$_productCollection2->addCategoryFilter( Mage::getModel('catalog/category')->load(87) );
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($_productCollection2);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($_productCollection2);
$_productCollection2->setPageSize(4)->setCurPage(1);

I get this error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'report_table_views.entity_id' in 'on clause'

Someone can help me? Thanks

  • 写回答

2条回答 默认 最新

  • dongxue7306 2015-02-13 16:06
    关注

    I don't think you can use those filters in a reports collection if you use addViewsCount. I guess if you need addViewsCount you could create a product collection out of the product ids of the report, and then apply the filters. Something like this:

    $mostViewed = Mage::getResourceModel('reports/product_collection')->addViewsCount();
    $productIds = array();
    
    foreach ($mostViewed as $product) {
       $productIds[] = $product->getId();
    }
    
    // Load a collection of the most viewed products and then apply the desired filters
    $_productCollection2 = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('entity_id', array('in' => $productIds));
    $_productCollection2->addCategoryFilter( Mage::getModel('catalog/category')->load(87) );
    Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($_productCollection2);
    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($_productCollection2);
    $_productCollection2->setPageSize(4)->setCurPage(1);
    

    I think something like that might work, not sure if there are better ways though. I hope it helps!

    评论

报告相同问题?

悬赏问题

  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏