0

我有 Magento 版本。1.5.0.1,我需要向产品添加过滤器。就像我有 2 个类别“A”和“B”,只有当产品同时存在(“A”和“B”)类别时才应显示结果。我用过这个代码但没有成功

$_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' => '4'),array('finset' =>'5'))) ->addAttributeToSort('created_at', ‘降序’);

任何帮助将不胜感激

谢谢

4

1 回答 1

0

希望对你有帮助

$collection = Mage::getModel('catalog/product')->getCollection()
             ->addAttributeToSelect('*')
             ->addFieldToFilter('is_saleable',1)
             ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
             ->addAttributeToFilter('category_id', array(
                 array('finset' => '4'),
                 array('finset' => '8'))
               )
             ->addAttributeToSort('created_at', 'desc');

4 & 8 是类别 ID

于 2013-10-10T11:30:12.640 回答