Magento:按状态过滤产品 [英] Magento: Filter products by Status
问题描述
我在这里有一些严重的Magento问题。正如预期的那样:
$ products = Mage :: getModel('catalog / category') - > load )
- > getProductCollection()
- > addAttributeToSelect('*')
- > addAttributeToFilter('status',array('eq'=&
将为我的$ category_id返回所有已启用的产品。但是:
$ products = Mage :: getModel('catalog / category') - > load($ category_id)
- > getProductCollection()
- > addAttributeToSelect('*')
- > addAttributeToFilter('status',array('eq'=&
不返回禁用的产品。我似乎找不到退回停用的产品的方法,我不知道为什么。
我试过这个:
Mage :: getSingleton('catalog / product_status') - > addVisibleFilterToCollection($ products);
这意味着工作,但显然可能已被弃用。
有人知道如何获得所有产品的类别,启用和停用?
不用担心,你只是被一个非常不寻常的常数定义^^。只要尝试:
$ products = Mage :: getModel('catalog / category') - > load($ category_id)
- > getProductCollection()
- > addAttributeToSelect('*')
- > addAttributeToFilter(
'status',
array('eq'=> ; Mage_Catalog_Model_Product_Status :: STATUS_DISABLED)
);
无论什么原因,Varien决定定义 STATUS_DISABLED
0
的值,而不是更直观(常用)的值。 p>
I'm having some serious Magento issues here. As expected the following:
$products = Mage::getModel('catalog/category')->load($category_id)
->getProductCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('status', array('eq' => 1));
Will return all enabled products for my $category_id. However this:
$products = Mage::getModel('catalog/category')->load($category_id)
->getProductCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('status', array('eq' => 0));
Does not return disabled products. I can't seem to find a way to return disabled products, and I don't know why.
I've tried this:
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
Which was meant to have worked, but apparently may have been deprecated.
Does anyone know how to get all products in a category, enabled and disabled?
Don't worry, you simply got trapped by a very unusual constant definition^^. Just try:
$products = Mage::getModel('catalog/category')->load($category_id)
->getProductCollection()
->addAttributeToSelect('*')
->addAttributeToFilter(
'status',
array('eq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED)
);
For whatever reasons Varien decided to define this STATUS_DISABLED
constant with a value of 2
, instead of the more intuitive (and commonly used) value of 0
.
这篇关于Magento:按状态过滤产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!