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[] = []; const productOptions: ProductOption[] = [];
if (parent.children && parent.parentId === null && parent.children.length > 0) { if (parent.children && parent.parentId === null && parent.children.length > 0) {
const group: { [key: string]: string[] } = {}; const group: { [key: string]: string[] } = {};
const groupId: { [key: string]: string } = {};
parent.children.map((child) => { parent.children.map((child) => {
child.options?.map((option) => { child.options?.map((option) => {
if (option && option.group) { if (option && option.group) {
groupId[option.group.name] = option.groupId;
group[option.group.name] = group[option.group.name] group[option.group.name] = group[option.group.name]
? [...new Set([...(group[option.group.name] as []), ...[option.name]])] ? [...new Set([...(group[option.group.name] as []), ...[option.name]])]
: [option.name]; : [option.name];
@ -252,13 +254,15 @@ function transformOptions(parent: ExtendedProduct): ProductOption[] {
}); });
}); });
if (parent.id) { for (const [key, value] of Object.entries(group)) {
for (const [key, value] of Object.entries(group)) { for (const [currentGroupName, currentGroupId] of Object.entries(groupId)) {
productOptions.push({ if (key === currentGroupName) {
id: parent.id, productOptions.push({
name: key, id: currentGroupId,
values: value name: key,
}); values: value
});
}
} }
} }
} }