@@ -45,6 +45,30 @@ public function toNestedArray(
4545 }
4646 $ dataObjectArray = $ this ->dataObjectProcessor ->buildOutputDataArray ($ dataObject , $ dataObjectType );
4747 //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+ {
4872 if (!empty ($ dataObjectArray [AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY ])) {
4973 /** @var AttributeValue[] $customAttributes */
5074 $ customAttributes = $ dataObjectArray [AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY ];
@@ -56,14 +80,9 @@ public function toNestedArray(
5680 }
5781 }
5882 }
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 );
6786 }
6887 }
6988 return $ dataObjectArray ;
0 commit comments