0
votes

I have Magento ver. 1.5.0.1 and I need to add filter to product.Like I have 2 categories 'A' and 'B',result should be shown only if product exist in both('A' and 'B') categories.I have used this code but no success

$_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', 'desc');

Any help will be highly appreciated

Thanks

1

1 Answers

0
votes

hope this will help you

$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 is category ids