如何从magento getCollection中排除类别 [英] How to exclude a category from a magento getCollection

查看:103
本文介绍了如何从magento getCollection中排除类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个愚蠢的问题,但是很好.我有以下代码可检索我商店中的所有产品.

this might be a silly question, but well. I have the following code that retrieves all the products on my shop.

$products = Mage::getModel('catalog/product')->getCollection();
$products->addAttributeToFilter('status', 1);
$products->addAttributeToFilter('visibility', 4);
$products->addAttributeToFilter('type_id', 'simple');
$products->addAttributeToSelect('*');
$products->addStoreFilter($storeId);
$prodIds = $products->getAllIds();

我知道:

$category = Mage::getModel('catalog/category')->load(9);
$products->addCategoryFilter($category);

按类别ID进行过滤,但是如何之外的所有产品都获得一个特定的类别ID? (Magento 1.6.2)

to filter by a category ID, but how to get all products except one specific category ID ? (Magento 1.6.2)

推荐答案

我认为这应该可行,前提是您知道要过滤的类别ID,但现在无法测试

I think this should work, presuming you know what category ID you want to filter out, but I can't test it right now

$catId = 9;

/* I'm almost positive 'e' is the alias used for catalog_product_entity, check your
   query with echo (string) $products->getSelect(); if it doesn't work */
$products->getSelect()->join(array('cats' => 'catalog_category_product'), 'cats.product_id = e.entity_id');
$products->getSelect()->where('cats.category_id', array('neq' => $catId));

这篇关于如何从magento getCollection中排除类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆