Question

Hello I want to get category and it's child categories product collection base on the custom attribute values.

like 3 is parent category and 31,32,33,34,35 all are it's child categories

then i want all the product which have color "Red" in 3,31,32,33,34,35 categories.

Était-ce utile?

La solution

Below collection will sure work for you.

$_productCollection = Mage::getResourceModel('catalog/product_collection')->joinField('category_id','catalog/category_product','category_id','product_id=entity_id',null,'left')
    ->addAttributeToFilter('category_id', array('in' => $catID)) // may be Use finset instead of eq
     ->addAttributeToFilter('your_attribute',
         array('eq' => Mage::getResourceModel('catalog/product')
            ->getAttribute('your_attribute')
            ->getSource()
            ->getOptionId($your_attribute_value)
        )
    )
    ->addAttributeToSelect('*');
    $_productCollection->load();

    foreach($_productCollection as $_product){ 
        echo $this->htmlEscape($_product->getName())."<br/>"; 
    };

hope this could solve your problem

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top