I am trying to get the available size based on color

$attValConfig = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);

It is returning both color and size but I want color first after that sizes based on color.

foreach($attValConfig as $attValConfigSingle) {


   //Output Color and Size

1 Answer 1


You could get those options by getting the available child products and matching the option values like this:

//get all attributes
$configAttributesArray = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);

//filter so only color is left and select the values in the array
$configAttributesFilteredByColor = array_filter($configAttributesArray, function($v) { return $v['label'] == 'Color'; });
$configAttributesFilteredByColorValues = $configAttributesFilteredByColor[key($configAttributesFilteredByColor)]['values'];

//get the configurable product its childproducts

$childProducts = Mage::getModel('catalog/product_type_configurable')

//loop the values, and the childproducts and match them
foreach($configAttributesFilteredByColorValues as $configAttributeValue){
    echo $configAttributeValue['label'] . '<br />';
    $value = $configAttributeValue['value_index'];
    foreach($childProducts as $childProduct){
        if($childProduct->getColor() == $value){
            echo $childProduct->getAttributeText('size') . '<br />';

If you are planning to use this on configurable products pages the price will not update anymore. If you are aiming for that functionality you should take a look at the function getJsonConfig in Mage_Catalog_Block_Product_View_Type_Configurable and refactor that to your needs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.