Creating a multiselect in Magento when an attribute has many, many values gets truncated when it’s indexed into the catalog_product_flat table. This is because the catalog_product_flat table’s column is made specifically as a type varchar as length 255 for multiselects.
A fix is to create a plugin for the \Magento\Eav\Model\Entity\Attribute\Source\Table class;
di.xml:
<type name="Magento\Eav\Model\Entity\Attribute\Source\Table"> <plugin name="module_eav_entity_attribute_source_table" type="Namespace\Module\Plugin\Eav\Model\Entity\Attribute\Source\Table" sortOrder="10"/> </type>
And the PHP class…
namespace Namespace\Module\Plugin\Eav\Model\Entity\Attribute\Source; class Table { /** * For some reason, Magento indexes text types which are multiselects and type text as varchar 255. * This keeps the creation of text index columns so they stay as text type * * @param \Magento\Eav\Model\Entity\Attribute\Source\Table $subject * @param array $result * @return array */ public function afterGetFlatColumns( $subject, $result ) { $attributeCode = $subject->getAttribute()->getAttributeCode(); $isMulti = $subject->getAttribute()->getFrontend()->getInputType() == 'multiselect'; if($isMulti && $subject->getAttribute()->getBackendType() == \Magento\Framework\DB\Ddl\Table::TYPE_TEXT) { $result[$attributeCode]['length'] = null; } return $result; } }
This doesn’t appear to be intended, maybe Magento don’t recommend creating multiselects as type text anymore, but that’s no good for all use cases. Ho-hum.