Magento – Get all the velues of EAV attribute from attribute code

Many time we do required to get the all values of attribute or lets sey all option values of EAV attribue, while code a custom module or functionality. Bellow code would help you get all option values of EAV attribue,

// get the list of all gender type
public function getGenderList()
{
      $genders = array();
      $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'gender'); // "gender" is attribute_code
      $allOptions = $attribute->getSource()->getAllOptions(true, true);
      foreach ($allOptions as $instance) {
           $genders[$instance['value']] = $instance['label'];
      }
      return $genders;
}

above function will returns array of gender type, gender is attribute of catalog_product.

Advertisements