cancel
Showing results for 
Search instead for 
Did you mean: 

Multiselect custom attribute module is not showing on layered navigation but shows on product edit

Multiselect custom attribute module is not showing on layered navigation but shows on product edit

I'm getting a little frustrated with this, below is code i have to create a custom multi-select attribute for a product, it uses a custom source to pull the data for it from a database table, when selecting the attributes on the product edit screen it saves the id values (primary keys of the table the data comes from).

 

I thought that the source would also be used on the front end to create check boxes, but nothing i do makes it show up (and i have added a multi select in the admin directly and that attribute shows up just fine):

 

$eavSetup->addAttribute(
Product::ENTITY,
'svgs',
[
'type' => 'varchar',
'label' => 'Select SVG/Filters',
'input' => 'multiselect',
'source' => 'Vendor\Module\Model\Config\Attributes\SvgOptions',
'backend'=> 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
'required' => false,
'sort_order' => 100,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'group' => 'Product Overview SVG/Filters',
'visible_on_front' => true,
'used_in_product_listing' => true,
'filterable'=>true,
'searchable'=>true,
'comparable'=>false,
'user_defined'=>true,
'apply_to' => 'simple,configurable,virtual,bundle,downloadable',
'is_used_in_grid' => true,
'is_visible_in_grid' => false,
'is_filterable_in_grid' => true
]
);

 My data source is this:

 

public function getAllOptions() : array
{

/** @var Collection $svgCollection */
$svgCollection = $this->svgCollectionFactory->create();

/** @var Collection $svgCategoryCollection */
$svgCategoryCollection = $this->svgCategoryCollectionFactory->create();

// get all categories
$categories = $svgCategoryCollection->setOrder('name','ASC');

// for each category as an option group, assign SVGs
$options = [];

/** @var Category $category */
foreach($categories as $category) {

// reset where in collection so each loop works
$svgCollection->clear()->getSelect()->reset('where');

// get svgs in this category
$svgs = $svgCollection->addFieldToFilter('category_id',$category->getId())
->setOrder('display_name','ASC');

if($svgs->count() > 0){

// create svgs array
$svgOptions = [];
/** @var SVG $svg */
foreach ($svgs as $svg) {
$svgOptions[] = [
'label'=>$svg->getData('display_name'),
'value'=>$svg->getId()
];
}


// add category with svgs to options
$options[] = [
'label'=>$category->getData('name'),
'value'=>$svgOptions
];
}
}


return $options;
}

 

All the options show in the admin and save no problem, it's just the layered nav they won't show up on