I have a custom product attribute that uses a multiselect input to select one or more product stockists.
The data is being stored correctly, and selecting 1 option adds the information to the "More information' tab on the product frontend page.
Selecting 2 or more options, the information is no longer visible on the frontend.
Attribute config below
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'stockist',
[
'type' => 'varchar',
'label' => 'Stockist',
'input' => 'multiselect',
'source' => 'My\Module\Model\Attribute\Source\Stockist',
'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'searchable' => true,
'filterable' => true,
'comparable' => false,
'visible_on_front' => true,
'used_in_product_listing' => true
]
);
My\Module\Model\Attribute\Source\Stockist:
namespace My\Module\Model\Attribute\Source;
use My\Module\Model\ResourceModel\Stockist\CollectionFactory;
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
class Stockist extends AbstractSource
{
private $collectionFactory;
public function __construct(CollectionFactory $collectionFactory)
{
$this->collectionFactory = $collectionFactory;
}
public function getAllOptions()
{
$stockistCollection = $this->collectionFactory->create();
$stockistCollection->addFieldToSelect('*')->load();
$result = [];
foreach ($stockistCollection as $stockist) {
$result[] = [
'value' => $stockist->getId(),
'label' => $stockist->getName()
];
}
return $result;
}
}
$product->getAttributeText()
? – HelgeB Feb 28 '19 at 15:19