简体   繁体   中英

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.

Accessing the name attribute works perfectly for me using the following:

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>";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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