Description
Steps to reproduce
-
install attributes as follows:
$this->addSelectFieldWithSource($eavSetup, 'delivery_form', 'Delivery form', false, 2, 'Amrita\Catalog\Model\Product\Attribute\Source\DeliveryForm'); $this->addSelectFieldWithSource($eavSetup, 'manufacturer', 'Manufacturer', true, 5, 'Amrita\Catalog\Model\Product\Attribute\Source\Manufacturer');
private function addSelectFieldWithSource($eavSetup, $fieldName, $fieldTitle, $required, $position, $source) {
$eavSetup->addAttribute(
Product::ENTITY,
$fieldName,
[
'type' => 'int',
'label' => $fieldTitle,
'input' => 'select',
'required' => $required,
'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,
]
);
}
public function getAllOptions()
{
return [
['value' => '', 'label' => 'Please Select'],
['value' => '1', 'label' => 'Capsule'],
['value' => '2', 'label' => 'Chewable'],
['value' => '3', 'label' => 'Powder'],
['value' => '4', 'label' => 'Cream'],
['value' => '5', 'label' => 'Tablet'],
['value' => '6', 'label' => 'Lozenge'],
['value' => '7', 'label' => 'Drops'],
['value' => '8', 'label' => 'Softgel']
];
}
public function getAllOptions()
{
$manufacturers = $this->manufacturerCollectionFactory->create()
->addFilter('is_enabled', 1);
$this->_options[] = [
'label' => __('Please Select'),
'value' => '',
];
foreach ($manufacturers as $manufacturer) {
$this->_options[] = [
'label' => __($manufacturer['title']),
'value' => $manufacturer['manufacturer_id'],
];
}
return $this->_options;
}
Expected result
- On the frontend the attribute will be pulled through to the advanced search and layered navigation.
Actual result
- the attribute is only pulled through to the layered navigation, but only attributes with frontend_input type select are pulled through, any additional attributes with frontend_type multiselect are missing from the nav.
- the advanced search does not pull the attribute through, only attribute of frontend_input type multiselect are pulled through to the advanced search.
Looking at the code for the advanced search, the issue seems to be here, where the collection of searchable attributes is retrieved,
https://github.com/magento/magento2/blob/develop/app/code/Magento/CatalogSearch/Model/Advanced.php#L239
an options filter is applied here
https://github.com/magento/magento2/blob/develop/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Collection.php#L315
but the attributes i've added dynamically have no options in the table eav_attribute_option? that includes the mutliselect attributes that are being pulled through to the advanced search.
I'm pretty sure we have attributes on both types pulling through to both the advanced search and the layered navigation before we did the upgrade to 2.1, so any help would be greatly appreciated.
Thanks