From 3d857f471efca3e540a33e0de55fbf0078b7d14a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Meyer?= Date: Thu, 13 Jul 2023 14:15:10 +0200 Subject: [PATCH] feat(poc): use group id instead of parent id --- lib/shopware/transform.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/shopware/transform.ts b/lib/shopware/transform.ts index 3afef3a06..b9bfab8f5 100644 --- a/lib/shopware/transform.ts +++ b/lib/shopware/transform.ts @@ -242,9 +242,11 @@ function transformOptions(parent: ExtendedProduct): ProductOption[] { const productOptions: ProductOption[] = []; if (parent.children && parent.parentId === null && parent.children.length > 0) { const group: { [key: string]: string[] } = {}; + const groupId: { [key: string]: string } = {}; parent.children.map((child) => { child.options?.map((option) => { if (option && option.group) { + groupId[option.group.name] = option.groupId; group[option.group.name] = group[option.group.name] ? [...new Set([...(group[option.group.name] as []), ...[option.name]])] : [option.name]; @@ -252,13 +254,15 @@ function transformOptions(parent: ExtendedProduct): ProductOption[] { }); }); - if (parent.id) { - for (const [key, value] of Object.entries(group)) { - productOptions.push({ - id: parent.id, - name: key, - values: value - }); + for (const [key, value] of Object.entries(group)) { + for (const [currentGroupName, currentGroupId] of Object.entries(groupId)) { + if (key === currentGroupName) { + productOptions.push({ + id: currentGroupId, + name: key, + values: value + }); + } } } }