@@ -45,6 +45,30 @@ public function toNestedArray(
45
45
}
46
46
$ dataObjectArray = $ this ->dataObjectProcessor ->buildOutputDataArray ($ dataObject , $ dataObjectType );
47
47
//process custom attributes if present
48
+ $ dataObjectArray = $ this ->processCustomAttributes ($ dataObjectArray , $ skipAttributes );
49
+
50
+ if (!empty ($ dataObjectArray [ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY ])) {
51
+ /** @var array $extensionAttributes */
52
+ $ extensionAttributes = $ dataObjectArray [ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY ];
53
+ unset($ dataObjectArray [ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY ]);
54
+ foreach ($ extensionAttributes as $ attributeKey => $ attributeValue ) {
55
+ if (!in_array ($ attributeKey , $ skipAttributes )) {
56
+ $ dataObjectArray [$ attributeKey ] = $ attributeValue ;
57
+ }
58
+ }
59
+ }
60
+ return $ dataObjectArray ;
61
+ }
62
+
63
+ /**
64
+ * Recursive process array to process customer attributes
65
+ *
66
+ * @param array $dataObjectArray
67
+ * @param array $skipAttributes
68
+ * @return array
69
+ */
70
+ private function processCustomAttributes (array $ dataObjectArray , array $ skipAttributes ): array
71
+ {
48
72
if (!empty ($ dataObjectArray [AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY ])) {
49
73
/** @var AttributeValue[] $customAttributes */
50
74
$ customAttributes = $ dataObjectArray [AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY ];
@@ -56,14 +80,9 @@ public function toNestedArray(
56
80
}
57
81
}
58
82
}
59
- if (!empty ($ dataObjectArray [ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY ])) {
60
- /** @var array $extensionAttributes */
61
- $ extensionAttributes = $ dataObjectArray [ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY ];
62
- unset($ dataObjectArray [ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY ]);
63
- foreach ($ extensionAttributes as $ attributeKey => $ attributeValue ) {
64
- if (!in_array ($ attributeKey , $ skipAttributes )) {
65
- $ dataObjectArray [$ attributeKey ] = $ attributeValue ;
66
- }
83
+ foreach ($ dataObjectArray as $ key => $ value ) {
84
+ if (is_array ($ value )) {
85
+ $ dataObjectArray [$ key ] = $ this ->processCustomAttributes ($ value , $ skipAttributes );
67
86
}
68
87
}
69
88
return $ dataObjectArray ;
0 commit comments