简体   繁体   English

Magento-通过sku获取产品的自定义属性

[英]Magento- Get a custom attribute of a product by sku

I am trying to display the value of a custom attribute using the sku of a product. 我正在尝试使用产品的sku显示自定义属性的值。

Accessing the name attribute works perfectly for me using the following: 使用以下命令,对我来说,访问name属性非常合适:

echo Mage::getModel('catalog/product')->loadByAttribute('sku',$bulb_merge)->getName();

However when i try this for a custom attribute: 但是,当我尝试将此作为自定义属性时:

echo Mage::getModel('catalog/product')->loadByAttribute('sku',$bulb_merge)->getTechnologies();

I receive an integer number. 我收到一个整数。

Id appreciate the help. 我很感谢您的帮助。

thank you 谢谢

Maybe you are receiving an integer because your attribute is a dropdown attribute. 也许您收到一个整数,因为您的属性是一个下拉属性。 It means you are getting the value, and that's correct. 这意味着您正在获得价值,这是正确的。 Then maybe what you are looking for is the frontend value of the attribute, the label, in such case try with this: 然后,也许您正在寻找的是属性的前端值,标签,在这种情况下,请尝试以下操作:

$_product->getResource()->getAttribute('attribute_code')->getFrontend()->getValue($_product);

Hope it helps. 希望能帮助到你。 Regards! 问候!

I don't know what exactly you want but we do not have the custom attribute sets as functions so here you can just use the attribute code to retrieve the data you wanted: 我不知道您到底想要什么,但是我们没有自定义属性集作为函数,因此在这里您可以使用属性代码来检索所需的数据:

$products = Mage::getModel('catalog/product')->getCollection()
              ->addAttributeToSelect('Technologies')
              ->addAttributeToSelect('sku');

foreach ($products as $product){
    $technology = $product->getAttributeText('Technologies');

    echo $technology;
    echo"<br>";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM