@sledge-app/react-instant-search 2.0.66 → 2.0.68
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/dist/components/SearchResultWidget/utils.d.ts.map +1 -1
- package/dist/sledge-react-instant-search.cjs +1 -1
- package/dist/sledge-react-instant-search.cjs.map +1 -1
- package/dist/sledge-react-instant-search.js +65 -13
- package/dist/sledge-react-instant-search.js.map +1 -1
- package/package.json +1 -1
|
@@ -1807,6 +1807,19 @@ const checkWishlist = async ({ id, variantId = "", query = null }) => {
|
|
|
1807
1807
|
return;
|
|
1808
1808
|
});
|
|
1809
1809
|
};
|
|
1810
|
+
const checkWishlists = async () => {
|
|
1811
|
+
let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
|
|
1812
|
+
let url = `${API_URL}/wishlist/checks`;
|
|
1813
|
+
return await fetchApi({
|
|
1814
|
+
url,
|
|
1815
|
+
method: "GET",
|
|
1816
|
+
authorization: sledgeAuthApp
|
|
1817
|
+
}).then((result) => {
|
|
1818
|
+
return result;
|
|
1819
|
+
}).catch(() => {
|
|
1820
|
+
return;
|
|
1821
|
+
});
|
|
1822
|
+
};
|
|
1810
1823
|
const clearWishlist = async () => {
|
|
1811
1824
|
let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
|
|
1812
1825
|
let url = `${API_URL}/wishlist/clear`;
|
|
@@ -3308,6 +3321,27 @@ const BadgeInitSelector = (props) => {
|
|
|
3308
3321
|
});
|
|
3309
3322
|
}
|
|
3310
3323
|
};
|
|
3324
|
+
let wishlistBatchCache = null;
|
|
3325
|
+
let wishlistBatchPromise = null;
|
|
3326
|
+
const fetchWishlistBatch = async () => {
|
|
3327
|
+
if (wishlistBatchCache)
|
|
3328
|
+
return wishlistBatchCache;
|
|
3329
|
+
if (!wishlistBatchPromise) {
|
|
3330
|
+
wishlistBatchPromise = checkWishlists().then((result) => {
|
|
3331
|
+
wishlistBatchCache = result;
|
|
3332
|
+
wishlistBatchPromise = null;
|
|
3333
|
+
return result;
|
|
3334
|
+
}).catch(() => {
|
|
3335
|
+
wishlistBatchPromise = null;
|
|
3336
|
+
return;
|
|
3337
|
+
});
|
|
3338
|
+
}
|
|
3339
|
+
return wishlistBatchPromise;
|
|
3340
|
+
};
|
|
3341
|
+
const clearWishlistBatchCache = () => {
|
|
3342
|
+
wishlistBatchCache = null;
|
|
3343
|
+
wishlistBatchPromise = null;
|
|
3344
|
+
};
|
|
3311
3345
|
const Trigger = (props) => {
|
|
3312
3346
|
var _a, _b, _c, _d, _e;
|
|
3313
3347
|
const {
|
|
@@ -3358,7 +3392,8 @@ const Trigger = (props) => {
|
|
|
3358
3392
|
const { show: show_notification, location: location_notification } = ((_c = dataSettings == null ? void 0 : dataSettings.display) == null ? void 0 : _c.notification) || {};
|
|
3359
3393
|
const { title_added_to_wishlist, text_added_to_wishlist, title_removed_to_wishlist, text_removed_to_wishlist, title_fail_add_to_wishlist, text_fail_add_to_wishlist } = ((_d = dataSettings == null ? void 0 : dataSettings.languages) == null ? void 0 : _d.notification) || {};
|
|
3360
3394
|
const { alert_login, alert, login_button } = ((_e = dataSettings == null ? void 0 : dataSettings.languages) == null ? void 0 : _e.widget) || {};
|
|
3361
|
-
const handleCheckWishlist = async () => {
|
|
3395
|
+
const handleCheckWishlist = async (props2) => {
|
|
3396
|
+
const { useBatch = true } = props2 || {};
|
|
3362
3397
|
let response;
|
|
3363
3398
|
let queryParam = {
|
|
3364
3399
|
...wishlistPreviewSettings && (generalPreviewSettings == null ? void 0 : generalPreviewSettings.use_dummy_data) ? {
|
|
@@ -3369,11 +3404,23 @@ const Trigger = (props) => {
|
|
|
3369
3404
|
response = wishlistChecked;
|
|
3370
3405
|
setIsFirstTime(false);
|
|
3371
3406
|
} else {
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3407
|
+
if (useBatch && !reload && !wishlistPreviewSettings && !(generalPreviewSettings == null ? void 0 : generalPreviewSettings.use_dummy_data)) {
|
|
3408
|
+
const batchResponse = await fetchWishlistBatch();
|
|
3409
|
+
const { status, data } = batchResponse || {};
|
|
3410
|
+
if ((status == null ? void 0 : status.code) === 200 && data) {
|
|
3411
|
+
const productIdValue = productId ? String(productId) : "";
|
|
3412
|
+
const variantIdValue = productVariantId ? String(productVariantId) : "";
|
|
3413
|
+
const productWishlist = productIdValue ? (data == null ? void 0 : data[productIdValue]) || {} : {};
|
|
3414
|
+
response = Boolean((productWishlist == null ? void 0 : productWishlist.all) || variantIdValue && (productWishlist == null ? void 0 : productWishlist[variantIdValue]));
|
|
3415
|
+
}
|
|
3416
|
+
}
|
|
3417
|
+
if (typeof response === "undefined") {
|
|
3418
|
+
response = await checkWishlist({
|
|
3419
|
+
id: productId,
|
|
3420
|
+
variantId: productVariantId,
|
|
3421
|
+
query: queryParam
|
|
3422
|
+
});
|
|
3423
|
+
}
|
|
3377
3424
|
}
|
|
3378
3425
|
setIsWishlist(forceActive ? forceActive : response);
|
|
3379
3426
|
};
|
|
@@ -3411,6 +3458,7 @@ const Trigger = (props) => {
|
|
|
3411
3458
|
});
|
|
3412
3459
|
if (run) {
|
|
3413
3460
|
setIsWishlist(!isWishlist);
|
|
3461
|
+
clearWishlistBatchCache();
|
|
3414
3462
|
if (triggerRenderWishlistBadge)
|
|
3415
3463
|
triggerRenderWishlistBadge(true);
|
|
3416
3464
|
if (isJsVersion) {
|
|
@@ -3432,8 +3480,6 @@ const Trigger = (props) => {
|
|
|
3432
3480
|
if (window.sledgeWishlistButtonDetailUpdate)
|
|
3433
3481
|
window.sledgeWishlistButtonDetailUpdate();
|
|
3434
3482
|
}
|
|
3435
|
-
if (!wishlistPreviewSettings)
|
|
3436
|
-
handleCheckWishlist();
|
|
3437
3483
|
if (!isWishlist) {
|
|
3438
3484
|
handleFunctions.onAfterAddWishlist && handleFunctions.onAfterAddWishlist("success");
|
|
3439
3485
|
} else {
|
|
@@ -4468,8 +4514,7 @@ const VariantSelector = (props) => {
|
|
|
4468
4514
|
setSelectedVariantId == null ? void 0 : setSelectedVariantId(variantId);
|
|
4469
4515
|
if (inventoryQuantity)
|
|
4470
4516
|
setSelectedVariantStock == null ? void 0 : setSelectedVariantStock(inventoryQuantity);
|
|
4471
|
-
|
|
4472
|
-
setSelectedVariantInventoryManagement == null ? void 0 : setSelectedVariantInventoryManagement(inventoryManagement);
|
|
4517
|
+
setSelectedVariantInventoryManagement == null ? void 0 : setSelectedVariantInventoryManagement(inventoryManagement || null);
|
|
4473
4518
|
if (inventoryPolicy)
|
|
4474
4519
|
setSelectedVariantInventoryPolicy == null ? void 0 : setSelectedVariantInventoryPolicy(inventoryPolicy);
|
|
4475
4520
|
if (price)
|
|
@@ -6881,8 +6926,8 @@ const keyOpenFilters = ({ items = [] }) => {
|
|
|
6881
6926
|
}).filter((item) => item) : [];
|
|
6882
6927
|
};
|
|
6883
6928
|
const handleSearchResponse = async (props) => {
|
|
6884
|
-
var _a, _b, _c;
|
|
6885
|
-
|
|
6929
|
+
var _a, _b, _c, _d;
|
|
6930
|
+
let {
|
|
6886
6931
|
layoutType = "default",
|
|
6887
6932
|
clickedTabIndexId,
|
|
6888
6933
|
clickedTabIndexType = "product",
|
|
@@ -6911,6 +6956,7 @@ const handleSearchResponse = async (props) => {
|
|
|
6911
6956
|
instantSearchSettings
|
|
6912
6957
|
} = props;
|
|
6913
6958
|
let keyword = keywordProp;
|
|
6959
|
+
let collectionIdSelected = collectionId || (instantSearchSettings == null ? void 0 : instantSearchSettings.collections_all_id) || "";
|
|
6914
6960
|
const isResultForProduct = clickedTabIndexType === "product";
|
|
6915
6961
|
const isTypeCategoryHasPublished = ({ usePublishedFilter: usePublishedFilter2, type }) => Boolean(usePublishedFilter2 && type && ["collection", "page", "article"].includes(type));
|
|
6916
6962
|
const { separator: hierarchical_separator, hiddens: hierarchical_hiddens } = hierarchicalProductTypeSettings || {};
|
|
@@ -6931,6 +6977,11 @@ const handleSearchResponse = async (props) => {
|
|
|
6931
6977
|
containsFilter = `(${searchableAttributes.map((item) => `'${item}' CONTAINS ${JSON.stringify(keywordProp)}`).join(" OR ")})`;
|
|
6932
6978
|
keyword = "";
|
|
6933
6979
|
}
|
|
6980
|
+
let merchandisingSettings = null;
|
|
6981
|
+
if (collectionIdSelected && ((_d = instantSearchSettings == null ? void 0 : instantSearchSettings.have_merchandising_settings) == null ? void 0 : _d[collectionIdSelected])) {
|
|
6982
|
+
sort.push(`merchandising.${collectionIdSelected}.demote:asc`);
|
|
6983
|
+
merchandisingSettings = `merchandising.${collectionIdSelected}.hide != 1`;
|
|
6984
|
+
}
|
|
6934
6985
|
let response;
|
|
6935
6986
|
let filterProduct = createQueryFilter({
|
|
6936
6987
|
facets,
|
|
@@ -6954,7 +7005,8 @@ const handleSearchResponse = async (props) => {
|
|
|
6954
7005
|
(hiddenTags == null ? void 0 : hiddenTags.length) ? `'tags' NOT IN ${JSON.stringify(hiddenTags)}` : null,
|
|
6955
7006
|
collectionId ? `'collections.id' = '${collectionId}'` : null,
|
|
6956
7007
|
!showOutOfStock ? `'availability' IN ${JSON.stringify(["in stock"])}` : null,
|
|
6957
|
-
containsFilter
|
|
7008
|
+
containsFilter,
|
|
7009
|
+
merchandisingSettings
|
|
6958
7010
|
],
|
|
6959
7011
|
allowedFilterSlider,
|
|
6960
7012
|
hierarchicalFacetAliases,
|