0

I am using the following code to get the options of the select attribute.

Now I want to get the options that should be ordered alphabetically.

file.php

$eavConfig = $object_Manager->get('\Magento\Eav\Model\Config');
    $attribute = $eavConfig->getAttribute('catalog_product', 'color');
    $options = $attribute->getSource()->getAllOptions();

    $optionsExists = array();

    foreach($options as $option) {
        $optionsValues[] = $option['value'];
        $optionsExists[] = $option['label'];
    }

    return $optionsExists;

I am using the above code. Can anyone guide magentoe2

1

You may just use some php function to sort arrays like ksort or usort

Here you have an array sorting functions list https://www.php.net/manual/en/array.sorting.php

Let me know if it helps.

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.