From 748eb97db6c6981d14d5ca02ac5223a6a3765936 Mon Sep 17 00:00:00 2001 From: Thijs De Paepe Date: Fri, 20 Dec 2024 19:09:34 +0100 Subject: [PATCH] fix: scalar issues during copy --- .../DataStructure/BuildProductMatcher.php | 91 +++++++++++++++++++ src/Model/DataStructure/Item.php | 2 +- 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 src/Component/Akeneo/DataStructure/BuildProductMatcher.php diff --git a/src/Component/Akeneo/DataStructure/BuildProductMatcher.php b/src/Component/Akeneo/DataStructure/BuildProductMatcher.php new file mode 100644 index 0000000..653b6bd --- /dev/null +++ b/src/Component/Akeneo/DataStructure/BuildProductMatcher.php @@ -0,0 +1,91 @@ +getItemNodes() as $code => $itemNode) { + $matcher = $itemNode->getMatcher(); + + if ($matcher->matches('values')) { + $fields['values'][$matcher->getPrimaryKey()][] = $itemNode->getValue(); + } else { + $fields[$code] = $itemNode->getValue(); + } + } + + return $fields; + } + + public static function revertMatcherToProduct(array $productData): array + { + $fields = []; + foreach ($productData as $field => &$fieldValue) { + $matcher = $fieldValue['matcher'] ?? null; + if ($matcher instanceof Matcher) { + unset($fieldValue['matcher']); + $fields['values'][$matcher->getPrimaryKey()][] = $fieldValue; + } else { + $fields[$field] = $fieldValue; + } + } + + return $fields; + } + + public static function revertToKeyValue(array $productData): array + { + $fields = []; + foreach ($productData as $field => $fieldValue) { + $fields[$field] = $fieldValue; + $matcher = $fieldValue['matcher'] ?? null; + if ($matcher instanceof Matcher) { + $fields[$field] = $fieldValue['data'] ?? null; + } + } + + return $fields; + } +} \ No newline at end of file diff --git a/src/Model/DataStructure/Item.php b/src/Model/DataStructure/Item.php index 5abf035..aa6f9ec 100644 --- a/src/Model/DataStructure/Item.php +++ b/src/Model/DataStructure/Item.php @@ -40,7 +40,7 @@ public function copyItem(string $fromCode, string $toCode): void } // Property Values - if (is_string($itemValue)) { + if (!is_array($itemValue)) { $this->addItem($toCode, $itemValue, $item->getContext()); return; }