Magento:在不加载整个产品的情况下获取自定义属性值 [英] Magento: Get a custom attribute value without loading the entire product

查看:81
本文介绍了Magento:在不加载整个产品的情况下获取自定义属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此刻,我使用它来获取自定义属性值:

At the moment I use this to get a custom attribute value:

$_item = $this->getProduct()->getId();
$_product = $_product = Mage::getModel('catalog/product')->load($_item);  
$optionvalue = $_product->getCustomAttributeValue();
echo $optionvalue;

我想知道有没有一种更简单的方法来获得此自定义值,而无需加载整个产品?

I wonder is there an easier way to get this custom value without loading the entire product?

推荐答案

这取决于您正在运行的Magento版本.不同的版本有不同的产品.如果您运行的是Community Edition 1.6+,则Catalog模块有一个非常适合您的方法

This depends on which version of Magento you're running. Different versions have different offerings. If you're running Community edition 1.6+, the Catalog module has a very nice method just for you!

请尝试以下操作:

$_item = $this->getProduct()->getId();
$_resource = $this->getProduct()->getResource();
$optionValue = $_resource->getAttributeRawValue($_item, 'custom_attribute_value', Mage::app()->getStore());
echo $optionvalue;

如果您有兴趣,可以深入了解Mage_Catalog_Model_Resource_Abstract,看看这个小家伙在做什么.从本质上讲,它只是一个查询(就像一个EAV一样,它是一个相当复杂的查询),用于检索您要查询的一个属性(或您要查询的多个属性,因为您也可以传递数组).

If you're interested, you could dive down into Mage_Catalog_Model_Resource_Abstract to see what this little guy is doing. It's essentially just a query (admittedly a rather complex one, as EAV tends to be) to retrieve the one attribute you asked for (or the multiple attributes you asked for, since you can pass an array as well).

这篇关于Magento:在不加载整个产品的情况下获取自定义属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆