Reputation: 735
I'm working on an existing e-commerce site, where one of the custom attributes for a product is Designer, which is a dropdown list of names that have been added to the attribute under:
Catalog > Attributes > Manage Attributes
I'm building a custom module that will allow admins to create posts about designers, with additional info (bio, image etc), and ideally what I want is to restrict the admin user to creating posts only for designers that exist within that product attribute, by letting them set the name of the designer via a dropdown list of names populated by the values available to that product attribute.
I'm relatively new to using Magento, so I have no idea how to go about accessing those attribute values from within a custom module, and hoping someone can help me?
Upvotes: 1
Views: 1102
Reputation: 1437
This code will let you load a product attribute option array
$arg_attribute = 'YOUR ATTRIBUTE CODE';
$attribute_model = Mage::getModel('eav/entity_attribute');
$attribute_options_model= Mage::getModel('eav/entity_attribute_source_table') ;
$attribute_code = $attribute_model->getIdByCode('catalog_product', $arg_attribute);
$attribute = $attribute_model->load($attribute_code);
$attribute_table = $attribute_options_model->setAttribute($attribute);
$options = $attribute_options_model->getAllOptions(false);
Upvotes: 1