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
]
);
2 Answers 2
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;
}
-
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– Gaurav Jain2016年08月29日 10:13:40 +00:00Commented Aug 29, 2016 at 10:13
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;
}