php 如何在magento中获取产品属性值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27410748/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:21:24  来源:igfitidea点击:

How to get product attribute value in magento

phpmagento

提问by Ali

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.

我有一个很奇怪的问题,我可以在本地获取产品属性值,但是当我转到实时服务器时,我得到一个空值。Magento 版本 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

本地和实时服务器上的 PHP 5.3 和 apache 2.2

回答by Girish SH

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

干杯:-)