Skip to main content
replaced http://magento.stackexchange.com/ with https://magento.stackexchange.com/
Source Link

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

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 frontend

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 frontend

one typo but had to get up to 6 characters to be able to save
Source Link

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

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

// Create a collection and filter childschild 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_ENABLESTATUS_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 frontend

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

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 frontend

added 119 characters in body
Source Link
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

// 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('*')->
           addAttributeToFilter('entity_id', array('in' =>  array_values($childIds[0])))->addAttributeToFilter(
'status',
array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLE)

);;

// group by color attribute

$collection->groupByAttribute('color');
foreach($collection as $eachPro){


}
<?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

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

// 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('*')->
           addAttributeToFilter('entity_id', array('in' =>  array_values($childIds[0])))->addAttributeToFilter(
'status',
array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLE)

);;

// group by color attribute

$collection->groupByAttribute('color');
foreach($collection as $eachPro){


}

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

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

added 105 characters in body
Source Link
Amit Bera
  • 77.7k
  • 20
  • 124
  • 239
Loading
added 236 characters in body
Source Link
Amit Bera
  • 77.7k
  • 20
  • 124
  • 239
Loading
Source Link
Amit Bera
  • 77.7k
  • 20
  • 124
  • 239
Loading