How to make everything turn on and off products from a certain category?

I am trying to get all enabled and disabled products and I am using this code:

/*$categoryId = 3; // a category id that you can get from admin
    $category = Mage::getModel('catalog/category')->load($categoryId);

    $collection = Mage::getModel('catalog/product')
                    ->getCollection()
                   ->addCategoryFilter($category)
                    ->addAttributeToSelect('*')
                    ->addAttributeToFilter('status', array('gt' => 0))
                    ->load();

$categoryId = 3; // a category id that you can get from admin
    $category = Mage::getModel('catalog/category')->load($categoryId);*/

The above code only displays allowed products.

Commenting on the status filter, it still brings the same result, that is, only allowed products.

    /*$collection = Mage::getModel('catalog/product')
                    ->getCollection()
                   ->addCategoryFilter($category)
                    ->addAttributeToSelect('*')
                    //->addAttributeToFilter('status', array('gt' => 0))
                    ->load();*/

It still contains only Enabled products. But when I comment on the category check, what brings n of all products :( Can anyone help PLZ?

Note:

For those who do not understand this issue, let me tell you that Status is enabled = 1 and Status is Disabled = 2 .

, , , , , . ???

$collection = Mage::getModel('catalog/category')->load(3)
                    ->getProductCollection()
                    ->addAttributeToSelect('*')
                    ->addAttributeToSort('entity_id', 'ASC');

die((string) $collection->getSelect());

:

SELECT `e`.*, `cat_index`.`position` AS `cat_index_position` FROM `catalog_product_entity` AS `e` INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.category_id='3' ORDER BY `e`.`entity_id` ASC
+5
4

, .

, , $productCollection->addCategoryFilter() $category->getProductCollection() INDEX . , . INDEX Enabled, . Magento , , Raw SQL .

+8

, , .

233 44 , .

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

$category = Mage::getModel('catalog/category')->load($categoryId);

$collection = Mage::getModel('catalog/product')
    ->getCollection()
    ->addCategoryFilter($category)
    ->addAttributeToSelect('*')
//  ->addAttributeToFilter('status', array('gt' => 0)) //filter commented, show all products
    ->load();

echo $collection->count(); // 44 products


$category = Mage::getModel('catalog/category')->load($categoryId);

$collection = Mage::getModel('catalog/product')
    ->getCollection()
    ->addCategoryFilter($category)
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('status', array('eq' => 1)) //show only enabled
    ->load();

echo $collection->count(); // 44 products

$collection = Mage::getModel('catalog/product')
    ->getCollection()
    ->addCategoryFilter($category)
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('status', array('eq' => 2)) //only disabled 
    ->load();

echo $collection->count(); // 0 products

, , , .

+3

You use ->addAttributeToFilter('status', array('gt' => 0))in your collection, which filters the included products, so you can delete this line to get all products

+2
source

You can use the constant. Magento Mage_Catalog_Model_Product_Status::STATUS_DISABLEDwill only return products that are disabled in the category.

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

All Articles