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
/**
23
+ * The class contains methods for getting information about a customer group
24
+ *
21
25
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
22
26
*/
23
27
class GroupManagement implements \Magento \Customer \Api \GroupManagementInterface
@@ -65,6 +69,11 @@ class GroupManagement implements \Magento\Customer\Api\GroupManagementInterface
65
69
*/
66
70
protected $ filterBuilder ;
67
71
72
+ /**
73
+ * @var SortOrderBuilder
74
+ */
75
+ private $ sortOrderBuilder ;
76
+
68
77
/**
69
78
* @param StoreManagerInterface $storeManager
70
79
* @param ScopeConfigInterface $scopeConfig
@@ -73,6 +82,7 @@ class GroupManagement implements \Magento\Customer\Api\GroupManagementInterface
73
82
* @param GroupInterfaceFactory $groupDataFactory
74
83
* @param SearchCriteriaBuilder $searchCriteriaBuilder
75
84
* @param FilterBuilder $filterBuilder
85
+ * @param SortOrderBuilder $sortOrderBuilder
76
86
*/
77
87
public function __construct (
78
88
StoreManagerInterface $ storeManager ,
@@ -81,7 +91,8 @@ public function __construct(
81
91
GroupRepositoryInterface $ groupRepository ,
82
92
GroupInterfaceFactory $ groupDataFactory ,
83
93
SearchCriteriaBuilder $ searchCriteriaBuilder ,
84
- FilterBuilder $ filterBuilder
94
+ FilterBuilder $ filterBuilder ,
95
+ SortOrderBuilder $ sortOrderBuilder = null
85
96
) {
86
97
$ this ->storeManager = $ storeManager ;
87
98
$ this ->scopeConfig = $ scopeConfig ;
@@ -90,10 +101,12 @@ public function __construct(
90
101
$ this ->groupDataFactory = $ groupDataFactory ;
91
102
$ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ;
92
103
$ this ->filterBuilder = $ filterBuilder ;
104
+ $ this ->sortOrderBuilder = $ sortOrderBuilder ?: ObjectManager::getInstance ()
105
+ ->get (SortOrderBuilder::class);
93
106
}
94
107
95
108
/**
96
- * { @inheritdoc}
109
+ * @inheritdoc
97
110
*/
98
111
public function isReadonly ($ groupId )
99
112
{
@@ -107,7 +120,7 @@ public function isReadonly($groupId)
107
120
}
108
121
109
122
/**
110
- * { @inheritdoc}
123
+ * @inheritdoc
111
124
*/
112
125
public function getDefaultGroup ($ storeId = null )
113
126
{
@@ -133,15 +146,15 @@ public function getDefaultGroup($storeId = null)
133
146
}
134
147
135
148
/**
136
- * { @inheritdoc}
149
+ * @inheritdoc
137
150
*/
138
151
public function getNotLoggedInGroup ()
139
152
{
140
153
return $ this ->groupRepository ->getById (self ::NOT_LOGGED_IN_ID );
141
154
}
142
155
143
156
/**
144
- * { @inheritdoc}
157
+ * @inheritdoc
145
158
*/
146
159
public function getLoggedInGroups ()
147
160
{
@@ -155,15 +168,20 @@ public function getLoggedInGroups()
155
168
->setConditionType ('neq ' )
156
169
->setValue (self ::CUST_GROUP_ALL )
157
170
->create ();
171
+ $ groupNameSortOrder = $ this ->sortOrderBuilder
172
+ ->setField ('customer_group_code ' )
173
+ ->setDirection (Collection::SORT_ORDER_ASC )
174
+ ->create ();
158
175
$ searchCriteria = $ this ->searchCriteriaBuilder
159
176
->addFilters ($ notLoggedInFilter )
160
177
->addFilters ($ groupAll )
178
+ ->addSortOrder ($ groupNameSortOrder )
161
179
->create ();
162
180
return $ this ->groupRepository ->getList ($ searchCriteria )->getItems ();
163
181
}
164
182
165
183
/**
166
- * { @inheritdoc}
184
+ * @inheritdoc
167
185
*/
168
186
public function getAllCustomersGroup ()
169
187
{
0 commit comments