@propeller-commerce/propeller-v2-react-ui 0.4.27 → 0.4.29
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.
- package/CHANGELOG.md +28 -0
- package/dist/index.cjs +40 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +40 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2157,6 +2157,7 @@ function useProductSearch(options) {
|
|
|
2157
2157
|
);
|
|
2158
2158
|
const isLoading = !isControlled && internalLoading;
|
|
2159
2159
|
function filterByLanguage(products, lang) {
|
|
2160
|
+
if (!lang) return products;
|
|
2160
2161
|
return products.filter((p) => {
|
|
2161
2162
|
const names = p.names || p.names || [];
|
|
2162
2163
|
if (!names || names.length === 0) return true;
|
|
@@ -2344,13 +2345,21 @@ function useProductSearch(options) {
|
|
|
2344
2345
|
if (!graphqlClient) return;
|
|
2345
2346
|
setSearchLoading(true);
|
|
2346
2347
|
try {
|
|
2347
|
-
const service = createServices(graphqlClient).
|
|
2348
|
+
const service = createServices(graphqlClient).category;
|
|
2349
|
+
const catId = configuration?.baseCategoryId ?? 0;
|
|
2350
|
+
if (!catId) {
|
|
2351
|
+
setSearchResults([]);
|
|
2352
|
+
setSearchItemsFound(0);
|
|
2353
|
+
return;
|
|
2354
|
+
}
|
|
2348
2355
|
const orderlistScope = options.orderlistIds && options.orderlistIds.length > 0 ? {
|
|
2349
2356
|
applyOrderlists: options.applyOrderlists !== false,
|
|
2350
2357
|
orderlistIds: options.orderlistIds
|
|
2351
2358
|
} : { applyOrderlists: false };
|
|
2352
|
-
const
|
|
2353
|
-
|
|
2359
|
+
const userId = options.user && "contactId" in options.user ? options.user.contactId : options.user && "customerId" in options.user ? options.user.customerId : void 0;
|
|
2360
|
+
const contactId = options.user && "contactId" in options.user ? options.user.contactId : void 0;
|
|
2361
|
+
const customerId = options.user && "customerId" in options.user ? options.user.customerId : void 0;
|
|
2362
|
+
const categoryProductSearchInput = {
|
|
2354
2363
|
language,
|
|
2355
2364
|
page: 1,
|
|
2356
2365
|
offset: 10,
|
|
@@ -2360,8 +2369,8 @@ function useProductSearch(options) {
|
|
|
2360
2369
|
ProductStatus.T,
|
|
2361
2370
|
ProductStatus.S
|
|
2362
2371
|
],
|
|
2363
|
-
|
|
2364
|
-
|
|
2372
|
+
hidden: false,
|
|
2373
|
+
term,
|
|
2365
2374
|
searchFields: [
|
|
2366
2375
|
{
|
|
2367
2376
|
fieldNames: [
|
|
@@ -2388,17 +2397,34 @@ function useProductSearch(options) {
|
|
|
2388
2397
|
],
|
|
2389
2398
|
boost: 1
|
|
2390
2399
|
}
|
|
2391
|
-
]
|
|
2400
|
+
],
|
|
2401
|
+
sortInputs: [{ field: ProductSortField.RELEVANCE, order: SortOrder.DESC }],
|
|
2402
|
+
...options.companyId && { companyId: options.companyId },
|
|
2403
|
+
...userId !== void 0 && { userId },
|
|
2404
|
+
...orderlistScope
|
|
2405
|
+
};
|
|
2406
|
+
const priceCalculateProductInput = {
|
|
2407
|
+
taxZone,
|
|
2408
|
+
...options.companyId && { companyId: options.companyId },
|
|
2409
|
+
...contactId !== void 0 && { contactId },
|
|
2410
|
+
...customerId !== void 0 && { customerId }
|
|
2392
2411
|
};
|
|
2393
2412
|
const variables = {
|
|
2394
|
-
|
|
2413
|
+
categoryId: catId,
|
|
2395
2414
|
language,
|
|
2415
|
+
categoryProductSearchInput,
|
|
2416
|
+
priceCalculateProductInput,
|
|
2417
|
+
imageSearchFilters: configuration?.imageSearchFiltersGrid,
|
|
2396
2418
|
imageVariantFilters: configuration?.imageVariantFiltersMedium
|
|
2397
2419
|
};
|
|
2398
|
-
const
|
|
2399
|
-
const
|
|
2420
|
+
const response = await service.getCategory(variables);
|
|
2421
|
+
const productsResponse = response?.products;
|
|
2422
|
+
const rawItems = productsResponse?.items ?? [];
|
|
2423
|
+
const items = filterByLanguage(rawItems, language);
|
|
2424
|
+
const untranslated = rawItems.length - items.length;
|
|
2425
|
+
const apiTotal = productsResponse?.itemsFound ?? rawItems.length;
|
|
2400
2426
|
setSearchResults(items);
|
|
2401
|
-
setSearchItemsFound(
|
|
2427
|
+
setSearchItemsFound(Math.max(0, apiTotal - untranslated));
|
|
2402
2428
|
} catch {
|
|
2403
2429
|
setSearchResults([]);
|
|
2404
2430
|
setSearchItemsFound(0);
|
|
@@ -17185,7 +17211,7 @@ function RegisterForm(rawProps) {
|
|
|
17185
17211
|
] });
|
|
17186
17212
|
}
|
|
17187
17213
|
var RegisterForm_default = RegisterForm;
|
|
17188
|
-
function mapToSearchBarResult(item) {
|
|
17214
|
+
function mapToSearchBarResult(item, language) {
|
|
17189
17215
|
const isCluster = "clusterId" in item;
|
|
17190
17216
|
const displayItem = isCluster ? item.defaultProduct : item;
|
|
17191
17217
|
const id = isCluster ? item.clusterId : item.productId;
|
|
@@ -17193,9 +17219,10 @@ function mapToSearchBarResult(item) {
|
|
|
17193
17219
|
const url = isCluster ? "/cluster/" + id + "/" + slug : "/product/" + id + "/" + slug;
|
|
17194
17220
|
const priceNet = displayItem?.price?.net || 0;
|
|
17195
17221
|
const priceGross = displayItem?.price?.gross || 0;
|
|
17222
|
+
const localizedName = language && item.names?.find((n) => n.language === language)?.value || item.names?.[0]?.value || "Product";
|
|
17196
17223
|
return {
|
|
17197
17224
|
id,
|
|
17198
|
-
name:
|
|
17225
|
+
name: localizedName,
|
|
17199
17226
|
sku: item.sku || displayItem?.sku || "",
|
|
17200
17227
|
// `price` stays the gross value for back-compat; the row picks net/gross
|
|
17201
17228
|
// from the two explicit fields below per the toggle.
|
|
@@ -17222,7 +17249,7 @@ function SearchBar(rawProps) {
|
|
|
17222
17249
|
orderlistIds: props.orderlistIds,
|
|
17223
17250
|
applyOrderlists: props.applyOrderlists
|
|
17224
17251
|
});
|
|
17225
|
-
const results = searchResults.slice(0, maxResults).map((item) => mapToSearchBarResult(item));
|
|
17252
|
+
const results = searchResults.slice(0, maxResults).map((item) => mapToSearchBarResult(item, props.language));
|
|
17226
17253
|
const itemsFound = searchItemsFound;
|
|
17227
17254
|
function formatItemPrice(price) {
|
|
17228
17255
|
if (props.formatPrice) {
|