2013-08-28 71 views
0

我想創建一個可顯示2個(或更多)類別產品的塊。我試圖用幾種方法做到這一點,但它們不起作用。Magento 1.7顯示塊中的2個類別中的產品

我怎樣努力:

/app/code/local/Mage/Catalog/Block/Product/Fulllist.php (同list.php的具有改變_getProductCollection()函數:)

protected function _getProductCollection() 
{ 
$_productCollection = Mage::getModel('catalog/product') 
    ->getCollection() 
    ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left') 
    ->addAttributeToSelect('*') 
    ->addAttributeToFilter('category_id', array(
     array('finset' => '30'), 
     array('finset' => '32')) 
    ) 
     ->addAttributeToSort('created_at', 'desc'); 

     return $_productCollection; 
} 

然後,在CMS頁面中的一個我試圖用:

{{block type="catalog/product_fulllist" template="catalog/product/list.phtml"}} 

但是,這似乎並沒有工作,頁面是明確的。我錯過任何部分?還是有更簡單的方法來做到這一點?

問候!

回答

0

您好檢查下面的代碼

$collection = Mage::getModel('catalog/product')->getCollection(); 

$collection->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id=entity_id', null, 'left'); 

$collection->addAttributeToFilter('category_id', array('in' => array('finset'=>'30,31'))); 

$collection->addAttributeToSort('created_at', 'desc'); 

$collection->addAttributeToSelect('*'); 

return $collection; 
+0

不幸的是沒有,當我打印出來的查詢,它看起來像:[鏈接](http://pastebin.com/tZQGL44X)我注意到的是有沒有WHERE子句在那種查詢中常見?有些東西顯然不適用。先生,謝謝您的幫助! – jwitos

相關問題