@@ -182,7 +182,10 @@ private function setCreatedObject($response, $index, $requestDataArray, $isJson)
182
182
$ responseData = $ responseData [$ index ];
183
183
}
184
184
if (is_array ($ responseData )) {
185
- $ persistedData = $ this ->convertToFlatArray (array_merge ($ requestDataArray , $ responseData ));
185
+ $ persistedData = $ this ->convertToFlatArray (array_merge (
186
+ $ requestDataArray ,
187
+ $ this ->convertCustomAndExtensionAttributesArray ($ responseData )
188
+ ));
186
189
} else {
187
190
$ persistedData = $ this ->convertToFlatArray (array_merge ($ requestDataArray , ['return ' => $ responseData ]));
188
191
}
@@ -225,4 +228,43 @@ private function convertToFlatArray($arrayIn, $rootKey = '')
225
228
}
226
229
return $ arrayOut ;
227
230
}
231
+
232
+ /**
233
+ * Convert custom_attributes and extension_attributes array from
234
+ * e.g.
235
+ * 'custom_attributes' => [
236
+ * 0 => [
237
+ * 'attribute_code' => 'code1',
238
+ * 'value' => 'value1',
239
+ * ],
240
+ 1 => [
241
+ * 'attribute_code' => 'code2',
242
+ * 'value' => 'value2',
243
+ * ],
244
+ * ]
245
+ *
246
+ * to
247
+ *
248
+ * 'custom_attributes' => [
249
+ * 'code1' => 'value1',
250
+ * 'code2' => 'value2',
251
+ * ]
252
+ *
253
+ * @param array $arrayIn
254
+ * @return array
255
+ */
256
+ private function convertCustomAndExtensionAttributesArray ($ arrayIn )
257
+ {
258
+ $ keys = ['custom_attributes ' , 'extension_attributes ' ];
259
+ foreach ($ keys as $ key ) {
260
+ if (!array_key_exists ($ key , $ arrayIn )) {
261
+ continue ;
262
+ }
263
+ $ arrayCopy = $ arrayIn [$ key ];
264
+ foreach ($ arrayCopy as $ index => $ attributes ) {
265
+ $ arrayIn [$ key ][$ attributes ['attribute_code ' ]] = $ attributes ['value ' ];
266
+ }
267
+ }
268
+ return $ arrayIn ;
269
+ }
228
270
}
0 commit comments