2

I've added a product attribute by adding the following to InstallData.php within my module.

 $eavSetup->addAttribute(
        \Magento\Catalog\Model\Product::ENTITY,
        'allergens',
        [
            'type' => 'int',
            'label' => 'Free from the following allergens',
            'input' => 'multiselect',
            'required' => false,
            'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
            'global' => Attribute::SCOPE_GLOBAL,
            'visible' => true,
            'user_defined' => false,
            'searchable' => false,
            'filterable' => true,
            'filterable_in_search' => true,
            '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,
            'label' => [
                'values' => [
                    'Gluten',
                    'Soy',
                    'Eggs',
                    'Shellfish',
                    'Dairy',
                    'Fish',
                    'Nuts',
                    'Yeast'
                ]
            ]
        ]
    );

I've checked this attribute in the CMS, and i can see it's marked as filterable with results, and use in layered navigation is set to true. The issue is that it's not appearing alongside the other filters in my custom layered navigation.

$block->getFilters() is retrieving the filter,

but when i echo the results echo $filter->getItemsCount() it's showing 0 results? Even though i have products with this attribute assigned.

The product deffinately has the attribute saved correctly, so i'm not sure what's happening here.

Any help would be appreciated.

Thanks

  • did you rebuild your indexes? – Marius Jun 8 '16 at 14:47
  • i ran php bin/magento indexer:reindex from the CL – Sophie Baxter Jun 8 '16 at 15:21
0

I inadvertently created the attributes as system attributes, i added 'system' => 0 where i added the attribute and this seems to have resolved the issue.

  • instead of 'system'=>0 you should have used the following user_defined' => true, to set system. Anyway I can't see this new attribute in the layered navigation even has the same values as other I created through the backend.. – Jordi Jan 25 '17 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.