7

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.

4

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;
  • You pointed me in the right direction. Thank you so much for your help! I'm gonna post my full solution tomorrow. – Stefan Jun 30 '14 at 18:20
2

Here my full solution for a certain problem. Perhaps someone can use it.

    function getImgColor($productId, $colorOfProduct)
    {
    $optionId = Mage::getResourceModel('catalog/product')->getAttributeRawValue($productId, 'color', 1);

    $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();

    $collection = $collection->toOptionArray();

    foreach ($collection as $option) {
        if ($option['value'] == $optionId) {
            $img = $option["label"];
            break;
        }
    }

    return file_exists(Mage::getBaseDir('media')."/colorall/_thumbs/color/".$img.".png") ? "<img src=\"".Mage::getBaseUrl('media')."colorall/_thumbs/color/".$img.".png\" title=\"".$colorOfProduct."\" />" : Mage::getBaseDir('media')."/colorall/_thumbs/color/".$img.".png";
}
0

You can do this more simply in a single call as follows:

Example attribute 'gender' to get custom attribute value for and we are using the magic method getGender() to do the equivalent of getData('gender')

$gender = Mage::getModel('catalog/resource_eav_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'gender')->getSource()->getOptionText($product->getGender());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.