Back to Top

Attribute options from attribute code magento

Updated 25 January 2018

How to get all attribute options from attribute code

Use the following code to retrieve all attribute options from attribute code

try {
    $attr_code = 'color';
    $attributeInfo=Mage::getSingleton('eav/config')
                   ->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attr_code);

    $attributeOptions = $attributeInfo->getSource()->getAllOptions(false);

    foreach ($attributeOptions as $key=>$attributeOption) {
        echo 'Label: '.$attributeOption['label'];
        echo 'Value: '.$attributeOption['value'];
    }
} catch (Exception $e) {
    echo $e->getMessage();
}

Happy coding 🙂

Searching for an experienced
Magento Company ?
Find out More
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home