Categories are not sroted alphabetically when attempting to add /select categories while editing products.
This becomes very troublesome especially when you are dealing with sites with a large amount of categories and sub categories.
Steps to resproduce this :
While trying to add categories you will notice that the categoris displayed are not sorted alphabetically.
This is very frustrating especially when you are dealing with a large number of categories / sub categories.
Please advice.
Solved! Go to Solution.
Hi @donweb,
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');
Please don't modify core file.
Hope this helps you!
Problem solved! Click Kudos & Accept as Solution!
Hi @donweb,
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');
Please don't modify core file.
Hope this helps you!
Problem solved! Click Kudos & Accept as Solution!
Thanks Nishu... Worked like a charm.. But I am relatively new to magento 2. Do you have any info on how to apply this solution the right way without editing the core files. Something very detailed?