0

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,

1

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
         )
 )
10
  • My situation est more in the "another method" because I want a table with all the value of this attribute. However when it's a price type attribute it's not working. The right value is located in catalog_product_entity_decimal instead of the standard eav_attribute_option_value Feb 6 '14 at 9:26
  • yes this code will return all value of your attribute with label just copy and paste the code and change the store id and attribute code
    – Keyul Shah
    Feb 6 '14 at 9:27
  • I have tested it then and then I suggest you .
    – Keyul Shah
    Feb 6 '14 at 9:28
  • but you try with the color attribute which is not a price attribute. Feb 6 '14 at 9:41
  • buddy replace with your attribute code simple man..
    – Keyul Shah
    Feb 6 '14 at 9:46

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.