Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top