Ali
Ali

Reputation: 154

How to get product attribute value in magento

I have a very weird problem, I can get the product attribute value in local but when I go to the live server, I get an empty value. Magento version 1.6.2.

To get the attribute value, I use this code :

$product = Mage::getModel('catalog/product')->load($_item->getProductId());
$my_attribute = $product->getAttributeText('my_attribute');

PHP 5.3 and apache 2.2 on both local and live server

Upvotes: 5

Views: 40537

Answers (1)

Girish Hosamani
Girish Hosamani

Reputation: 1203

Try these things :

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

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

OR

    $_id = $this->getProduct()->getId();
$_resource = Mage::getSingleton('catalog/product')->getResource();
$optionValue = $_resource->getAttributeRawValue($_id,  [ATTRIBUTE_ID/ATTRIBUTE_CODE], Mage::app()->getStore());
echo $optionValue;

OR

$attribute_value = $product->getResource()->getAttribute($attribute_code)->getFrontend()->getValue($product);

Cheers :-)

Upvotes: 28

Related Questions