If you have the attribute code and the option value id for the data, then we can get the text value for the option by the below code. The below code is for product, you can use the same logic to get the data for other eav resource models like customer, category, etc.
public function getOptionValue($field, $value) {
$attribute = $this->getAttribute($field);
if (!is_null($value) && $attribute) {
if ($attribute->usesSource()) {
$text_value = array();
foreach(explode(",", $value) as $sub_value) {
$text_value[] = $attribute->getSource()->getOptionText($sub_value);
}
return implode("|", $text_value);
}
}
return $value;
}
The function take attribute code and value as input. If the attribute uses source to get the values, then get the text for the option id, else it return the value as it, as it is not an option.
You can get the attribute data from the link http://mage-simplified.blogspot.in/2016/02/magento-get-attributes-from-attribute.html
Comments
Post a Comment