mirror of
https://github.com/vercel/commerce.git
synced 2025-05-15 05:56:59 +00:00
feat(poc): if parent change variant url
This commit is contained in:
parent
3d857f471e
commit
245127227e
@ -116,10 +116,33 @@ export async function getSearchCollectionProducts(params?: {
|
|||||||
const searchCriteria = { ...criteria, ...sorting };
|
const searchCriteria = { ...criteria, ...sorting };
|
||||||
|
|
||||||
const res = await requestSearchCollectionProducts(searchCriteria);
|
const res = await requestSearchCollectionProducts(searchCriteria);
|
||||||
|
res.elements = await changeVariantUrlToParentUrl(res);
|
||||||
|
|
||||||
return res ? transformProducts(res) : [];
|
return res ? transformProducts(res) : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function changeVariantUrlToParentUrl(
|
||||||
|
collection: ExtendedProductListingResult
|
||||||
|
): Promise<ExtendedProduct[]> {
|
||||||
|
const newElements: ExtendedProduct[] = [];
|
||||||
|
if (collection.elements && collection.elements.length > 0) {
|
||||||
|
await Promise.all(
|
||||||
|
collection.elements.map(async (item) => {
|
||||||
|
if (item.parentId && item.seoUrls && item.seoUrls[0]) {
|
||||||
|
const parentProduct = await getFirstProduct(item.parentId);
|
||||||
|
if (parentProduct && parentProduct.seoUrls && parentProduct.seoUrls[0]) {
|
||||||
|
item.seoUrls[0].seoPathInfo = parentProduct.seoUrls[0].seoPathInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
newElements.push(item);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return newElements;
|
||||||
|
}
|
||||||
|
|
||||||
export async function getCollectionProducts(params?: {
|
export async function getCollectionProducts(params?: {
|
||||||
collection: string;
|
collection: string;
|
||||||
page?: number;
|
page?: number;
|
||||||
@ -152,6 +175,7 @@ export async function getCollectionProducts(params?: {
|
|||||||
: params?.defaultSearchCriteria;
|
: params?.defaultSearchCriteria;
|
||||||
const productsCriteria = { ...criteria, ...sorting };
|
const productsCriteria = { ...criteria, ...sorting };
|
||||||
res = await requestCategoryProductsCollection(category, productsCriteria);
|
res = await requestCategoryProductsCollection(category, productsCriteria);
|
||||||
|
res.elements = await changeVariantUrlToParentUrl(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
Loading…
x
Reference in New Issue
Block a user