Attributes – Get Attribute Default Store View Label List

attributes

I'm looking for a function that get all labels of a specific attribute. However the label that I get is the admin view. I would like to show the default store view instead.

Here is my current wrong code :

 $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', '81');
 foreach ( $attribute->getSource()->getAllOptions(true, true) as $option){
    /*some stuff here*/
 }

Thanks for your help !

Best Answer

You can get all options with value using below code:

 $config    = Mage::getModel('eav/config');
    $attribute = $config->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'brand');// change 'brand' with your attribute code.    
    $values    = $attribute->getSource()->getAllOptions(); // first method to get attribute option values

Second Method:

$options = Mage::getResourceModel('eav/entity_attribute_option_collection');
$values  = $options->setAttributeFilter($attribute->getId())->setStoreFilter($storeId)->toOptionArray();

Now to get all labels you can use below code:

foreach($values as $option)
    {
        if(!empty($option['label'])){
         $_labels[] = $option['label'];
        }
    }
    echo '<pre>';
    print_r($_labels);

I hope this will help you :)

Related Topic