@wix/headless-stores 0.0.49 → 0.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -206,19 +206,16 @@ export async function parseUrlToSearchOptions(url, categoriesList, defaultSearch
|
|
|
206
206
|
};
|
|
207
207
|
// Initialize search state for service
|
|
208
208
|
const initialSearchState = {};
|
|
209
|
-
// Extract category slug from URL path
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
let categorySlug = null;
|
|
209
|
+
// Extract category slug from URL path
|
|
210
|
+
// The category slug is always the last segment of the path
|
|
211
|
+
const pathSegments = urlObj.pathname.split("/").filter(Boolean);
|
|
213
212
|
let category = undefined;
|
|
214
|
-
if (
|
|
215
|
-
|
|
216
|
-
//
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
initialSearchState.category = category;
|
|
221
|
-
}
|
|
213
|
+
if (pathSegments.length > 0) {
|
|
214
|
+
const lastSegment = pathSegments[pathSegments.length - 1];
|
|
215
|
+
// Check if the last segment matches any category in the categories list
|
|
216
|
+
category = categoriesList.find((cat) => cat.slug === lastSegment);
|
|
217
|
+
if (category) {
|
|
218
|
+
initialSearchState.category = category;
|
|
222
219
|
}
|
|
223
220
|
}
|
|
224
221
|
// Handle text search (q parameter)
|
|
@@ -459,7 +456,7 @@ export async function parseUrlToSearchOptions(url, categoriesList, defaultSearch
|
|
|
459
456
|
*/
|
|
460
457
|
export async function loadProductsListSearchServiceConfig(input) {
|
|
461
458
|
let initialSearchState;
|
|
462
|
-
if (typeof input ===
|
|
459
|
+
if (typeof input === "string") {
|
|
463
460
|
// URL input - parse it
|
|
464
461
|
const categoriesListConfig = await loadCategoriesListServiceConfig();
|
|
465
462
|
const { initialSearchState: parsedState } = await parseUrlToSearchOptions(input, categoriesListConfig.categories);
|
|
@@ -206,19 +206,16 @@ export async function parseUrlToSearchOptions(url, categoriesList, defaultSearch
|
|
|
206
206
|
};
|
|
207
207
|
// Initialize search state for service
|
|
208
208
|
const initialSearchState = {};
|
|
209
|
-
// Extract category slug from URL path
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
let categorySlug = null;
|
|
209
|
+
// Extract category slug from URL path
|
|
210
|
+
// The category slug is always the last segment of the path
|
|
211
|
+
const pathSegments = urlObj.pathname.split("/").filter(Boolean);
|
|
213
212
|
let category = undefined;
|
|
214
|
-
if (
|
|
215
|
-
|
|
216
|
-
//
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
initialSearchState.category = category;
|
|
221
|
-
}
|
|
213
|
+
if (pathSegments.length > 0) {
|
|
214
|
+
const lastSegment = pathSegments[pathSegments.length - 1];
|
|
215
|
+
// Check if the last segment matches any category in the categories list
|
|
216
|
+
category = categoriesList.find((cat) => cat.slug === lastSegment);
|
|
217
|
+
if (category) {
|
|
218
|
+
initialSearchState.category = category;
|
|
222
219
|
}
|
|
223
220
|
}
|
|
224
221
|
// Handle text search (q parameter)
|
|
@@ -459,7 +456,7 @@ export async function parseUrlToSearchOptions(url, categoriesList, defaultSearch
|
|
|
459
456
|
*/
|
|
460
457
|
export async function loadProductsListSearchServiceConfig(input) {
|
|
461
458
|
let initialSearchState;
|
|
462
|
-
if (typeof input ===
|
|
459
|
+
if (typeof input === "string") {
|
|
463
460
|
// URL input - parse it
|
|
464
461
|
const categoriesListConfig = await loadCategoriesListServiceConfig();
|
|
465
462
|
const { initialSearchState: parsedState } = await parseUrlToSearchOptions(input, categoriesListConfig.categories);
|