Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom filterable attribute #363

Closed
madonzy opened this issue Mar 22, 2017 · 3 comments
Closed

Add custom filterable attribute #363

madonzy opened this issue Mar 22, 2017 · 3 comments

Comments

@madonzy
Copy link

madonzy commented Mar 22, 2017

Is it possible to add custom filterable attribute?

Preconditions

OS: Linux debian-8 3.16.0-4-amd64 #1 SMP Debian 3.16.39-1+deb8u2 (2017-03-07) x86_64 GNU/Linux
Magento Version: 2.1.4 CE
ElasticSuite Version: 2.3.3
Environment: developer

Steps to reproduce

  1. In own module setup I use this configuration while adding the attribute:
[
                'type'                    => 'text',
                'backend'                 => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
                'frontend'                => '',
                'label'                   => 'Brand',
                'input'                   => 'multiselect',
                'class'                   => '',
                'source'                  => 'XXX\YYY\Model\Source\Array',
                'global'                  => ScopedAttributeInterface::SCOPE_GLOBAL,
                'visible'                 => true,
                'required'                => false,
                'user_defined'            => true,
                'default'                 => '',
                'searchable'              => true,
                'filterable'              => true,
                'comparable'              => false,
                'visible_on_front'        => true,
                'used_in_product_listing' => true,
                'unique'                  => false,
                'apply_to'                => '',
            ]
  1. Add this attribute to default set
  2. I source model I override this method:
/**
     * {@inheritdoc}
     */
    public function getAllOptions()
    {
        if ($this->_options === null) {
            $this->_options = [
                [
                    'value' => 'nike',
                    'label' => 'Nike'
                ],
                [
                    'value' => 'adidas',
                    'label' => 'Adidas'
                ],
                [
                    'value' => 'puma',
                    'label' => 'Puma'
                ]
            ];

            // TODO: implement brand fetching
        }

        return $this->_options;
    }
  1. Set one product to value Adidas, go to the category page...
  2. Check the front

Expected result

  1. My attribute will apply as filter in category page (the same as activity, style, features, etc. attributes)

Actual result

  1. There's no filter added :D
@romainruaud
Copy link
Collaborator

Hello @madonzy and thank you for submitting this issue.

This should work as intended, are you sure the index is properly rebuilt ? You should also ensure that enough products among all those displayed are having values for this attribute, otherwise it could get skipped by the facet coverage rate (see https://github.com/Smile-SA/elasticsuite/wiki/Attribute-configuration#faceting-configuration)

Let me know,

Regards,

@madonzy
Copy link
Author

madonzy commented Mar 22, 2017

@romainruaud Index rebuilt is "green" :)
Facet coverage rate is set to 0 (is it ok?), I have only one product with this attribute and I don't wand to set others yet.

@romainruaud
Copy link
Collaborator

Ok I found it.

You did not properly create your attribute.

For a multiselect one, you have to use "varchar" as the type.

If you set it to "text" as you did previously, Magento will autoritary change it to "varchar" when you save it from the backoffice, resulting as loading empty data for product when indexing to the search engine.

Please drop your attribute, recreate it properly (as a varchar) and set your product values again, then process a full reindex.

Feel free to reopen the issue if you are still encountering problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants