Magento – Get Admin Label of Configurable Option Value

configurable-product

Working in a product view template (.phtml) I am trying to get the Admin label for a configurable option value. I have managed to var_dump the front end values:

$productAttributeOptions = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);

$attributeOptions = array();

foreach ($productAttributeOptions as $productAttribute) {

    foreach ($productAttribute['values'] as $attribute) {

        $attributeOptions[$productAttribute['label']][$attribute['value_index']] = $attribute['store_label'];
    }
}

var_dump($attributeOptions);

This gives me an array:

array (size=1)
  'Configurable Option' => 
    array (size=2)
      378 => string 'Black' (length=5)
      379 => string 'Pink' (length=4)

Which is all fine and dandy. But how would I go about getting the "Admin" values for these options? The reason I would like to do this is because the admin values will contain hex colours that I can use to show a colour for a visitor to select instead of just having a drop down.

Any help is muchly appreciated.

Best Answer

As you have using this at frontend,then you cannot easy get those option. Get need to use option collection and filter the option collection by Attribute id and option ids.

Get Option ids:

Get option list from your code:

    $productAttributeOptions = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);

$attributeOptions = array();
$attributeList=array();
foreach ($productAttributeOptions as $productAttribute) {


    foreach ($productAttribute['values'] as $attribute) {
        $attributeList[$productAttribute['attribute_id']][]=$attribute['value_index'];

        $attributeOptions[$productAttribute['label']][$attribute['value_index']] = $attribute['store_label'];
    }
}

get Admin label:

then call eav option collection then filter collection by option is

 foreach( $attributeList as $key=>$value){
    $attributeId=$key;
    $options=array_unique($value);
            $collection = Mage::getResourceModel('eav/entity_attribute_option_collection');
                $collection->getSelect()->where('main_table.option_id IN (?)',$options);
                $collection->setPositionOrder('asc');
                $collection->setAttributeFilter($attributeId)
                ->setStoreFilter(0);
            $collection->load();
echo "<pre>";
print_r($collection->toOptionArray());

}

and 0 for store admin