as far as I understand when you have a <source_model> in your system.xml, it searches through the specified module for the function of getOptionArray(), right now I need to show all the attribute set names in a multi-select in the system configuration and was wondering why getoptionarray does not exist for the eav/entity_attribute_set? does it exist somewhere else which I am not aware of?
<show_attributesetname translate="label">
<label>show_attributesetname</label>
<frontend_type>multiselect</frontend_type>
<source_model>eav/entity_attribute_set?????</source_model>
<sort_order>21</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</show_attributesetname>
I was wondering if it exists and I just could not find it. if it doesn't exist then I should go ahead and add a tooptionarray to my module.
wanted to know if it really does not exist?? since doesn't seem right to me.
2 Answers 2
Yes we do have it, after Kul answered no and came up with toOptionArray, I searched again this time with toOptionArray and found out, we do have the source model for it in the resurces.
here is the answer:
<source_model>Mage_Eav_Model_Resource_Entity_Attribute_Set_Collection</source_model>
I'm not sure if my solution is cool enough since I am using resource in source! would love to hear back if anybody thinks what I did is wrong.
No. As far i know there is not any source model to get attribute set. You can create your own source model and add below code to fetch attribute set.
public function toOptionArray()
{
if (!count($this->_options)) {
$entityTypeId = Mage::getResourceModel('catalog/product')->getTypeId();
$attributeSetCollection = Mage::getResourceModel('eav/entity_attribute_set_collection')
->setEntityTypeFilter($entityTypeId);
foreach ($attributeSetCollection as $_attributeSet) {
$this->_options[] = array(
'value' => $_attributeSet->getId(),
'label' => $_attributeSet->getAttributeSetName()
);
}
}
return $this->_options;
}
Hope this help!
-
shouldn't your function be getOptionArray?Nickool– Nickool2016年11月01日 22:04:44 +00:00Commented Nov 1, 2016 at 22:04
-
nevermind seems both worksNickool– Nickool2016年11月01日 22:06:03 +00:00Commented Nov 1, 2016 at 22:06
-
you helped me to find my answer, I will upvote and then post the answer, the answer is yes we can do it. I searched for toOptionArray and found it for arrtibutesetnamesNickool– Nickool2016年11月01日 22:10:54 +00:00Commented Nov 1, 2016 at 22:10
-
@Nickool Perfect I wasn't 100% sure That's why i Mention as far as i know. Glad to know you found proper solution.Kul– Kul2016年11月01日 22:17:57 +00:00Commented Nov 1, 2016 at 22:17