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

Undefined index: adminSortIndex #562

Closed
srenon opened this issue Oct 16, 2017 · 6 comments
Closed

Undefined index: adminSortIndex #562

srenon opened this issue Oct 16, 2017 · 6 comments

Comments

@srenon
Copy link

srenon commented Oct 16, 2017

Exception #0 (Exception): Notice: Undefined index: adminSortIndex in /vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/Layer/Filter/Attribute.php on line 279

Preconditions

Magento Version : 2.1.9EE

ElasticSuite Version : 2.3.7

We are using a third-party extension to create products/attributes and it doesn't always add the 'adminSortIndex' for newly created attributes. To fix we normally have to resave the attributes option.

Possible Solution

        usort($items, function ($item1, $item2) {
           //Check if array key exist
            if(!array_key_exists('adminSortIndex', $item1) || !array_key_exists('adminSortIndex', $item2)){
                return 0;
            }

            return $item1['adminSortIndex'] <= $item2['adminSortIndex'] ? -1 : 1;
        });
@afoucret
Copy link
Contributor

A fix is available on branches 2.3.x, 2.4.x and master.

@srenon
Copy link
Author

srenon commented Oct 17, 2017

Thanks...

Are you going to do a new version release anytime soon?

@afoucret
Copy link
Contributor

2.3.9 has been released and contains the fix.

BR,

@srenon
Copy link
Author

srenon commented Oct 17, 2017

@afoucret ... after upgrading to 2.3.9... I'm missing products from categories, any idea?

@srenon
Copy link
Author

srenon commented Oct 17, 2017

@afoucret ... the issue is not caused by this release but by this code #567

@DanielSousa
Copy link

@afoucret
This issue still not fixed on 2.3.11
If you're using several languages and the translation value added in admin for some typo, or a bad copy paste has some space before or after the string the system will return false for isset($items[$optionLabel])

            if ($optionLabel !== null && isset($items[$optionLabel])) {
                $items[$optionLabel]['adminSortIndex'] = $optionPosition;
                $items[$optionLabel]['value'] = $option['value'];
            }

Possible Solution:

                        $optionLabel = trim($optionLabel);
                        if (isset($items[$optionLabel])) {
                            $items[$optionLabel]['adminSortIndex'] = $optionPosition;
                            $items[$optionLabel]['value']          = $option['value'];
                        }

Another improvement can be made:
the use of spaceship operator

            usort($items, function ($item1, $item2) {
                return $item1['adminSortIndex'] <=> $item2['adminSortIndex'];
            });

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

3 participants