I'm having issue trying to get all the products that aren't in a specific category. Here's a code that works fine until I added the 'join-nin' query.
$collection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSelect('*') ->addAttributeToSort('created_at', 'desc') ->addAttributeToFilter( 'status', ['eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED]) ->addAttributeToFilter('visibility', [ 'in' =>[ 2, 4 ] ]); Here's my 'join-nin'
$collection = $collection->joinField('category_xxx', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left') ->addAttributeToFilter('category_xxx', ['nin'=>24]) Now I know that currently, it would give me duplicate products (result) for some reason so I have to group the result by 'e.entity_id'
$collection->getSelect()->group('e.entity_id'); Then when I looped through the collection and print/echo their Ids, I see the product which I specifically assigned to that category (24).
TLDR: I need to query all products with using 'in' and 'nin' for any categories.