Magento - get all attribute value

I need to get a list of all the color attribute values. when i use this code

$name='color';
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($name)->getFirstItem();
$attributeId = $attributeInfo->getAttributeId();
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attributeOptions = $attribute ->getSource()->getAllOptions(false); 

In this case, I get a list like this:

 (
        [0] => Array
            (
                [value] => 6
                [label] => blueAdmin
            )
        [1] => Array
            (
                [value] => 5
                [label] => coralAdmin
            )
        [2] => Array
            (
                [value] => 3
                [label] => redAdmin
            )
        [3] => Array
            (
                [value] => 4
                [label] => limeAdmin
            )
    ) 

This is a list of all the values ​​displayed in the administration part of the website. How can I get a list of all attribute values ​​that are displayed in the store, and not in the administrative part of the website?

Thank.

+1
source share
1 answer

You can get the attribute parameter values ​​for a specific store by setting the store identifier in the attribute before calling getAllOptions (), for example,

$attributeOptions = $attribute->setStoreId(1)->getSource()->getAllOptions(false);

gets parameter values ​​for the store with identifier 1. You can get the identifier of the current store using

Mage::app()->getStore()->getId();

So, something like this should get what you want:

$storeId = Mage::app()->getStore()->getId();
$attributeOptions = $attribute->setStoreId($storeId)->getSource()->getAllOptions(false);
+2

All Articles