@@ -105,71 +105,87 @@ public function __construct(
105
105
*/
106
106
public function getFields (array $ context = []): array
107
107
{
108
+ /** @var ProductAttributeInterface[] $attributes */
108
109
$ attributes = $ this ->eavConfig ->getEntityAttributes (ProductAttributeInterface::ENTITY_TYPE_CODE );
109
110
$ allAttributes = [];
110
111
111
112
foreach ($ attributes as $ attribute ) {
112
- if (in_array ($ attribute ->getAttributeCode (), $ this ->excludedAttributes , true )) {
113
- continue ;
114
- }
115
- $ attributeAdapter = $ this ->attributeAdapterProvider ->getByAttributeCode ($ attribute ->getAttributeCode ());
116
- $ fieldName = $ this ->fieldNameResolver ->getFieldName ($ attributeAdapter );
113
+ $ allAttributes += $ this ->getField ($ attribute );
114
+ }
117
115
118
- $ allAttributes [$ fieldName ] = [
119
- 'type ' => $ this ->fieldTypeResolver ->getFieldType ($ attributeAdapter ),
120
- ];
116
+ $ allAttributes ['store_id ' ] = [
117
+ 'type ' => $ this ->fieldTypeConverter ->convert (FieldTypeConverterInterface::INTERNAL_DATA_TYPE_STRING ),
118
+ 'index ' => $ this ->indexTypeConverter ->convert (IndexTypeConverterInterface::INTERNAL_NO_INDEX_VALUE ),
119
+ ];
121
120
122
- $ index = $ this ->fieldIndexResolver ->getFieldIndex ($ attributeAdapter );
123
- if (null !== $ index ) {
124
- $ allAttributes [$ fieldName ]['index ' ] = $ index ;
125
- }
121
+ return $ allAttributes ;
122
+ }
126
123
127
- if ($ attributeAdapter ->isSortable ()) {
128
- $ sortFieldName = $ this ->fieldNameResolver ->getFieldName (
129
- $ attributeAdapter ,
130
- ['type ' => FieldMapperInterface::TYPE_SORT ]
131
- );
132
- $ allAttributes [$ fieldName ]['fields ' ][$ sortFieldName ] = [
133
- 'type ' => $ this ->fieldTypeConverter ->convert (
134
- FieldTypeConverterInterface::INTERNAL_DATA_TYPE_KEYWORD
135
- ),
136
- 'index ' => $ this ->indexTypeConverter ->convert (
137
- IndexTypeConverterInterface::INTERNAL_NO_ANALYZE_VALUE
138
- )
139
- ];
140
- }
124
+ /**
125
+ * Get field mapping for specific attribute.
126
+ *
127
+ * @param ProductAttributeInterface $attribute
128
+ * @return array
129
+ */
130
+ public function getField (ProductAttributeInterface $ attribute ): array
131
+ {
132
+ $ fieldMapping = [];
133
+ if (in_array ($ attribute ->getAttributeCode (), $ this ->excludedAttributes , true )) {
134
+ return $ fieldMapping ;
135
+ }
141
136
142
- if ($ attributeAdapter ->isTextType ()) {
143
- $ keywordFieldName = FieldTypeConverterInterface::INTERNAL_DATA_TYPE_KEYWORD ;
144
- $ index = $ this ->indexTypeConverter ->convert (
137
+ $ attributeAdapter = $ this ->attributeAdapterProvider ->getByAttributeCode ($ attribute ->getAttributeCode ());
138
+ $ fieldName = $ this ->fieldNameResolver ->getFieldName ($ attributeAdapter );
139
+
140
+ $ fieldMapping [$ fieldName ] = [
141
+ 'type ' => $ this ->fieldTypeResolver ->getFieldType ($ attributeAdapter ),
142
+ ];
143
+
144
+ $ index = $ this ->fieldIndexResolver ->getFieldIndex ($ attributeAdapter );
145
+ if (null !== $ index ) {
146
+ $ fieldMapping [$ fieldName ]['index ' ] = $ index ;
147
+ }
148
+
149
+ if ($ attributeAdapter ->isSortable ()) {
150
+ $ sortFieldName = $ this ->fieldNameResolver ->getFieldName (
151
+ $ attributeAdapter ,
152
+ ['type ' => FieldMapperInterface::TYPE_SORT ]
153
+ );
154
+ $ fieldMapping [$ fieldName ]['fields ' ][$ sortFieldName ] = [
155
+ 'type ' => $ this ->fieldTypeConverter ->convert (
156
+ FieldTypeConverterInterface::INTERNAL_DATA_TYPE_KEYWORD
157
+ ),
158
+ 'index ' => $ this ->indexTypeConverter ->convert (
145
159
IndexTypeConverterInterface::INTERNAL_NO_ANALYZE_VALUE
146
- );
147
- $ allAttributes [$ fieldName ]['fields ' ][$ keywordFieldName ] = [
148
- 'type ' => $ this ->fieldTypeConverter ->convert (
149
- FieldTypeConverterInterface::INTERNAL_DATA_TYPE_KEYWORD
150
- )
151
- ];
152
- if ($ index ) {
153
- $ allAttributes [$ fieldName ]['fields ' ][$ keywordFieldName ]['index ' ] = $ index ;
154
- }
155
- }
160
+ )
161
+ ];
162
+ }
156
163
157
- if ($ attributeAdapter ->isComplexType ()) {
158
- $ childFieldName = $ this ->fieldNameResolver ->getFieldName (
159
- $ attributeAdapter ,
160
- ['type ' => FieldMapperInterface::TYPE_QUERY ]
161
- );
162
- $ allAttributes [$ childFieldName ] = [
163
- 'type ' => $ this ->fieldTypeConverter ->convert (FieldTypeConverterInterface::INTERNAL_DATA_TYPE_STRING )
164
- ];
164
+ if ($ attributeAdapter ->isTextType ()) {
165
+ $ keywordFieldName = FieldTypeConverterInterface::INTERNAL_DATA_TYPE_KEYWORD ;
166
+ $ index = $ this ->indexTypeConverter ->convert (
167
+ IndexTypeConverterInterface::INTERNAL_NO_ANALYZE_VALUE
168
+ );
169
+ $ fieldMapping [$ fieldName ]['fields ' ][$ keywordFieldName ] = [
170
+ 'type ' => $ this ->fieldTypeConverter ->convert (
171
+ FieldTypeConverterInterface::INTERNAL_DATA_TYPE_KEYWORD
172
+ )
173
+ ];
174
+ if ($ index ) {
175
+ $ fieldMapping [$ fieldName ]['fields ' ][$ keywordFieldName ]['index ' ] = $ index ;
165
176
}
166
177
}
167
178
168
- $ allAttributes ['store_id ' ] = [
169
- 'type ' => $ this ->fieldTypeConverter ->convert (FieldTypeConverterInterface::INTERNAL_DATA_TYPE_STRING ),
170
- 'index ' => $ this ->indexTypeConverter ->convert (IndexTypeConverterInterface::INTERNAL_NO_INDEX_VALUE ),
171
- ];
179
+ if ($ attributeAdapter ->isComplexType ()) {
180
+ $ childFieldName = $ this ->fieldNameResolver ->getFieldName (
181
+ $ attributeAdapter ,
182
+ ['type ' => FieldMapperInterface::TYPE_QUERY ]
183
+ );
184
+ $ fieldMapping [$ childFieldName ] = [
185
+ 'type ' => $ this ->fieldTypeConverter ->convert (FieldTypeConverterInterface::INTERNAL_DATA_TYPE_STRING )
186
+ ];
187
+ }
172
188
173
- return $ allAttributes ;
189
+ return $ fieldMapping ;
174
190
}
175
191
}
0 commit comments