88namespace Magento \Customer \Model ;
99
1010use Magento \Customer \Api \Data \GroupInterface ;
11+ use Magento \Customer \Api \Data \GroupInterfaceFactory ;
12+ use Magento \Customer \Api \GroupRepositoryInterface ;
13+ use Magento \Framework \Api \FilterBuilder ;
1114use Magento \Framework \Api \SearchCriteriaBuilder ;
15+ use Magento \Framework \Api \SortOrderBuilder ;
1216use Magento \Framework \App \Config \ScopeConfigInterface ;
13- use Magento \Framework \Api \FilterBuilder ;
17+ use Magento \Framework \App \ObjectManager ;
18+ use Magento \Framework \Data \Collection ;
1419use Magento \Framework \Exception \NoSuchEntityException ;
1520use Magento \Store \Model \StoreManagerInterface ;
16- use Magento \Customer \Api \GroupRepositoryInterface ;
17- use Magento \Customer \Api \Data \GroupInterfaceFactory ;
18- use Magento \Customer \Model \GroupFactory ;
1921
2022/**
2123 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -65,6 +67,11 @@ class GroupManagement implements \Magento\Customer\Api\GroupManagementInterface
6567 */
6668 protected $ filterBuilder ;
6769
70+ /**
71+ * @var SortOrderBuilder
72+ */
73+ private $ sortOrderBuilder ;
74+
6875 /**
6976 * @param StoreManagerInterface $storeManager
7077 * @param ScopeConfigInterface $scopeConfig
@@ -73,6 +80,7 @@ class GroupManagement implements \Magento\Customer\Api\GroupManagementInterface
7380 * @param GroupInterfaceFactory $groupDataFactory
7481 * @param SearchCriteriaBuilder $searchCriteriaBuilder
7582 * @param FilterBuilder $filterBuilder
83+ * @param SortOrderBuilder $sortOrderBuilder
7684 */
7785 public function __construct (
7886 StoreManagerInterface $ storeManager ,
@@ -81,7 +89,8 @@ public function __construct(
8189 GroupRepositoryInterface $ groupRepository ,
8290 GroupInterfaceFactory $ groupDataFactory ,
8391 SearchCriteriaBuilder $ searchCriteriaBuilder ,
84- FilterBuilder $ filterBuilder
92+ FilterBuilder $ filterBuilder ,
93+ SortOrderBuilder $ sortOrderBuilder = null
8594 ) {
8695 $ this ->storeManager = $ storeManager ;
8796 $ this ->scopeConfig = $ scopeConfig ;
@@ -90,6 +99,8 @@ public function __construct(
9099 $ this ->groupDataFactory = $ groupDataFactory ;
91100 $ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ;
92101 $ this ->filterBuilder = $ filterBuilder ;
102+ $ this ->sortOrderBuilder = $ sortOrderBuilder ?: ObjectManager::getInstance ()
103+ ->get (SortOrderBuilder::class);
93104 }
94105
95106 /**
@@ -155,9 +166,14 @@ public function getLoggedInGroups()
155166 ->setConditionType ('neq ' )
156167 ->setValue (self ::CUST_GROUP_ALL )
157168 ->create ();
169+ $ groupNameSortOrder = $ this ->sortOrderBuilder
170+ ->setField ('customer_group_code ' )
171+ ->setDirection (Collection::SORT_ORDER_ASC )
172+ ->create ();
158173 $ searchCriteria = $ this ->searchCriteriaBuilder
159174 ->addFilters ($ notLoggedInFilter )
160175 ->addFilters ($ groupAll )
176+ ->addSortOrder ($ groupNameSortOrder )
161177 ->create ();
162178 return $ this ->groupRepository ->getList ($ searchCriteria )->getItems ();
163179 }
0 commit comments