0

How do I get all disabled products in the current category

<?php 
    $categoryIds = array(956);//category id
    $products = Mage::getResourceModel('catalog/product_collection')
    ->addCategoryFilter(Mage::getModel('catalog/category')->load($categoryIds));
    $collection = Mage::getModel('catalog/product')->getCollection()
        ->addFieldToFilter('entity_id', array('in' => $products->getAllIds()))
    ->addAttributeToSelect('*');
 ->addFieldToFilter('status',Mage_Catalog_Model_Product_Status::STATUS_DISABLED);

?>
1
  • Have you set the website id ? Mar 29, 2016 at 11:26

3 Answers 3

1

When you want to get products from category using $productCollection->addCategoryFilter() or using $category->getProductCollection() query use product to category connection INDEX table. When you run re index that product category connection INDEX table is populated only with Enabled porducts, and you can not get disabled products on that way.

$categoryId = 956; // a category id that you can get from admin

For Disable Product

$collection = Mage::getModel('catalog/product')
->getCollection()
 ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
->addAttributeToSelect('*')
->addAttributeToFilter('status', array('eq' => 2))
 ->addAttributeToFilter('category_id',  array('eq' => $categoryId));
9
  • I already tried No result
    – Magento 2
    Mar 29, 2016 at 11:23
  • Updated answer check it Mar 29, 2016 at 11:41
  • No luck i already try this all solution
    – Magento 2
    Mar 29, 2016 at 11:58
  • It is working for me. what is the error ? Mar 29, 2016 at 12:11
  • it shows empty page i disabled 1 product]
    – Magento 2
    Mar 29, 2016 at 12:12
0

Try this way

$products = Mage::getModel('catalog/category')->load(956)
->getProductCollection()
->addAttributeToSelect('*')
->addAttributeToFilter(
    'status',
    array('eq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED)
);
3
  • No luck i already try this all solution
    – Magento 2
    Mar 29, 2016 at 11:58
  • did you try to re-index the data? Mar 29, 2016 at 12:04
  • Everthing is ready to index only
    – Magento 2
    Mar 29, 2016 at 12:05
0

I have tested this code in Magento 1.9 and working fine hope it will work for you.

$catId = 45;
$products = Mage::getModel('catalog/category')->load($catId)
     ->getProductCollection()
     ->addAttributeToSelect('*') // add all attributes - optional
     ->addAttributeToFilter('status', 2);


    foreach ($products as $pid)
    {
        echo    $pid->getName(); 

    } 
1
  • No luck i already try this all solution
    – Magento 2
    Mar 29, 2016 at 11:58

Your Answer

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

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