8
8
namespace Magento \Customer \Model ;
9
9
10
10
use Magento \Customer \Api \Data \GroupInterface ;
11
+ use Magento \Customer \Api \Data \GroupInterfaceFactory ;
12
+ use Magento \Customer \Api \GroupRepositoryInterface ;
13
+ use Magento \Framework \Api \FilterBuilder ;
11
14
use Magento \Framework \Api \SearchCriteriaBuilder ;
15
+ use Magento \Framework \Api \SortOrderBuilder ;
12
16
use Magento \Framework \App \Config \ScopeConfigInterface ;
13
- use Magento \Framework \Api \FilterBuilder ;
17
+ use Magento \Framework \App \ObjectManager ;
18
+ use Magento \Framework \Data \Collection ;
14
19
use Magento \Framework \Exception \NoSuchEntityException ;
15
20
use Magento \Store \Model \StoreManagerInterface ;
16
- use Magento \Customer \Api \GroupRepositoryInterface ;
17
- use Magento \Customer \Api \Data \GroupInterfaceFactory ;
18
- use Magento \Customer \Model \GroupFactory ;
19
21
20
22
/**
21
23
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -65,6 +67,11 @@ class GroupManagement implements \Magento\Customer\Api\GroupManagementInterface
65
67
*/
66
68
protected $ filterBuilder ;
67
69
70
+ /**
71
+ * @var SortOrderBuilder
72
+ */
73
+ private $ sortOrderBuilder ;
74
+
68
75
/**
69
76
* @param StoreManagerInterface $storeManager
70
77
* @param ScopeConfigInterface $scopeConfig
@@ -73,6 +80,7 @@ class GroupManagement implements \Magento\Customer\Api\GroupManagementInterface
73
80
* @param GroupInterfaceFactory $groupDataFactory
74
81
* @param SearchCriteriaBuilder $searchCriteriaBuilder
75
82
* @param FilterBuilder $filterBuilder
83
+ * @param SortOrderBuilder $sortOrderBuilder
76
84
*/
77
85
public function __construct (
78
86
StoreManagerInterface $ storeManager ,
@@ -81,7 +89,8 @@ public function __construct(
81
89
GroupRepositoryInterface $ groupRepository ,
82
90
GroupInterfaceFactory $ groupDataFactory ,
83
91
SearchCriteriaBuilder $ searchCriteriaBuilder ,
84
- FilterBuilder $ filterBuilder
92
+ FilterBuilder $ filterBuilder ,
93
+ SortOrderBuilder $ sortOrderBuilder = null
85
94
) {
86
95
$ this ->storeManager = $ storeManager ;
87
96
$ this ->scopeConfig = $ scopeConfig ;
@@ -90,6 +99,8 @@ public function __construct(
90
99
$ this ->groupDataFactory = $ groupDataFactory ;
91
100
$ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ;
92
101
$ this ->filterBuilder = $ filterBuilder ;
102
+ $ this ->sortOrderBuilder = $ sortOrderBuilder ?: ObjectManager::getInstance ()
103
+ ->get (SortOrderBuilder::class);
93
104
}
94
105
95
106
/**
@@ -155,9 +166,14 @@ public function getLoggedInGroups()
155
166
->setConditionType ('neq ' )
156
167
->setValue (self ::CUST_GROUP_ALL )
157
168
->create ();
169
+ $ groupNameSortOrder = $ this ->sortOrderBuilder
170
+ ->setField ('customer_group_code ' )
171
+ ->setDirection (Collection::SORT_ORDER_ASC )
172
+ ->create ();
158
173
$ searchCriteria = $ this ->searchCriteriaBuilder
159
174
->addFilters ($ notLoggedInFilter )
160
175
->addFilters ($ groupAll )
176
+ ->addSortOrder ($ groupNameSortOrder )
161
177
->create ();
162
178
return $ this ->groupRepository ->getList ($ searchCriteria )->getItems ();
163
179
}
0 commit comments