@wix/headless-stores 0.0.49 → 0.0.51
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);
|
|
@@ -516,7 +513,6 @@ export const ProductsListSearchService = implementService.withConfig()(ProductsL
|
|
|
516
513
|
const maxPrice = userFilterMaxPriceSignal.get();
|
|
517
514
|
const selectedInventoryStatuses = selectedInventoryStatusesSignal.get();
|
|
518
515
|
const selectedProductOptions = selectedProductOptionsSignal.get();
|
|
519
|
-
const selectedCategory = selectedCategorySignal.get();
|
|
520
516
|
const selectedVisible = selectedVisibleSignal.get();
|
|
521
517
|
const selectedProductType = selectedProductTypeSignal.get();
|
|
522
518
|
// Check if any filters are different from default values
|
|
@@ -524,13 +520,11 @@ export const ProductsListSearchService = implementService.withConfig()(ProductsL
|
|
|
524
520
|
maxPrice < catalogPriceRange.maxPrice;
|
|
525
521
|
const hasInventoryFilter = selectedInventoryStatuses.length > 0;
|
|
526
522
|
const hasProductOptionsFilter = Object.keys(selectedProductOptions).length > 0;
|
|
527
|
-
const hasCategoryFilter = selectedCategory !== null;
|
|
528
523
|
const hasVisibilityFilter = selectedVisible !== null;
|
|
529
524
|
const hasProductTypeFilter = selectedProductType !== null;
|
|
530
525
|
return (hasPriceFilter ||
|
|
531
526
|
hasInventoryFilter ||
|
|
532
527
|
hasProductOptionsFilter ||
|
|
533
|
-
hasCategoryFilter ||
|
|
534
528
|
hasVisibilityFilter ||
|
|
535
529
|
hasProductTypeFilter);
|
|
536
530
|
});
|
|
@@ -813,7 +807,6 @@ export const ProductsListSearchService = implementService.withConfig()(ProductsL
|
|
|
813
807
|
userFilterMaxPriceSignal.set(catalogMaxPriceSignal.get());
|
|
814
808
|
selectedInventoryStatusesSignal.set([]);
|
|
815
809
|
selectedProductOptionsSignal.set({});
|
|
816
|
-
selectedCategorySignal.set(null);
|
|
817
810
|
selectedVisibleSignal.set(null);
|
|
818
811
|
selectedProductTypeSignal.set(null);
|
|
819
812
|
},
|
|
@@ -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);
|
|
@@ -516,7 +513,6 @@ export const ProductsListSearchService = implementService.withConfig()(ProductsL
|
|
|
516
513
|
const maxPrice = userFilterMaxPriceSignal.get();
|
|
517
514
|
const selectedInventoryStatuses = selectedInventoryStatusesSignal.get();
|
|
518
515
|
const selectedProductOptions = selectedProductOptionsSignal.get();
|
|
519
|
-
const selectedCategory = selectedCategorySignal.get();
|
|
520
516
|
const selectedVisible = selectedVisibleSignal.get();
|
|
521
517
|
const selectedProductType = selectedProductTypeSignal.get();
|
|
522
518
|
// Check if any filters are different from default values
|
|
@@ -524,13 +520,11 @@ export const ProductsListSearchService = implementService.withConfig()(ProductsL
|
|
|
524
520
|
maxPrice < catalogPriceRange.maxPrice;
|
|
525
521
|
const hasInventoryFilter = selectedInventoryStatuses.length > 0;
|
|
526
522
|
const hasProductOptionsFilter = Object.keys(selectedProductOptions).length > 0;
|
|
527
|
-
const hasCategoryFilter = selectedCategory !== null;
|
|
528
523
|
const hasVisibilityFilter = selectedVisible !== null;
|
|
529
524
|
const hasProductTypeFilter = selectedProductType !== null;
|
|
530
525
|
return (hasPriceFilter ||
|
|
531
526
|
hasInventoryFilter ||
|
|
532
527
|
hasProductOptionsFilter ||
|
|
533
|
-
hasCategoryFilter ||
|
|
534
528
|
hasVisibilityFilter ||
|
|
535
529
|
hasProductTypeFilter);
|
|
536
530
|
});
|
|
@@ -813,7 +807,6 @@ export const ProductsListSearchService = implementService.withConfig()(ProductsL
|
|
|
813
807
|
userFilterMaxPriceSignal.set(catalogMaxPriceSignal.get());
|
|
814
808
|
selectedInventoryStatusesSignal.set([]);
|
|
815
809
|
selectedProductOptionsSignal.set({});
|
|
816
|
-
selectedCategorySignal.set(null);
|
|
817
810
|
selectedVisibleSignal.set(null);
|
|
818
811
|
selectedProductTypeSignal.set(null);
|
|
819
812
|
},
|