mirror of
https://github.com/vercel/commerce.git
synced 2025-05-15 05:56:59 +00:00
feat(poc): use group id instead of parent id
This commit is contained in:
parent
f21f41c59d
commit
3d857f471e
@ -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
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user