Magento Product Collection Get only products from specific categories.

I am trying to get a list of products that have a selling price only in certain categories. Now I'm trying to use a collection of products to get this data. I am not sure how I was going to limit the collection to certain categories only. Here is what I still have:

$products = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('status', 1)
    ->addAttributeToFilter('visibility', 4)
    ->addAttributeToFilter('special_price', array('neq' => ""))
    ->addAttributeToFilter('discontinued', array('neq' => 1))
    ->setPageSize(10)
    ->setOrder('price', 'ASC')
    ;

A disabled attribute is a custom attribute that we use to prevent products from being displayed, as well as not 404.

Is there a way to use a product model and limit certain categories?

+5
source share
1 answer

. , . :

$products = Mage::getModel('catalog/category')->load(410)
    ->getProductCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('status', 1)
    ->addAttributeToFilter('visibility', 4)
    ->addAttributeToFilter('special_price', array('neq' => ""))
    ->addAttributeToFilter('discontinued', array('neq' => 1))
    ->setOrder('price', 'ASC')
    ;
+5

All Articles