-
Notifications
You must be signed in to change notification settings - Fork 13
USF-3785: ACO PDP support #264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| /* | ||
|
|
||
| Copyright 2026 Adobe. All rights reserved. | ||
| This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. You may obtain a copy | ||
| of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software distributed under | ||
| the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| OF ANY KIND, either express or implied. See the License for the specific language | ||
| governing permissions and limitations under the License. | ||
|
|
||
| */ | ||
|
|
||
| const { | ||
| CategoriesQuery, | ||
| ProductCountQuery, | ||
| ProductsQuery, | ||
| } = require("../queries"); | ||
| const { requestSaaS } = require("../utils"); | ||
|
|
||
| // Limiting at 10,000 products per category | ||
| const MAX_PAGES_FETCHED = 20; | ||
|
|
||
| const accsMapper = ({ productView }) => ({ | ||
| urlKey: productView.urlKey, | ||
| sku: productView.sku, | ||
| }); | ||
|
|
||
| async function getAllCategories(context) { | ||
| const categories = []; | ||
| const categoriesResp = await requestSaaS( | ||
| CategoriesQuery, | ||
| "getCategories", | ||
| {}, | ||
| context, | ||
| ); | ||
| const items = categoriesResp.data.categories; | ||
| for (const { urlPath, level, name } of items) { | ||
| const index = parseInt(level); | ||
| categories[index] = categories[index] || []; | ||
| categories[index].push({ urlPath, name, level }); | ||
| } | ||
| return categories; | ||
| } | ||
|
|
||
| async function getSkus(categoryPath, context) { | ||
| let productsResp = await requestSaaS( | ||
| ProductsQuery, | ||
| "getProducts", | ||
| { currentPage: 1, categoryPath }, | ||
| context, | ||
| ); | ||
| const products = [...productsResp.data.productSearch.items.map(accsMapper)]; | ||
| let maxPage = productsResp.data.productSearch.page_info.total_pages; | ||
|
|
||
| if (maxPage > MAX_PAGES_FETCHED) { | ||
| console.warn(`Category ${categoryPath} has more than 10000 products.`); | ||
| maxPage = MAX_PAGES_FETCHED; | ||
| } | ||
|
|
||
| for (let currentPage = 2; currentPage <= maxPage; currentPage++) { | ||
| productsResp = await requestSaaS( | ||
| ProductsQuery, | ||
| "getProducts", | ||
| { currentPage, categoryPath }, | ||
| context, | ||
| ); | ||
| products.push(...productsResp.data.productSearch.items.map(accsMapper)); | ||
| } | ||
|
|
||
| return products; | ||
| } | ||
|
|
||
| async function getAllSkus(context) { | ||
| const productCountResp = await requestSaaS( | ||
| ProductCountQuery, | ||
| "getProductCount", | ||
| { categoryPath: "" }, | ||
| context, | ||
| ); | ||
| const productCount = | ||
| productCountResp.data.productSearch?.page_info?.total_pages; | ||
|
|
||
| if (!productCount) { | ||
| throw new Error("Unknown product count."); | ||
| } | ||
|
|
||
| if (productCount <= 10000) { | ||
| // we can get everything from the default category | ||
| return getSkus("", context); | ||
| } | ||
|
|
||
| const products = new Set(); | ||
| // we have to traverse the category tree | ||
| const categories = await getAllCategories(context); | ||
|
|
||
| outer: for (const category of categories) { | ||
| if (!category) continue; | ||
| while (category.length) { | ||
| const slice = category.splice(0, 50); | ||
| const fetchedProducts = await Promise.all( | ||
| slice.map((cat) => getSkus(cat.urlPath, context)), | ||
| ); | ||
| fetchedProducts | ||
| .flatMap((skus) => skus) | ||
| .forEach((sku) => products.add(sku)); | ||
| if (products.size >= productCount) { | ||
| // break if we got all products already | ||
| break outer; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (products.size !== productCount) { | ||
| console.warn( | ||
| `Expected ${productCount} products, but got ${products.size}.`, | ||
| ); | ||
| } | ||
|
|
||
| return [...products]; | ||
| } | ||
|
|
||
| module.exports = { getAllSkus }; |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,68 @@ | ||||||
| /* | ||||||
|
|
||||||
| Copyright 2026 Adobe. All rights reserved. | ||||||
| This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||||||
| you may not use this file except in compliance with the License. You may obtain a copy | ||||||
| of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||||||
|
|
||||||
| Unless required by applicable law or agreed to in writing, software distributed under | ||||||
| the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||||||
| OF ANY KIND, either express or implied. See the License for the specific language | ||||||
| governing permissions and limitations under the License. | ||||||
|
|
||||||
| */ | ||||||
|
|
||||||
| const { requestSaaS } = require("../utils"); | ||||||
| const { ProductsQuery } = require("../queries"); | ||||||
|
|
||||||
| // Limiting at 10,000 products per category | ||||||
|
||||||
| // Limiting at 10,000 products per category |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is applicable to ACO as well. It's a Catalog Service limitation on pagination (500 products per page, max 20 pages). I am reworking this logic to account for category paths related to the configured category families so we can get around this, though.
I think I'll just close this PR and open a new one with the reworked functionality.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to make the error message more generic. Otherwise, any change on the pageSize or the MAX_PAGES_FETCHED would the error message be misleading.
| console.warn(`Catalog has more than 10000 products.`); | |
| console.warn(`Catalog has more products than the maximum supported. Only the first ${MAX_PAGES_FETCHED} pages will be fetched.`); |
Uh oh!
There was an error while loading. Please reload this page.