2

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

2
  • try again with remove $storeid from your script. Oct 16 '17 at 9:36
  • I tried using below snippet but still receiveing default store view value: $product = Mage::getModel('catalog/product')->load($product_id); $attributeText=$product->getAttributeText('my_attribute');
    – user00247
    Oct 16 '17 at 9:41
0

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();
}
0

Try This:

Mage::getResourceSingleton('catalog/product')->load($product_id)
    ->getAttribute('color')
    ->getSource()->getOptionText($customer->getColor());
0
$productAttribute = $product->getResource()->getAttribute('my_attribute');

$attriuteValue = $productAttribute->setStoreId($store_id)
                                  ->getSource()
                                  ->getOptionText($product->getData('my_attribute'));

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.