3 Comments

get all disabled products in current category

Add one image to all products
Rearrange product collection in magento

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);

?>

Related Posts

  • How to filter product collection using category id in flat mode (3)
    I have flat mode enabled and I need to filter the product collection using category id, but I am not able to. Here below is my code... $productCollection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSelect('*') […]
  • Create product collection in PHTML with filter based on Category ID (1)
    We want to get a Product Collection based on a filter with the category ID. In our case, we have the desired Category with ID 43. Our Call looks like this: $objectManager = MagentoFrameworkAppObjectManager::getInstance(); $productCollection = […]
  • Custom filters to get product magento (2)
    I am trying to filter with multiple category and custom attribute but the code its not working please let me know whats wrong with my code $type1=array(); foreach($_REQUEST['type'] as $tyof) { $implodetype=$tyof.','; $type1[]=$implodetype; } foreach($type1 as $categoryid){ $category […]
  • Load custom collection with multiple category ids (1)
    I am using magento 1.9 version. I am having custom collection which consists category ids. I tried to get the collection based on the category ids. I followed this link. I tried with this code too. $collection->addAttributeToFilter('category_id', array('in' => array('finset' […]
  • Disabling programmatically the flat catalog category not working (1)
    I have an import routine that needs to be run periodically to mass-import categories. It processes a tree like structure of category data, and creates any categories that don't exist. The difficulty I face is that because flat catalog is enabled on the store, even after the […]
  • All categories list the same products (0)
    When I have the blocks HTML output cache enabled every category will display the same list of products. Disabling the cache solves the issue but I'd prefer to keep the cache enabled. Has anyone dealt with this before? Running on v1.9.2.4
  • How to mass delete products from disabled categories? (2)
    I have a lot of products that are part of disabled categories. Is there a way for me to delete them all? I want to tell it the ID of the category and then delete all the products under that category. Is this possible? Thank you very much!
  • Get all products of a category only – without products of its child categories (3)
    I'm trying to get all products of a certain category. Unfortunately I always get not only all products of the category but also all products from its child categories. What am I doing wrong? For example I'm working with following code snippet: $catId = 160; $category = […]
  • Get product IDs of current category page (1)
    I would like to get all the product IDs from the current category page. I don't want to load the whole collection, I just need to get the product IDs from the products currently displayed. E.g.: Customer goes on category, order is set to price descending, number of displayed […]
  • Magento 2: get product collection using category id (2)
    How to get all products of category using category id in magento 2?
Add one image to all products
Rearrange product collection in magento

3 Comments on this article

  • User November 12, 2016

    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));
    

    Reply

  • User November 12, 2016

    Try this way

    $products = Mage::getModel('catalog/category')->load(956)
    ->getProductCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter(
        'status',
        array('eq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED)
    );
    

    Reply

  • User November 12, 2016

    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(); 
    
        } 
    

    Reply

Add a comment