2

On my category page I am trying to show all it's products, even though they are all disabled.

On the category page I am using:

$categoryModel = Mage::getModel('catalog/category');
$_category  = $this->getCurrentCategory();
$_category_id  = $_category->getId();

$products = $categoryModel->load($_category_id)
->getProductCollection()
->addAttributeToSelect(array('id', 'name','etc...'))
->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_DISABLED);

But my collection is always empty.

I have also tried using:

->addAttributeToFilter('status', 2)

Without success. If i switch the filter to enabled products with either:

->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)

->addAttributeToFilter('status', 1)

Then (in any other category where products are enabled) then the collection shows all products.

I have flat catalog turned off/set to No in my configuration.

1 Answer 1

5

Take a look at Mage_Catalog_Model_Category::getProductCollection():

public function getProductCollection()
{
    $collection = Mage::getResourceModel('catalog/product_collection')
        ->setStoreId($this->getStoreId())
        ->addCategoryFilter($this);
    return $collection;
}

That ProductCollection::addCategoryFilter() call does quite a lot of stuff related to category products display logic, mainly via ProductCollection::_applyProductLimitations().

You can set up a frontend observer to consume the catalog_product_collection_apply_limitations_after event dispatched in _applyProductLimitations(). You might need to start with debugging the collection in your observer to get the current SELECT statement which you'll need to bang your logic onto.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.