Repository: pimcore/pimcore (language: php)

Issue:
[Bug, EC]: ClassificationStore inheritance is not working
### Pimcore version

> 11

### Steps to reproduce

- create classification store with a few keys and groups
- add inheriting object structure in object key
- add a few values on parent object in same group
- add other values on child object in same group
- call getItems() on child using PHP API

### Actual Behavior

- only the values of the child in the group are returned

### Expected Behavior

- a merged array with values from children and (all) parents should be returned


Discussion / hints:
problem is located there https://github.com/pimcore/pimcore/blob/068781b7e6b40e259a6b3ade4b2fa2ad79a4688d/models/DataObject/Classificationstore.php#L101

using $array1 + $array2 will not merge correctly if a key is already present
using array_merge_recursive would work correctly if the array keys would be non-numeric, but they are

https://onlinephp.io/c/f3dca - snipped to play with
Thank you for reporting, confirming the issue.

Assigning Robert, as he worked on it on https://github.com/pimcore/pimcore/pull/14477 and knows the most behind this change.
So far, i think we should replace the callable with a custom function that walks the array and performs a merge without resetting the keys. 
Hi @kingjia90,

yeah I think this is the only way as far as there are numeric keys... array_merge_recursive would work if the keys would be non numeric.

but walking the whole tree and merging would be the best way in my opinion

Thank you!

Fix patch:
diff --git a/models/DataObject/Classificationstore.php b/models/DataObject/Classificationstore.php
index 3be2ae0f803..801a9444287 100644
--- a/models/DataObject/Classificationstore.php
+++ b/models/DataObject/Classificationstore.php
@@ -98,7 +98,12 @@ public function getItems(): array
             return $this->items;
         }
 
-        return $this->getAllDataFromField(fn ($classificationStore, $fieldsArray) => $fieldsArray + $classificationStore->items);
+        return $this->getAllDataFromField(
+            fn ($classificationStore, $fieldsArray) => $this->mergeArrays(
+                $fieldsArray,
+                $classificationStore->items
+            )
+        );
     }
 
     public function setObject(Concrete $object): static
@@ -478,4 +483,21 @@ private function getGroupConfigById(int $groupId): ?Classificationstore\GroupCon
     {
         return Classificationstore\GroupConfig::getById($groupId);
     }
+
+    private function mergeArrays(array $a1, array $a2): array
+    {
+        foreach($a1 as $key => $value) {
+            if(array_key_exists($key, $a2)) {
+                if(is_array($value)) {
+                    $a2[$key] = $this->mergeArrays($a2[$key], $value);
+                } else {
+                    $a2[$key] = $value;
+                }
+            } else {
+                $a2[$key] = $value;
+            }
+        }
+
+        return $a2;
+    }
 }


Test patch: