4
4
* See COPYING.txt for license details.
5
5
*/
6
6
7
- /**
8
- * Attribute add/edit form options tab
9
- *
10
- * @author Magento Core Team <core@magentocommerce.com>
11
- */
12
7
namespace Magento \Eav \Block \Adminhtml \Attribute \Edit \Options ;
13
8
14
9
use Magento \Store \Model \ResourceModel \Store \Collection ;
10
+ use Magento \Eav \Model \Entity \Attribute \AbstractAttribute ;
15
11
16
12
/**
13
+ * Attribute add/edit form options tab
14
+ *
17
15
* @api
18
16
* @since 100.0.2
19
17
*/
@@ -61,6 +59,7 @@ public function __construct(
61
59
62
60
/**
63
61
* Is true only for system attributes which use source model
62
+ *
64
63
* Option labels and position for such attributes are kept in source model and thus cannot be overridden
65
64
*
66
65
* @return bool
@@ -96,12 +95,16 @@ public function getStoresSortedBySortOrder()
96
95
{
97
96
$ stores = $ this ->getStores ();
98
97
if (is_array ($ stores )) {
99
- usort ($ stores , function ($ storeA , $ storeB ) {
100
- if ($ storeA ->getSortOrder () == $ storeB ->getSortOrder ()) {
101
- return $ storeA ->getId () < $ storeB ->getId () ? -1 : 1 ;
98
+ usort (
99
+ $ stores ,
100
+ function ($ storeA , $ storeB ) {
101
+ if ($ storeA ->getSortOrder () == $ storeB ->getSortOrder ()) {
102
+ return $ storeA ->getId () < $ storeB ->getId () ? -1 : 1 ;
103
+ }
104
+
105
+ return ($ storeA ->getSortOrder () < $ storeB ->getSortOrder ()) ? -1 : 1 ;
102
106
}
103
- return ($ storeA ->getSortOrder () < $ storeB ->getSortOrder ()) ? -1 : 1 ;
104
- });
107
+ );
105
108
}
106
109
return $ stores ;
107
110
}
@@ -130,12 +133,14 @@ public function getOptionValues()
130
133
}
131
134
132
135
/**
133
- * @param \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute
136
+ * Preparing values of attribute options
137
+ *
138
+ * @param AbstractAttribute $attribute
134
139
* @param array|\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection $optionCollection
135
140
* @return array
136
141
*/
137
142
protected function _prepareOptionValues (
138
- \ Magento \ Eav \ Model \ Entity \ Attribute \ AbstractAttribute $ attribute ,
143
+ AbstractAttribute $ attribute ,
139
144
$ optionCollection
140
145
) {
141
146
$ type = $ attribute ->getFrontendInput ();
@@ -149,6 +154,41 @@ protected function _prepareOptionValues(
149
154
150
155
$ values = [];
151
156
$ isSystemAttribute = is_array ($ optionCollection );
157
+ if ($ isSystemAttribute ) {
158
+ $ values = $ this ->getPreparedValues ($ optionCollection , $ isSystemAttribute , $ inputType , $ defaultValues );
159
+ } else {
160
+ $ optionCollection ->setPageSize (200 );
161
+ $ pageCount = $ optionCollection ->getLastPageNumber ();
162
+ $ currentPage = 1 ;
163
+ while ($ currentPage <= $ pageCount ) {
164
+ $ optionCollection ->clear ();
165
+ $ optionCollection ->setCurPage ($ currentPage );
166
+ $ values = array_merge (
167
+ $ values ,
168
+ $ this ->getPreparedValues ($ optionCollection , $ isSystemAttribute , $ inputType , $ defaultValues )
169
+ );
170
+ $ currentPage ++;
171
+ }
172
+ }
173
+
174
+ return $ values ;
175
+ }
176
+
177
+ /**
178
+ * Return prepared values of system or user defined attribute options
179
+ *
180
+ * @param array|\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection $optionCollection
181
+ * @param bool $isSystemAttribute
182
+ * @param string $inputType
183
+ * @param array $defaultValues
184
+ */
185
+ private function getPreparedValues (
186
+ $ optionCollection ,
187
+ bool $ isSystemAttribute ,
188
+ string $ inputType ,
189
+ array $ defaultValues
190
+ ) {
191
+ $ values = [];
152
192
foreach ($ optionCollection as $ option ) {
153
193
$ bunch = $ isSystemAttribute ? $ this ->_prepareSystemAttributeOptionValues (
154
194
$ option ,
@@ -169,12 +209,13 @@ protected function _prepareOptionValues(
169
209
170
210
/**
171
211
* Retrieve option values collection
212
+ *
172
213
* It is represented by an array in case of system attribute
173
214
*
174
- * @param \Magento\Eav\Model\Entity\Attribute\ AbstractAttribute $attribute
215
+ * @param AbstractAttribute $attribute
175
216
* @return array|\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection
176
217
*/
177
- protected function _getOptionValuesCollection (\ Magento \ Eav \ Model \ Entity \ Attribute \ AbstractAttribute $ attribute )
218
+ protected function _getOptionValuesCollection (AbstractAttribute $ attribute )
178
219
{
179
220
if ($ this ->canManageOptionDefaultOnly ()) {
180
221
$ options = $ this ->_universalFactory ->create (
@@ -226,7 +267,7 @@ protected function _prepareSystemAttributeOptionValues($option, $inputType, $def
226
267
foreach ($ this ->getStores () as $ store ) {
227
268
$ storeId = $ store ->getId ();
228
269
$ value ['store ' . $ storeId ] = $ storeId ==
229
- \Magento \Store \Model \Store::DEFAULT_STORE_ID ? $ valuePrefix . $ this ->escapeHtml ($ option ['label ' ]) : '' ;
270
+ \Magento \Store \Model \Store::DEFAULT_STORE_ID ? $ valuePrefix . $ this ->escapeHtml ($ option ['label ' ]) : '' ;
230
271
}
231
272
232
273
return [$ value ];
0 commit comments