@sledge-app/react-instant-search 1.0.43 → 1.0.44

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.
@@ -159,6 +159,7 @@ const OBJECT_DATA_STRING_KEY = {
159
159
  CURRENT_PAGE: "{{ current_page }}",
160
160
  TOTAL_PAGE: "{{ total_page }}",
161
161
  TOTAL_RESULT: "{{ total_result }}",
162
+ COLLECTION_ID: "{{ collection_id }}",
162
163
  COLLECTION_NAME: "{{ collection_name }}",
163
164
  TOTAL_WISHLIST: "{{ total_wishlist }}",
164
165
  ACCEPTED_FILETYPE_MEDIA: "{{ accepted_filetype_media }}",
@@ -4030,6 +4031,7 @@ const SearchResultWidget = (props) => {
4030
4031
  );
4031
4032
  };
4032
4033
  const handleSettings = async (LOCAL_STORAGE_INSTANT_SEARCH_SETTING) => {
4034
+ var _a2;
4033
4035
  setIsLoadingSetting(true);
4034
4036
  let response;
4035
4037
  let getFirstIndex;
@@ -4038,13 +4040,26 @@ const SearchResultWidget = (props) => {
4038
4040
  return;
4039
4041
  const { allowed_sorts, default_sort, filters, index_product, tabs, hidden_tags, display, colors, show_out_of_stock, languages, hierarchical_product_type } = response;
4040
4042
  const { limit } = (display == null ? void 0 : display.search) || {};
4041
- setAllowedSorts((allowed_sorts == null ? void 0 : allowed_sorts.length) ? allowed_sorts : []);
4043
+ let valueAllowedSorts = (allowed_sorts == null ? void 0 : allowed_sorts.length) ? collectionId ? allowed_sorts.map((allowed_sort) => {
4044
+ const { value, ...other_allowed_sort } = allowed_sort;
4045
+ return {
4046
+ ...other_allowed_sort,
4047
+ value: String(value).replaceAll(OBJECT_DATA_STRING_KEY.COLLECTION_ID, String(collectionId))
4048
+ };
4049
+ }) : allowed_sorts.filter((allowed_sort) => {
4050
+ const { value } = allowed_sort;
4051
+ if (!String(value).includes(OBJECT_DATA_STRING_KEY.COLLECTION_ID))
4052
+ return allowed_sort;
4053
+ }) : [];
4054
+ setAllowedSorts(valueAllowedSorts);
4042
4055
  setAllowedFilters((filters == null ? void 0 : filters.length) ? filters : []);
4043
4056
  setIndexProduct(index_product);
4044
4057
  setHiddenTags(hidden_tags);
4045
4058
  setDisplaySettings(display);
4046
4059
  setColorSwatches(colors);
4047
- setDefaultSort(default_sort);
4060
+ setDefaultSort(
4061
+ collectionId ? String(default_sort).replaceAll(OBJECT_DATA_STRING_KEY.COLLECTION_ID, String(collectionId)) : String(default_sort).includes(OBJECT_DATA_STRING_KEY.COLLECTION_ID) ? (_a2 = valueAllowedSorts[0]) == null ? void 0 : _a2.value : default_sort
4062
+ );
4048
4063
  setDefaultLimit((localStorage == null ? void 0 : localStorage.getItem(LOCAL_STORAGE_KEY.LIMIT_PRODUCT)) || limit);
4049
4064
  setShowOutOfStock(show_out_of_stock);
4050
4065
  setLanguageSettings(languages);