I am trying to get attribute text, but it only works for simple products.

This is what I am doing:


    $products = Mage::getModel("catalog/product")->getCollection()
                        ->addAttributeToFilter('type_id', 'configurable')
                        ->setOrder('entity_id', 'DESC');

    foreach($products as $product){
        $attr = 'attribute_name';
        var_dump( $product->getResource()->getAttribute($attr)->getFrontend()->getValue($product) ); // returns NULL or 'no' 

It returns NULL or 'no'. Which is, I think, weird behaviour.


If it returns "No" that means that there is no value added for that attribute for a product. Most probably it is because the attribute is not assigned for a particular product type.
Make sure that your attribute with id attribute_name is Applied to to configurable products.
If it is available for Configurable Products then the issue is because you have not added addAttributeToSelect in your collection.

$products = Mage::getModel("catalog/product")->getCollection()->addAttributeToSelect("attribute_name")
    ->addAttributeToFilter('type_id', 'configurable')
    ->setOrder('entity_id', 'DESC');

Try with this code. If it still shows "No" then there is no value added in that product for your attribute.

  • Thanks! In production code, there will be another foreach loop that loops trough a set of predefined attributes... Is there a way to do this differently than directly getting an attribute with all the products? – xvilo Mar 11 '17 at 15:25
  • You can use addAttributeToSelect("*") to get all product attributes and then you can get value of any attribute. – Jaimin Sutariya Mar 11 '17 at 16:43
  • @JaiminSutariya i want to get products info, my code : justpaste.it/4yyqf and my output : snag.gy/y7iZav.jpg can you pls help me to solve the error? – zus Nov 14 '18 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.