@@ -117,15 +117,15 @@ public function addChild($sku, $childSku)
117
117
throw new StateException (__ ('Parent product does not have configurable product options ' ));
118
118
}
119
119
120
- $ configurableOptionData = [];
120
+ $ attributeIds = [];
121
121
foreach ($ configurableProductOptions as $ configurableProductOption ) {
122
122
$ attributeCode = $ configurableProductOption ->getProductAttribute ()->getAttributeCode ();
123
123
if (!$ child ->getData ($ attributeCode )) {
124
124
throw new StateException (__ ('Child product does not have attribute value %1 ' , $ attributeCode ));
125
125
}
126
- $ configurableOptionData = array_merge ($ configurableOptionData ,
127
- $ this ->getConfigurableAttributesData ($ configurableProductOption ->getAttributeId ()));
126
+ $ attributeIds [] = $ configurableProductOption ->getAttributeId ();
128
127
}
128
+ $ configurableOptionData = $ this ->getConfigurableAttributesData ($ attributeIds );
129
129
130
130
/** @var Factory $optionFactory */
131
131
$ optionFactory = $ this ->getOptionsFactory ();
@@ -201,33 +201,35 @@ private function getAttributeFactory()
201
201
/**
202
202
* Get Configurable Attribute Data
203
203
*
204
- * @param int $attributeId
204
+ * @param int[] $attributeIds
205
205
* @return array
206
206
*/
207
- private function getConfigurableAttributesData ($ attributeId )
207
+ private function getConfigurableAttributesData ($ attributeIds )
208
208
{
209
209
$ attributeValues = [];
210
- $ attribute = $ this ->getAttributeFactory ()->create ();
211
- $ attribute ->load ($ attributeId );
212
- foreach ($ attribute ->getOptions () as $ option ) {
213
- if ($ option ->getValue ()) {
214
- $ attributeValues [] = [
215
- 'label ' => $ option ->getLabel (),
210
+ $ attributes = $ this ->getAttributeFactory ()->create ()
211
+ ->getCollection ()
212
+ ->addFieldToFilter ('attribute_id ' , $ attributeIds )
213
+ ->getItems ();
214
+ foreach ($ attributes as $ attribute ) {
215
+ foreach ($ attribute ->getOptions () as $ option ) {
216
+ if ($ option ->getValue ()) {
217
+ $ attributeValues [] = [
218
+ 'label ' => $ option ->getLabel (),
219
+ 'attribute_id ' => $ attribute ->getId (),
220
+ 'value_index ' => $ option ->getValue (),
221
+ ];
222
+ }
223
+ }
224
+ $ configurableAttributesData [] =
225
+ [
216
226
'attribute_id ' => $ attribute ->getId (),
217
- 'value_index ' => $ option ->getValue (),
227
+ 'code ' => $ attribute ->getAttributeCode (),
228
+ 'label ' => $ attribute ->getStoreLabel (),
229
+ 'values ' => $ attributeValues ,
218
230
];
219
- }
220
231
}
221
232
222
- $ configurableAttributesData = [
223
- [
224
- 'attribute_id ' => $ attribute ->getId (),
225
- 'code ' => $ attribute ->getAttributeCode (),
226
- 'label ' => $ attribute ->getStoreLabel (),
227
- 'values ' => $ attributeValues ,
228
- ],
229
- ];
230
-
231
233
return $ configurableAttributesData ;
232
234
}
233
235
}
0 commit comments