How to get product attribute value in magento

I have a very strange problem, I can get the value of the product attribute in the local one, 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 local and live server

+5
source share
1 answer

Try the following:

  $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); 

Greetings :-)

+28
source

Source: https://habr.com/ru/post/1208764/


All Articles