cancel
Showing results for 
Search instead for 
Did you mean: 

Categories not sorted alphabetically - When selecting categories while adding and editing products.

SOLVED

Categories not sorted alphabetically - When selecting categories while adding and editing products.

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 :

  1. Edit  exisiting product or add new product.
  2. 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.

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Categories not sorted alphabetically - When selecting categories while adding and editing produc

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!

View solution in original post

2 REPLIES 2

Re: Categories not sorted alphabetically - When selecting categories while adding and editing produc

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!

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?