Magento – Get values of your attribute option text from product

attribute-optionsmagento-1.9product-attributestore-view

I want to get value of attribute option text from product based on store id. I want to get admin text for attribute option.

$attribute_option_id = Mage::getResourceModel('catalog/product')->getAttributeRawValue($product_id,'my_attribute', $storeId);
        $product = Mage::getModel('catalog/product')
            ->setStoreId($storeId)
            ->setData('my_attribute', $attribute_option_id);

        $attributeText = $product->getAttributeText('my_attribute');

I am always getting value of default store view. enter image description here

Best Answer

Create a function getAttributeAdminLabel() in your block and call this on page where you want.

$storeId = 1; //add you store id
$attribute_option_id = Mage::getResourceModel('catalog/product')->getAttributeRawValue($product_id, 'my_attribute', $storeId);
$product = Mage::getModel('catalog/product')
        ->setStoreId($storeId)
        ->setData('my_attribute', $attribute_option_id);

echo $attributeText = $this->getAttributeAdminLabel('my_attribute', $product);

function getAttributeAdminLabel($attributeCode, $product) {
    $entityType = Mage::getModel('eav/config')->getEntityType('catalog_product');
    $attributeModel = Mage::getModel('eav/entity_attribute')->loadByCode($entityType, $attributeCode);
    $_collection = Mage::getResourceModel('eav/entity_attribute_option_collection')
            ->setAttributeFilter($attributeModel->getId())
            ->setStoreFilter(0)
            ->load();
    foreach ($_collection->toOptionArray() as $_cur_option) {
        if ($_cur_option['value'] == $product->getMyAttribute()) {
            return $_cur_option['label'];
        }
    }
    return $item->getLabel();
}
Related Topic