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.

asked Jun 30, 2014 at 16:38

4 Answers 4

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;
answered Jun 30, 2014 at 17:50
1
  • You pointed me in the right direction. Thank you so much for your help! I'm gonna post my full solution tomorrow. Commented Jun 30, 2014 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";
}
Qaisar Satti
32.6k18 gold badges88 silver badges138 bronze badges
answered Jul 1, 2014 at 7:23
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());
answered Nov 17, 2016 at 11:54
0

set store id before retriving value

$attribute->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID)->getFrontend()->getValue($product)
answered Dec 9, 2020 at 15:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.