Magento – how to get attribute label if it’s a price attribute

attributesmagento-1.7

I'am trying to get all attribute label of a special attribute which type is "price". Here is my code but it's not retreiving the right value.

 $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', '170');
$options = Mage::getResourceModel('eav/entity_attribute_option_collection');
$table_screen = array();    
foreach ( $values  = $options->setAttributeFilter($attribute->getId())->setStoreFilter(1)->toOptionArray() as $option){
$table_screen[] = (int)$option['label'];
}

Do you have any idea how to do that ?

Thanks,

Best Answer

Use Below Code

To get the Value of your custom attribute then

 $option = Mage::getModel('catalog/product')->load($id);
 print_r($option->getData('Your Attribute ID'));

To get the All values

 /**
 * @var $config  Mage_Eav_Model_Config
 * @var $options Mage_Eav_Model_Resource_Entity_Attribute_Option_Collection
 */
$storeId   = 3;
$config    = Mage::getModel('eav/config');
$attribute = $config->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'color');
$values    = $attribute->setStoreId($storeId)->getSource()->getAllOptions();
print_r($values);

//here is another method
$options = Mage::getResourceModel('eav/entity_attribute_option_collection');
$values  = $options->setAttributeFilter($attribute->getId())->setStoreFilter($storeId)->toOptionArray();
print_r($values);    

when you print this $value you got one array contain below one.

 Array
 (
     [0] => Array
         (
             [value] => 128
             [label] => test
         )
 )
Related Topic