- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 :
- Edit exisiting product or add new product.
- Select categories to insert for the product.
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Categories not sorted alphabetically - When selecting categories while adding and editing produc
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?