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/**
23+ * The class contains methods for getting information about a customer group
24+ *
2125 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2226 */
2327class GroupManagement implements \Magento \Customer \Api \GroupManagementInterface
@@ -65,6 +69,11 @@ class GroupManagement implements \Magento\Customer\Api\GroupManagementInterface
6569 */
6670 protected $ filterBuilder ;
6771
72+ /**
73+ * @var SortOrderBuilder
74+ */
75+ private $ sortOrderBuilder ;
76+
6877 /**
6978 * @param StoreManagerInterface $storeManager
7079 * @param ScopeConfigInterface $scopeConfig
@@ -73,6 +82,7 @@ class GroupManagement implements \Magento\Customer\Api\GroupManagementInterface
7382 * @param GroupInterfaceFactory $groupDataFactory
7483 * @param SearchCriteriaBuilder $searchCriteriaBuilder
7584 * @param FilterBuilder $filterBuilder
85+ * @param SortOrderBuilder $sortOrderBuilder
7686 */
7787 public function __construct (
7888 StoreManagerInterface $ storeManager ,
@@ -81,7 +91,8 @@ public function __construct(
8191 GroupRepositoryInterface $ groupRepository ,
8292 GroupInterfaceFactory $ groupDataFactory ,
8393 SearchCriteriaBuilder $ searchCriteriaBuilder ,
84- FilterBuilder $ filterBuilder
94+ FilterBuilder $ filterBuilder ,
95+ SortOrderBuilder $ sortOrderBuilder = null
8596 ) {
8697 $ this ->storeManager = $ storeManager ;
8798 $ this ->scopeConfig = $ scopeConfig ;
@@ -90,10 +101,12 @@ public function __construct(
90101 $ this ->groupDataFactory = $ groupDataFactory ;
91102 $ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ;
92103 $ this ->filterBuilder = $ filterBuilder ;
104+ $ this ->sortOrderBuilder = $ sortOrderBuilder ?: ObjectManager::getInstance ()
105+ ->get (SortOrderBuilder::class);
93106 }
94107
95108 /**
96- * { @inheritdoc}
109+ * @inheritdoc
97110 */
98111 public function isReadonly ($ groupId )
99112 {
@@ -107,7 +120,7 @@ public function isReadonly($groupId)
107120 }
108121
109122 /**
110- * { @inheritdoc}
123+ * @inheritdoc
111124 */
112125 public function getDefaultGroup ($ storeId = null )
113126 {
@@ -133,15 +146,15 @@ public function getDefaultGroup($storeId = null)
133146 }
134147
135148 /**
136- * { @inheritdoc}
149+ * @inheritdoc
137150 */
138151 public function getNotLoggedInGroup ()
139152 {
140153 return $ this ->groupRepository ->getById (self ::NOT_LOGGED_IN_ID );
141154 }
142155
143156 /**
144- * { @inheritdoc}
157+ * @inheritdoc
145158 */
146159 public function getLoggedInGroups ()
147160 {
@@ -155,15 +168,20 @@ public function getLoggedInGroups()
155168 ->setConditionType ('neq ' )
156169 ->setValue (self ::CUST_GROUP_ALL )
157170 ->create ();
171+ $ groupNameSortOrder = $ this ->sortOrderBuilder
172+ ->setField ('customer_group_code ' )
173+ ->setDirection (Collection::SORT_ORDER_ASC )
174+ ->create ();
158175 $ searchCriteria = $ this ->searchCriteriaBuilder
159176 ->addFilters ($ notLoggedInFilter )
160177 ->addFilters ($ groupAll )
178+ ->addSortOrder ($ groupNameSortOrder )
161179 ->create ();
162180 return $ this ->groupRepository ->getList ($ searchCriteria )->getItems ();
163181 }
164182
165183 /**
166- * { @inheritdoc}
184+ * @inheritdoc
167185 */
168186 public function getAllCustomersGroup ()
169187 {
0 commit comments