2

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.

3

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.

2

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 Nov 1 '16 at 22:04
  • nevermind seems both works – Nickool Nov 1 '16 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 arrtibutesetnames – Nickool Nov 1 '16 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 Nov 1 '16 at 22:17

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.