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; }