0

2 つ (またはそれ以上) のカテゴリの製品を表示するブロックを作成したいと考えていました。私はいくつかの方法でそれをやろうとしましたが、うまくいきません。

私が試した方法:

/app/code/local/Mage/Catalog/Block/Product/Fulllist.php (_getProductCollection() 関数を変更した List.php と同じです:)

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ページの1つで:

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

しかし、それはうまくいかないようです。ページは明らかです。不足している部分はありますか?または、それを行う簡単な方法はありますか?

ご挨拶!

4

1 に答える 1

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;
于 2013-08-28T12:01:10.603 に答える