Get Attribute Admin Option Value by Option ID or Store View Value

custom-options

I'm trying since hours but I'm not able to load the admin option value of a certain attribute. Although I have enough information like option_id and store view value:

$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product','color');
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attributeOptions = $attribute ->getSource()->getAllOptions();

My attribute (name: color) option table looks like

Admin      Default Store View
15            white
20            yellow
22            blue
45            green

Following gives me only the option ids:

$colorOfProduct = "white";
$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product','color');
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attributeOptions = $attribute ->getSource()->getAllOptions();

foreach ($attributeOptions as $option) {
    if ($option['label'] == $colorOfProduct)
    echo $option['value'];
}

I have the Default store view value (i.e. white) and need the assigned Admin value. Unfortunately I don't get it done and appreciate every help.

Best Answer

For getting option value for admin

then you can get by below code and Where 0 is admin store id

$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product','color');
 $collection =Mage::getResourceModel('eav/entity_attribute_option_collection')
                ->setPositionOrder('asc')
                ->setAttributeFilter($attributeId)
                ->setStoreFilter(0)
                ->load();
                echo "<pre>";
                print_r($collection->toOptionArray());
                echo "</pre>";

You need to just change store

 view ids on place of 0;
Related Topic