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

Qaisar Satti
32.6k18 gold badges88 silver badges138 bronze badges
asked Aug 29, 2016 at 6:23

2 Answers 2

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;
}
answered Aug 29, 2016 at 6:38
1
  • This is not working for me :( Can you share any link with full example? What needs to be coded in category_form.xml? Commented Aug 29, 2016 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;
}

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.