feat(poc): use group id instead of parent id

This commit is contained in:
Björn Meyer 2023-07-13 14:15:10 +02:00
parent f21f41c59d
commit 3d857f471e

View File

@ -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,16 +254,18 @@ function transformOptions(parent: ExtendedProduct): ProductOption[] {
});
});
if (parent.id) {
for (const [key, value] of Object.entries(group)) {
for (const [currentGroupName, currentGroupId] of Object.entries(groupId)) {
if (key === currentGroupName) {
productOptions.push({
id: parent.id,
id: currentGroupId,
name: key,
values: value
});
}
}
}
}
return productOptions;
}