0

現在、カテゴリ内の製品と、どのカテゴリにも属していない製品があります。このコード スニペットは、Magento に最近追加されたすべての製品を提供します。

$_productCollection = Mage::getResourceModel('catalog/product_collection')
                ->addAttributeToSelect('*')
                ->addAttributeToFilter($preorderAttribute, array(
                    'eq' => Mage::getResourceModel('catalog/product')
                        ->getAttribute($preorderAttribute)
                        ->getSource()
                        ->getOptionId($preorderValue)
                ))
                ->setVisibility(array(2,3,4))
                ->setOrder('created_at', 'desc')
                ->setPage(1, 12);

ただし、どのカテゴリにも属さない製品も提供します。1 つ以上のカテゴリに含まれる製品のみが必要で、どのカテゴリにも属さない製品は必要ありません。

上記のコードでこれを行うにはどうすればよいですか?

4

1 に答える 1

0

以下のコードは、特定の 2 つのカテゴリの製品のみを表示するために機能します。うまくいくことを願っています。

 $_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' => '7'),
                        array('finset' => '8'))
                )
                ->addAttributeToSort('created_at', 'desc');
            foreach($_productCollection as $_testproduct){
                echo $_testproduct->getId()."<br/>";

            };
于 2013-08-24T05:06:21.883 に答える