Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get product attribute value in magento

Tags:

php

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

like image 617
Ali Avatar asked Dec 10 '14 21:12

Ali


People also ask

How do I get customer attribute value in Magento 2?

You can get customer custom_attribute value by, $customer = $CUSTOMER_OBJECT; // GET customer object $customer->getCustomAttribute('mobile')->getValue(); return will be your customer custom_attribute mobile value.

What is the setting that determines that an attribute value will show on the product page?

The “Add to Column Options” setting determines whether the attribute will be displayed in the product grid on your store's backend.

What are attributes in Magento?

Magento 2 uses attributes to manage the information associated with products. An attribute is a property of a product, for example, the product color, the size, or the description. Some attributes are built into the system by default, and others can be created to address specific needs.


1 Answers

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 :-)

like image 170
Girish SH Avatar answered Sep 27 '22 15:09

Girish SH