1

Working on custom extension, I have implemented multi select option using custom source. It don't show the option in multi select box. Anybody knows the reason? Check screenshot,

$eavSetup->addAttribute(
            \Magento\Catalog\Model\Product::ENTITY,
            'extension_source_user',
            [
                'type' => 'varchar',
                'label' => 'Used Title',
    'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
                'input' => 'multiselect',
    'source' => 'company\extension\Model\Source\Custom\User',
                'required' => false,
                'sort_order' => 7,
                'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
    'apply_to' => 'simple,configurable,virtual',
                'group' => 'company',
    'searchable'        => false,
    'filterable'        => false
            ]
        );

enter image description here

1

It the issue of your source model "'source' => 'company\extension\Model\Source\Custom\User'"

You need to return option array in the form of key, value pair like :

public function getOptionArray()
{
    $_options = array();
    foreach ($this->getAllOptions() as $option) {
        $_options[$option["value"]] = $option["label"];
    }
    return $_options;
}
| improve this answer | |
  • This is not working for me :( Can you share any link with full example? What needs to be coded in category_form.xml? – Gaurav Jain Aug 29 '16 at 10:13
0

Please try the following code.

In this code $option['value'] is the value of selected option and $option['label'] is the label to be shown.

public function getOptionArray()
 {
    $_options = array();
    $index = 0;
    foreach ($this->getAllOptions() as $option) {
        $_options[$index]['value'] = $option['value'];
        $_options[$index]['label'] = $option['label'];
        $index++;
    }
    return $_options;
}
| improve this answer | |

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.