Magento 2 Product Attribute – Custom Attribute Source Model for Multiselect

multiselect-attributeproduct-attributesource-model

I followed this tutorial here: http://inchoo.net/ecommerce/magento/how-to-create-custom-attribute-source-type/

In this tutorial, there are two key settings which I want to change:

'type'              => 'int',    //backend_type
'input'             => 'select', //frontend_input

I tried using this:

'type'              => 'varchar',    //backend_type
'input'             => 'multiselect', //frontend_input

This works great from a UI standpoint, but I can't get Magento save any selection when I have the attribute setup this way.

How can I make a custom attribute source model that fully supports multiselect?

Best Answer

Add this key:

'backend'=>'eav/entity_attribute_backend_array' //backend_model 

to your attribute definition array