In this instead of using Mage::getModel('catalog/product_type_configurable')
and getting child product color option.
You can use product collection resource model Mage::getResourceModel('catalog/product_collection')
and filter that collection by that configurable child ids
Then group by that collection attribute color using function groupByAttribute($attributeCode)
. and you get your desire result
<?php // get child ids in an array $childIds=Mage::getResourceSingleton('catalog/product_type_configurable') ->getChildrenIds($_product->getId()); // Create a collection and filter child ids $collection =Mage::getResourceModel('catalog/product_collection') ->addAttributeToSelect('color') ->addAttributeToFilter('entity_id', array('in' => array_values($childIds[0]))) ->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED)); // groupByAttribute($attributeCode) $collection->groupByAttribute('color'); foreach($collection as $eachPro){ $colors[]=$eachPro->getAttributeText('color'); }
Note:
If catalog product flat enable then the collection does not contain disable product.For getting disable products
in collection whenever flat enable,then use question: How to get disable product collection whenever flat enable at frontendHow to get disable product collection whenever flat enable at frontend