Having a similar issue to this https://github.com/magento/magento2/issues/4822
develop branch.$this->addMultiSelectFieldWithSource($eavSetup, 'special_requirements', 'Special requirements', false, 4,'Amrita\Catalog\Model\Product\Attribute\Source\SpecialRequirements');
private function addMultiSelectFieldWithSource($eavSetup, $fieldName, $fieldTitle, $required, $position, $source) {
$eavSetup->addAttribute(
Product::ENTITY,
$fieldName,
[
'type' => 'varchar',
'label' => $fieldTitle,
'input' => 'multiselect',
'required' => $required,
'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
'source' => $source,
'global' => Attribute::SCOPE_GLOBAL,
'visible' => true,
'user_defined' => true,
'system' => 0,
'searchable' => true,
'visible_in_advanced_search' => true,
'filterable' => true,
'filterable_in_search' => true,
'position' => $position,
'comparable' => false,
'visible_on_front' => false,
'unique' => false,
'group' => 'General',
'is_used_in_grid' => true,
'is_visible_in_grid' => false,
'is_filterable_in_grid' => true,
]
);
Select and save an option against the attribute
Multiselect field retrieves selected value.
selected value is saved the first time in the db table catalog_product_entity_varchar, and the attribute is added to the eav_attribute table

The attributes installed with the sample data work correctly, but i cannot understand how the magento installation differs to my attempted installation.
Is there any update on this, i'm aware this was an issue in the previous version but this hasn't been resolved for me through upgrading to 2.1?
It looks like this can be fixed by having string values instead of integers in the source. So ['value' => 1, ...] becomes ['value' => '1'].
I would say that this is still a bug, though.
This bug is not constrained to products only. Customer cannot save a multiselect. I can only assume it affects other entities.
Hello You can solve this issue by adding string cast to the option value of your source model
like this
public function getAllOptions()
{
$collection = $this->getCollection();
$_options = [];
foreach ($collection as $item) {
$_options[] = [
'label' => $item->getName(),
'value' => (string)$item->getId()
];
}
return $_options;
}
it is worked for me
Solution suggested by @zexperto solved my problem. And it's kinda explain the issue.
If you explode a string separated by comma it will results in an array of strings not integers.
[Update: 15/03/2018] Solution won't work on static data source with string values.
Example:
public function getAllOptions()
{
if (!$this->_options) {
$this->_options = [
['value' => 'one', 'label' => __('Label 1')],
['value' => 'two', 'label' => __('Label 2')],
['value' => 'three', 'label' => __('Label 3')],
['value' => 'other', 'label' => __('Other')],
];
}
return $this->_options;
}
Solution suggested by @zexperto dont work for me, magento version 2.2
@sma09sjb, thank you for your report.
We've created internal ticket(s) MAGETWO-84479 to track progress on the issue.
Just like @kovalevandrew i'm still seeing this issue on 2.2.2
Either defining the backend type as varchar, or keeping it as int and explicitly casting as ints work for me. In truth the, the ArrayBackend model should really double check what you're saving as and cast it as that.
Thanks to everyone in this thread for pointing me in the direction of a fix.
@magento-engcom-team Any update or bug fix on this ticket?
@sma09sjb @tuyennn
Fix for this issue is going to be available with the upcoming 2.2.6 release.
Meanwhile, you may use the following commits as the reference: https://github.com/search?q=MAGETWO-90576&type=Commits
Thank you
Hello You can solve this issue by adding string cast to the option value of your source model
like this
public function getAllOptions()
{
$collection = $this->getCollection();
$_options = [];
foreach ($collection as $item) {
$_options[] = [
'label' => $item->getName(),
'value' => (string)$item->getId()
];
}
return $_options;
}
it is worked for me
How do i do this? (sorry, programming n00b) :)
Most helpful comment
Hello You can solve this issue by adding string cast to the option value of your source model
like this
public function getAllOptions()
{
$collection = $this->getCollection();
$_options = [];
foreach ($collection as $item) {
$_options[] = [
'label' => $item->getName(),
'value' => (string)$item->getId()
];
}
return $_options;
}
it is worked for me