Skip to content

Instantly share code, notes, and snippets.

@pierreandreroy
Last active December 24, 2019 15:46
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save pierreandreroy/6251977 to your computer and use it in GitHub Desktop.
Save pierreandreroy/6251977 to your computer and use it in GitHub Desktop.
Get all possible value (dropdown options) of a product attribute in Magento.
<?php
//Possible color value
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'color'); //"color" is the attribute_code
$allOptions = $attribute->getSource()->getAllOptions(true, true);
foreach ($allOptions as $instance) {
$id = $instance['value']; //id of the option
$value = $instance['label']; //Label of the option
}
?>
@tahiryasin
Copy link

nice !

@latheesan-k
Copy link

Thanks, just what I needed!

@nshiff
Copy link

nshiff commented Apr 1, 2016

It works for me! Now I don't have to hard-code 1878 as a magic number. 👍

@PatrickBenn
Copy link

Nice its really use full thanks

@shaileshkhunt
Copy link

Thanks a lot ... It works...

@aaditya-s
Copy link

can someone say where is the definition for getAllOptions()? Is it possible to rewrite this method. i was to pass custom filter options which should be independent of any layered navigation plugin.?

@rlussier
Copy link

Would this be part of the install script, I'm still struggling to get it to pop up on my frontend. Also, can this also apply to a multi select option.

@huykon
Copy link

huykon commented Jun 7, 2019

how to do same it with Magento 2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment