Skip to main content
4 of 6
added 119 characters in body
Amit Bera
  • 77.7k
  • 20
  • 124
  • 239

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 childs ids in array
$childIds=Mage::getResourceSingleton('catalog/product_type_configurable')

    ->getChildrenIds($_product->getId());

// Create a collection and filter childs 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_ENABLE));


//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 frontend

Amit Bera
  • 77.7k
  • 20
  • 124
  • 239