Checking if a Magento product is a child of a configurable product

Viewed 26309

I have the following code to grab a list of Products

$collection = Mage::getModel('catalog/product')->getCollection();

$collection->addAttributeToSelect('name')
     ->addAttributeToFilter("category_ids", array('finset'=>$this->category_id));

foreach($collection as $product) {
   echo $product->getName();
}

My question is, how can I NOT echo products that are 'simple' but belong to a parent 'configurable' product. (for example don't show "Red Shirt Medium" as it belongs to "Red Shirt")

I have worked out that this association lives in 'catalog_product_super_link' but I have only just started with Magento and unfortuantely don't know how to do the filtering :)

Cheers guys,

Chris.

5 Answers

The quickest way might be to check if the product's visibility is set to "Not Visible Individually", since simple products associated with configurable products are typically set to this. Unfortunately I don't know the precise syntax but hopefully someone else who's willing to chime in does!

Related