0

I want to sort Categories alphabetically of the product form, how can I?

For more clarification please look onto the below picture.

enter image description here

As I checked, by default Magento 2 sort according to the category id(ASC order).

I'm not getting the files so that I can check and modify sorting.

1

Check vendor/magento/module-catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php

Following method is responsible for creating category tree.


protected function getCategoriesTree($filter = null)
{

You need to modify collection:


$collection->addAttributeToFilter('entity_id', ['in' => array_keys($shownCategoriesIds)])
            ->addAttributeToSelect(['name', 'is_active', 'parent_id'])
            ->setStoreId($storeId)->setOrder('name');

NB: don't modify core file

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.