Tag Archives: Get configurable option and value if parent and child known

Get configurable option and value if parent and child known

Suppose configurable product id is $configProductId and the Simple
product id is $simpleProductId.
Fetch configurable attributes values.

$product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($configProductId);
$attributes = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product); 

Now load simple product by simple product id.

$child = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($simpleProductId);


foreach ($attributes as $attribute){
    //ID of the option will give
    echo $attribute['store_label'].' = '.$child->getData($attribute['attribute_code']).'<br />'; 

    //LABEL of the option Will give
    foreach ($attribute['values'] as $value){
        $childValue = $child->getData($attribute['attribute_code']);
        if ($value['value_index'] == $childValue){
            echo $attribute['store_label'].' = '.$value['store_label'].'<br />';
        }
    }
}