@sentecacommerce-theme/lib 0.12.102 → 0.13.3

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.
Files changed (51) hide show
  1. package/dist/cjs/basket/api/mutations/index.js +14 -0
  2. package/dist/cjs/basket/api/mutations/useChangeGiftVariant.js +116 -0
  3. package/dist/cjs/basket/hooks/index.js +12 -0
  4. package/dist/cjs/basket/hooks/useChangeGiftVariant.js +16 -0
  5. package/dist/cjs/hooks/useLineItem/LineItemContext.js +86 -0
  6. package/dist/cjs/hooks/useLineItem/index.js +34 -12
  7. package/dist/cjs/hooks/useProduct/index.js +17 -276
  8. package/dist/cjs/hooks/useProduct/utils/index.js +44 -18
  9. package/dist/cjs/hooks/useProductVariants/index.js +334 -0
  10. package/dist/cjs/hooks/useProductVariants/types.js +3 -0
  11. package/dist/cjs/index.js +16 -4
  12. package/dist/cjs/listing/api/queries/useListingQuery.js +1 -0
  13. package/dist/cjs/listing/hooks/useListingBreadcrumbs.js +20 -8
  14. package/dist/cjs/listing/hooks/useListingCategories.js +2 -2
  15. package/dist/cjs/listing/hooks/useListingMeta.js +12 -10
  16. package/dist/cjs/listing/utils/buildCategoryQuery.js +22 -1
  17. package/dist/cjs/seo/components/TranslationsMeta/index.js +1 -0
  18. package/dist/cjs/utils/localStorage.js +7 -2
  19. package/dist/esm/basket/api/mutations/index.js +1 -0
  20. package/dist/esm/basket/api/mutations/useChangeGiftVariant.js +106 -0
  21. package/dist/esm/basket/hooks/index.js +1 -0
  22. package/dist/esm/basket/hooks/useChangeGiftVariant.js +3 -0
  23. package/dist/esm/hooks/useLineItem/LineItemContext.js +75 -0
  24. package/dist/esm/hooks/useLineItem/index.js +16 -12
  25. package/dist/esm/hooks/useProduct/index.js +18 -277
  26. package/dist/esm/hooks/useProduct/utils/index.js +44 -18
  27. package/dist/esm/hooks/useProductVariants/index.js +293 -0
  28. package/dist/esm/hooks/useProductVariants/types.js +1 -0
  29. package/dist/esm/index.js +1 -0
  30. package/dist/esm/listing/api/queries/useListingQuery.js +1 -0
  31. package/dist/esm/listing/hooks/useListingBreadcrumbs.js +15 -3
  32. package/dist/esm/listing/hooks/useListingCategories.js +2 -2
  33. package/dist/esm/listing/hooks/useListingMeta.js +12 -12
  34. package/dist/esm/listing/utils/buildCategoryQuery.js +22 -1
  35. package/dist/esm/seo/components/TranslationsMeta/index.js +1 -0
  36. package/dist/esm/utils/localStorage.js +7 -2
  37. package/dist/types/basket/api/mutations/index.d.ts +1 -0
  38. package/dist/types/basket/api/mutations/useChangeGiftVariant.d.ts +2 -0
  39. package/dist/types/basket/hooks/index.d.ts +1 -0
  40. package/dist/types/basket/hooks/useChangeGiftVariant.d.ts +2 -0
  41. package/dist/types/hooks/basket-hooks/useBasketLineItem/index.d.ts +1 -2
  42. package/dist/types/hooks/useLineItem/LineItemContext.d.ts +22 -0
  43. package/dist/types/hooks/useLineItem/index.d.ts +2 -2
  44. package/dist/types/hooks/useProduct/index.d.ts +2 -76
  45. package/dist/types/hooks/useProduct/utils/index.d.ts +6 -4
  46. package/dist/types/hooks/useProductVariants/index.d.ts +34 -0
  47. package/dist/types/hooks/useProductVariants/types.d.ts +79 -0
  48. package/dist/types/index.d.ts +1 -0
  49. package/dist/types/listing/hooks/useListingMeta.d.ts +4 -0
  50. package/dist/types/listing/types.d.ts +1 -0
  51. package/package.json +5 -5
@@ -0,0 +1,334 @@
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ exports.useProductVariants = void 0;
5
+ var _react = _interopRequireDefault(require("react"));
6
+ var _utils = require("../useProduct/utils");
7
+ var _types = _interopRequireWildcard(require("./types"));
8
+ Object.keys(_types).forEach(function(key) {
9
+ if (key === "default" || key === "__esModule") return;
10
+ if (key in exports && exports[key] === _types[key]) return;
11
+ Object.defineProperty(exports, key, {
12
+ enumerable: true,
13
+ get: function() {
14
+ return _types[key];
15
+ }
16
+ });
17
+ });
18
+ function _arrayLikeToArray(arr, len) {
19
+ if (len == null || len > arr.length) len = arr.length;
20
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
21
+ return arr2;
22
+ }
23
+ function _arrayWithHoles(arr) {
24
+ if (Array.isArray(arr)) return arr;
25
+ }
26
+ function _arrayWithoutHoles(arr) {
27
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
28
+ }
29
+ function _defineProperty(obj, key, value) {
30
+ if (key in obj) {
31
+ Object.defineProperty(obj, key, {
32
+ value: value,
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true
36
+ });
37
+ } else {
38
+ obj[key] = value;
39
+ }
40
+ return obj;
41
+ }
42
+ function _interopRequireDefault(obj) {
43
+ return obj && obj.__esModule ? obj : {
44
+ default: obj
45
+ };
46
+ }
47
+ function _interopRequireWildcard(obj) {
48
+ if (obj && obj.__esModule) {
49
+ return obj;
50
+ } else {
51
+ var newObj = {};
52
+ if (obj != null) {
53
+ for(var key in obj){
54
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
55
+ var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
56
+ if (desc.get || desc.set) {
57
+ Object.defineProperty(newObj, key, desc);
58
+ } else {
59
+ newObj[key] = obj[key];
60
+ }
61
+ }
62
+ }
63
+ }
64
+ newObj.default = obj;
65
+ return newObj;
66
+ }
67
+ }
68
+ function _iterableToArray(iter) {
69
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
70
+ }
71
+ function _iterableToArrayLimit(arr, i) {
72
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
73
+ if (_i == null) return;
74
+ var _arr = [];
75
+ var _n = true;
76
+ var _d = false;
77
+ var _s, _e;
78
+ try {
79
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
80
+ _arr.push(_s.value);
81
+ if (i && _arr.length === i) break;
82
+ }
83
+ } catch (err) {
84
+ _d = true;
85
+ _e = err;
86
+ } finally{
87
+ try {
88
+ if (!_n && _i["return"] != null) _i["return"]();
89
+ } finally{
90
+ if (_d) throw _e;
91
+ }
92
+ }
93
+ return _arr;
94
+ }
95
+ function _nonIterableRest() {
96
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
97
+ }
98
+ function _nonIterableSpread() {
99
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
100
+ }
101
+ function _objectSpread(target) {
102
+ for(var i = 1; i < arguments.length; i++){
103
+ var source = arguments[i] != null ? arguments[i] : {};
104
+ var ownKeys = Object.keys(source);
105
+ if (typeof Object.getOwnPropertySymbols === "function") {
106
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
107
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
108
+ }));
109
+ }
110
+ ownKeys.forEach(function(key) {
111
+ _defineProperty(target, key, source[key]);
112
+ });
113
+ }
114
+ return target;
115
+ }
116
+ function _slicedToArray(arr, i) {
117
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
118
+ }
119
+ function _toConsumableArray(arr) {
120
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
121
+ }
122
+ function _unsupportedIterableToArray(o, minLen) {
123
+ if (!o) return;
124
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
125
+ var n = Object.prototype.toString.call(o).slice(8, -1);
126
+ if (n === "Object" && o.constructor) n = o.constructor.name;
127
+ if (n === "Map" || n === "Set") return Array.from(n);
128
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
129
+ }
130
+ var useProductVariants = function(param) {
131
+ var product = param.product, defaultVariantId = param.defaultVariantId, _isLineItem = param.isLineItem, isLineItem = _isLineItem === void 0 ? false : _isLineItem;
132
+ var ref4 = _slicedToArray(_react.default.useState(getCombinationsAndAttributeRules), 2), ref1 = ref4[0], combinations = ref1.combinations, attributeRules = ref1.attributeRules, setCombinationsAndAttributeRules = ref4[1];
133
+ var ref2 = _slicedToArray(_react.default.useState(getVariantsWithInventory), 2), variants = ref2[0], setVariants = ref2[1];
134
+ var ref3 = _slicedToArray(_react.default.useState(getDefaultVariant), 2), selectedVariant = ref3[0], setSelectedVariant = ref3[1];
135
+ _react.default.useEffect(function() {
136
+ setVariants(getVariantsWithInventory());
137
+ }, [
138
+ product
139
+ ]);
140
+ _react.default.useMemo(function() {
141
+ if (Object.keys(variants).length) {
142
+ var data = getCombinationsAndAttributeRules();
143
+ setCombinationsAndAttributeRules(data);
144
+ }
145
+ }, [
146
+ variants
147
+ ]);
148
+ function getVariantsWithInventory() {
149
+ var ref9;
150
+ if (isLineItem) {
151
+ var innerProduct = JSON.parse(JSON.stringify(product));
152
+ delete innerProduct.variants;
153
+ product.variants.unshift(innerProduct);
154
+ }
155
+ var variantsWithInventory = product === null || product === void 0 ? void 0 : (ref9 = product.variants) === null || ref9 === void 0 ? void 0 : ref9.reduce(function(map, _, index, arr) {
156
+ var ref10, ref5, ref6, ref7, ref8;
157
+ var currentVariant = arr[index];
158
+ if (isLineItem && !Array.isArray((ref10 = currentVariant) === null || ref10 === void 0 ? void 0 : ref10.variantAttributes)) {
159
+ currentVariant.variantAttributes = (0, _utils).remapLineItemAttributes(currentVariant.variantAttributes);
160
+ }
161
+ var mappedAttributes = (0, _utils).createMappedAttributes(currentVariant, isLineItem);
162
+ var mappedOptions = (0, _utils).createMappedOptions(currentVariant === null || currentVariant === void 0 ? void 0 : currentVariant.availableOptions) || [];
163
+ var isAvailable = currentVariant === null || currentVariant === void 0 ? void 0 : (ref5 = currentVariant.inventorySnapshot) === null || ref5 === void 0 ? void 0 : ref5.canOrder;
164
+ var updatedVariant = _objectSpread({}, currentVariant, {
165
+ inventory: {
166
+ hasAvailableQuantity: (ref6 = currentVariant.inventorySnapshot) === null || ref6 === void 0 ? void 0 : ref6.canOrder,
167
+ availableQuantity: (ref7 = currentVariant.inventorySnapshot) === null || ref7 === void 0 ? void 0 : ref7.availableQuantity
168
+ },
169
+ isAvailable: isAvailable ? true : false,
170
+ quantity: isAvailable ? currentVariant === null || currentVariant === void 0 ? void 0 : (ref8 = currentVariant.inventorySnapshot) === null || ref8 === void 0 ? void 0 : ref8.availableQuantity : 0,
171
+ attributes: mappedAttributes,
172
+ options: mappedOptions,
173
+ selectedOptions: [],
174
+ labels: (0, _utils).createLabelsMap(currentVariant.labels),
175
+ getAttribute: function(rule) {
176
+ return getSelectedAttribute(rule, mappedAttributes);
177
+ },
178
+ getAttributeByKey: function(key) {
179
+ var ref;
180
+ return (ref = mappedAttributes.find(function(a) {
181
+ return a.name === key;
182
+ })) === null || ref === void 0 ? void 0 : ref.value;
183
+ },
184
+ getAvailabilityByStore: function() {
185
+ var ref;
186
+ return (0, _utils).processAvailabilityPerStore(currentVariant === null || currentVariant === void 0 ? void 0 : (ref = currentVariant.inventorySnapshot) === null || ref === void 0 ? void 0 : ref.availabilities);
187
+ }
188
+ });
189
+ map[isLineItem ? currentVariant.variantId : currentVariant._id] = updatedVariant;
190
+ return map;
191
+ }, {});
192
+ return variantsWithInventory || {};
193
+ }
194
+ var customFields = _react.default.useMemo(function() {
195
+ var mappedFields = (0, _utils).createCustomFieldsMap(product === null || product === void 0 ? void 0 : product.custom);
196
+ return mappedFields;
197
+ }, [
198
+ product === null || product === void 0 ? void 0 : product.custom
199
+ ]);
200
+ function getCombinationsAndAttributeRules() {
201
+ if (isLineItem && !(product === null || product === void 0 ? void 0 : product.attributeRules)) {
202
+ product.attributeRules = (0, _utils).remapLineItemAttributes(product === null || product === void 0 ? void 0 : product.attributes);
203
+ }
204
+ var mappedAttributeRules = (0, _utils).createAttributeRulesMap(product, isLineItem);
205
+ var attributesWithId = Object.keys(variants || {}).map(function(key) {
206
+ return {
207
+ variantId: isLineItem ? (variants === null || variants === void 0 ? void 0 : variants[key]).variantId : variants === null || variants === void 0 ? void 0 : variants[key]._id,
208
+ attributes: isLineItem && !Array.isArray(variants === null || variants === void 0 ? void 0 : variants[key].attributes) ? (0, _utils).remapLineItemAttributes(variants === null || variants === void 0 ? void 0 : variants[key].attributes) : variants === null || variants === void 0 ? void 0 : variants[key].attributes
209
+ };
210
+ });
211
+ var combinationsMap = (0, _utils).createCombinationsMap(Object.keys(mappedAttributeRules), attributesWithId);
212
+ (0, _utils).assignCombinationsToAttributeRules(mappedAttributeRules, combinationsMap);
213
+ return {
214
+ combinations: combinationsMap,
215
+ attributeRules: mappedAttributeRules
216
+ };
217
+ }
218
+ function getDefaultVariant() {
219
+ if (!defaultVariantId) return null;
220
+ return variants[defaultVariantId];
221
+ }
222
+ function selectVariantById(id) {
223
+ setSelectedVariant(variants[id]);
224
+ }
225
+ function selectVariantByCombination(key, value) {
226
+ // Take collapseKey for SD
227
+ var split = value.split(':');
228
+ if (split[0] === 'collapseKey') {
229
+ var id = Object.keys(variants).find(function(el) {
230
+ var ref;
231
+ return variants[el].collapseKey === split[1] && ((ref = variants[el].attributes.find(function(attr) {
232
+ return attr.name === 'size';
233
+ })) === null || ref === void 0 ? void 0 : ref.value) === key;
234
+ });
235
+ return setSelectedVariant(variants[id]);
236
+ }
237
+ var id1 = combinations[key].params[value];
238
+ setSelectedVariant(variants[id1]);
239
+ }
240
+ function selectVariantByAttribute(key) {
241
+ var ref;
242
+ // Get by collapseKey for SD
243
+ var split = key.split(':');
244
+ if (split[0] === 'collapseKey') {
245
+ var id = Object.keys(variants).find(function(el) {
246
+ return variants[el].collapseKey === split[1];
247
+ });
248
+ return setSelectedVariant(variants[id]);
249
+ }
250
+ var id2 = (ref = combinations[key]) === null || ref === void 0 ? void 0 : ref.value;
251
+ setSelectedVariant(variants[id2]);
252
+ }
253
+ function getVariantByCombination(key, value) {
254
+ var ref11;
255
+ var split = value === null || value === void 0 ? void 0 : value.split(':');
256
+ if ((split === null || split === void 0 ? void 0 : split[0]) === 'collapseKey') {
257
+ var id = Object.keys(variants).find(function(el) {
258
+ var ref;
259
+ return variants[el].collapseKey === (split === null || split === void 0 ? void 0 : split[1]) && ((ref = variants[el].attributes.find(function(attr) {
260
+ return attr.name === 'size';
261
+ })) === null || ref === void 0 ? void 0 : ref.value) === key;
262
+ });
263
+ return variants[id];
264
+ }
265
+ var id3 = (ref11 = combinations[key]) === null || ref11 === void 0 ? void 0 : ref11.params[value];
266
+ return variants === null || variants === void 0 ? void 0 : variants[id3];
267
+ }
268
+ function getSelectedAttribute(rule, attributes) {
269
+ var ref;
270
+ var attributeRule = (ref = attributeRules[rule]) === null || ref === void 0 ? void 0 : ref.values;
271
+ var result;
272
+ attributes.forEach(function(currentKey) {
273
+ var found = attributeRule === null || attributeRule === void 0 ? void 0 : attributeRule[currentKey.value];
274
+ if (found) result = _objectSpread({
275
+ id: currentKey.value,
276
+ name: rule
277
+ }, found);
278
+ });
279
+ return result;
280
+ }
281
+ function getVariantById(id) {
282
+ return variants === null || variants === void 0 ? void 0 : variants[id];
283
+ }
284
+ function getVariantByAttribute(key) {
285
+ var ref;
286
+ var id = (ref = combinations[key]) === null || ref === void 0 ? void 0 : ref.value;
287
+ return variants === null || variants === void 0 ? void 0 : variants[id];
288
+ }
289
+ function getCombinationsForAttributeRule(key, id) {
290
+ var ref, ref12;
291
+ var result = attributeRules === null || attributeRules === void 0 ? void 0 : (ref = attributeRules[key]) === null || ref === void 0 ? void 0 : (ref12 = ref.values) === null || ref12 === void 0 ? void 0 : ref12[id];
292
+ return result;
293
+ }
294
+ function selectVariantOptions(definitionKey, optionKey) {
295
+ if (selectedVariant) {
296
+ var newSelectedVariant = _objectSpread({}, selectedVariant);
297
+ newSelectedVariant.selectedOptions = newSelectedVariant.selectedOptions.filter(function(opt) {
298
+ return opt.definitionKey !== definitionKey;
299
+ });
300
+ newSelectedVariant.selectedOptions = _toConsumableArray(newSelectedVariant.selectedOptions).concat([
301
+ {
302
+ definitionKey: definitionKey,
303
+ optionKey: optionKey
304
+ },
305
+ ]);
306
+ newSelectedVariant.mappedSelectedOptions = newSelectedVariant.selectedOptions.map(function(option) {
307
+ return (0, _utils).createSelectedOption2(newSelectedVariant.options, option);
308
+ });
309
+ setSelectedVariant(newSelectedVariant);
310
+ }
311
+ }
312
+ function getCustomFieldValue(field) {
313
+ return customFields === null || customFields === void 0 ? void 0 : customFields[field];
314
+ }
315
+ return {
316
+ combinations: combinations,
317
+ attributeRules: attributeRules,
318
+ variants: variants,
319
+ selectedVariant: selectedVariant,
320
+ setSelectedVariant: setSelectedVariant,
321
+ customFields: customFields,
322
+ getVariantByAttribute: getVariantByAttribute,
323
+ getVariantById: getVariantById,
324
+ getCombinationsAndAttributeRules: getCombinationsAndAttributeRules,
325
+ getCombinationsForAttributeRule: getCombinationsForAttributeRule,
326
+ getVariantByCombination: getVariantByCombination,
327
+ getCustomFieldValue: getCustomFieldValue,
328
+ selectVariantByAttribute: selectVariantByAttribute,
329
+ selectVariantByCombination: selectVariantByCombination,
330
+ selectVariantOptions: selectVariantOptions,
331
+ selectVariantById: selectVariantById
332
+ };
333
+ };
334
+ exports.useProductVariants = useProductVariants;
@@ -0,0 +1,3 @@
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
package/dist/cjs/index.js CHANGED
@@ -1046,6 +1046,18 @@ Object.keys(_useLocalRating).forEach(function(key) {
1046
1046
  }
1047
1047
  });
1048
1048
  });
1049
+ var _types = _interopRequireWildcard(require("./hooks/useProductVariants/types"));
1050
+ Object.keys(_types).forEach(function(key) {
1051
+ if (key === "default" || key === "__esModule") return;
1052
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
1053
+ if (key in exports && exports[key] === _types[key]) return;
1054
+ Object.defineProperty(exports, key, {
1055
+ enumerable: true,
1056
+ get: function() {
1057
+ return _types[key];
1058
+ }
1059
+ });
1060
+ });
1049
1061
  var _utils1 = _interopRequireWildcard(require("./utils"));
1050
1062
  Object.keys(_utils1).forEach(function(key) {
1051
1063
  if (key === "default" || key === "__esModule") return;
@@ -1058,15 +1070,15 @@ Object.keys(_utils1).forEach(function(key) {
1058
1070
  }
1059
1071
  });
1060
1072
  });
1061
- var _types = _interopRequireWildcard(require("./types"));
1062
- Object.keys(_types).forEach(function(key) {
1073
+ var _types1 = _interopRequireWildcard(require("./types"));
1074
+ Object.keys(_types1).forEach(function(key) {
1063
1075
  if (key === "default" || key === "__esModule") return;
1064
1076
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
1065
- if (key in exports && exports[key] === _types[key]) return;
1077
+ if (key in exports && exports[key] === _types1[key]) return;
1066
1078
  Object.defineProperty(exports, key, {
1067
1079
  enumerable: true,
1068
1080
  get: function() {
1069
- return _types[key];
1081
+ return _types1[key];
1070
1082
  }
1071
1083
  });
1072
1084
  });
@@ -154,6 +154,7 @@ var useListingQuery = function() {
154
154
  postFilter: postFilter,
155
155
  offset: offset,
156
156
  config: config.meta,
157
+ includeVariants: config.includeVariants,
157
158
  slug: aliasedSlug
158
159
  });
159
160
  case 2:
@@ -5,11 +5,11 @@ exports.useListingBreadcrumbs = void 0;
5
5
  var _react = _interopRequireDefault(require("react"));
6
6
  var _router = require("next/router");
7
7
  var _api = require("../api");
8
- var _ = require("./");
9
- var _index = require("../../index");
8
+ var _index = require("./index");
9
+ var _index1 = require("../../index");
10
10
  var _typeToSuffix = require("../../utils/typeToSuffix");
11
11
  var _getTranslatableField = require("../../utils/getTranslatableField");
12
- var _1 = require("..");
12
+ var _ = require("..");
13
13
  function _arrayLikeToArray(arr, len) {
14
14
  if (len == null || len > arr.length) len = arr.length;
15
15
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
@@ -42,12 +42,15 @@ function _unsupportedIterableToArray(o, minLen) {
42
42
  }
43
43
  var _instance;
44
44
  var useListingBreadcrumbs = function() {
45
- var ref1 = (0, _api).usePredicate(), data = ref1.data, isLoading = ref1.isLoading;
46
- var config = (0, _).useListingConfig();
45
+ var ref3 = (0, _api).usePredicate(), data = ref3.data, isLoading = ref3.isLoading;
46
+ var config = (0, _index).useListingConfig();
47
47
  var router = (0, _router).useRouter();
48
- var slug = (0, _index).useListingAlias(config.meta).slug;
48
+ var slug = (0, _index1).useListingAlias(config.meta).slug;
49
+ var ref1 = (0, _index).useListingCategories(), categoriesData = ref1.data;
50
+ var categoryName = (0, _index).getCategoryName(router, categoriesData);
51
+ var categoryId = (0, _index).getFilterByType('category', router);
49
52
  var result = _react.default.useMemo(function() {
50
- if (config.type === _1.ListingTypesEnum.AttrPage) {
53
+ if (config.type === _.ListingTypesEnum.AttrPage) {
51
54
  var ref;
52
55
  return [
53
56
  {
@@ -66,7 +69,16 @@ var useListingBreadcrumbs = function() {
66
69
  },
67
70
  ];
68
71
  }
69
- return createCatalogBreadcrumb(data, config.type, router);
72
+ var breadcrumbData = createCatalogBreadcrumb(data, config.type, router);
73
+ if (config.type === _.ListingTypesEnum.View || config.type === _.ListingTypesEnum.Brand) {
74
+ var ref2;
75
+ breadcrumbData.push({
76
+ name: categoryName || '',
77
+ id: categoryId,
78
+ link: processLink((ref2 = data) === null || ref2 === void 0 ? void 0 : ref2.slug, config.type, router.query.slug) + applyFilters(router)
79
+ });
80
+ }
81
+ return breadcrumbData;
70
82
  }, [
71
83
  data,
72
84
  config.type,
@@ -103,14 +103,14 @@ function generateUrl(current, router, slug, config) {
103
103
  res = "/".concat(router.query.slug, "/").concat((0, _utils).getTranslatableField(current.meta.slug), "/").concat(suffix);
104
104
  }
105
105
  if (pageType === _types.ListingTypesEnum.View) {
106
- res = "/".concat(router.query.slug, "/").concat((0, _utils).getTranslatableField(current.meta.slug), "/").concat(suffix);
106
+ res = "/".concat(router.query.slug, "/").concat(suffix);
107
107
  }
108
108
  if (pageType === _types.ListingTypesEnum.Search) {
109
109
  var _q;
110
110
  res = "/".concat((0, _utils).getTranslatableField(current.meta.slug), "/c?search=").concat((_q = router.query.q) !== null && _q !== void 0 ? _q : router.query.search);
111
111
  }
112
112
  var filter = router.query.filter;
113
- if (suffix === 'b') {
113
+ if (suffix === 'b' || suffix === 'v') {
114
114
  if (filter) {
115
115
  if (Array.isArray(filter)) {
116
116
  filter = _toConsumableArray(filter);
@@ -1,6 +1,8 @@
1
1
  Object.defineProperty(exports, "__esModule", {
2
2
  value: true
3
3
  });
4
+ exports.getFilterByType = getFilterByType;
5
+ exports.getCategoryName = getCategoryName;
4
6
  exports.useListingMeta = void 0;
5
7
  var _react = _interopRequireDefault(require("react"));
6
8
  var _api = require("../api");
@@ -116,7 +118,7 @@ var useListingMeta = function() {
116
118
  };
117
119
  exports.useListingMeta = useListingMeta;
118
120
  function processDisplayName(slug, config, name, breadcrumb, router, aggData, categoriesData) {
119
- var ref, ref5;
121
+ var ref, ref5, ref6;
120
122
  var listingName = (0, _utils).getTranslatableField(name);
121
123
  var brandName = getBrandName(router, aggData);
122
124
  var categoryName = getCategoryName(router, categoriesData);
@@ -130,7 +132,7 @@ function processDisplayName(slug, config, name, breadcrumb, router, aggData, cat
130
132
  defaultName: listingName,
131
133
  attribute: (ref = config.titleAliases) === null || ref === void 0 ? void 0 : ref[slug],
132
134
  childAttribute: (0, _utils).getTranslatableField(breadcrumb === null || breadcrumb === void 0 ? void 0 : breadcrumb.label),
133
- search: router === null || router === void 0 ? void 0 : (ref5 = router.query) === null || ref5 === void 0 ? void 0 : ref5.search,
135
+ search: (router === null || router === void 0 ? void 0 : (ref5 = router.query) === null || ref5 === void 0 ? void 0 : ref5.q) || (router === null || router === void 0 ? void 0 : (ref6 = router.query) === null || ref6 === void 0 ? void 0 : ref6.search),
134
136
  isWithAttribute: Boolean(router === null || router === void 0 ? void 0 : router.query.cat)
135
137
  });
136
138
  return title || listingName;
@@ -138,35 +140,35 @@ function processDisplayName(slug, config, name, breadcrumb, router, aggData, cat
138
140
  function getFilterByType(filterType, router) {
139
141
  var filterId = '';
140
142
  if (Array.isArray(router === null || router === void 0 ? void 0 : router.query.filter)) {
141
- var ref, ref6;
143
+ var ref, ref7;
142
144
  var filters = (ref = router === null || router === void 0 ? void 0 : router.query.filter) === null || ref === void 0 ? void 0 : ref.filter(function(x) {
143
145
  return x === null || x === void 0 ? void 0 : x.includes(filterType);
144
146
  });
145
147
  if ((filters === null || filters === void 0 ? void 0 : filters.length) && filters.length > 1) {
146
148
  return '';
147
149
  }
148
- var filterTerm = (ref6 = /\d+/.exec((filters === null || filters === void 0 ? void 0 : filters[0]) || '')) === null || ref6 === void 0 ? void 0 : ref6[0];
150
+ var filterTerm = (ref7 = /\d+/.exec((filters === null || filters === void 0 ? void 0 : filters[0]) || '')) === null || ref7 === void 0 ? void 0 : ref7[0];
149
151
  if (!filterTerm) return '';
150
152
  filterId = filterTerm;
151
153
  } else {
152
- var ref7, ref8, ref9;
153
- var isFiltered = router === null || router === void 0 ? void 0 : (ref7 = router.query) === null || ref7 === void 0 ? void 0 : (ref8 = ref7.filter) === null || ref8 === void 0 ? void 0 : ref8.includes(filterType);
154
+ var ref8, ref9, ref10;
155
+ var isFiltered = router === null || router === void 0 ? void 0 : (ref8 = router.query) === null || ref8 === void 0 ? void 0 : (ref9 = ref8.filter) === null || ref9 === void 0 ? void 0 : ref9.includes(filterType);
154
156
  if (!isFiltered) {
155
157
  return '';
156
158
  }
157
- filterId = (ref9 = /(\w+)-(\d+)/.exec(router === null || router === void 0 ? void 0 : router.query.filter)) === null || ref9 === void 0 ? void 0 : ref9[0];
159
+ filterId = (ref10 = /(\w+)-(\d+)/.exec(router === null || router === void 0 ? void 0 : router.query.filter)) === null || ref10 === void 0 ? void 0 : ref10[0];
158
160
  }
159
161
  return filterId;
160
162
  }
161
163
  function getBrandName(router, filtersData) {
162
- var ref, ref10, ref11;
164
+ var ref, ref11, ref12;
163
165
  var brandId = getFilterByType('brand', router);
164
166
  var brand = (ref = filtersData === null || filtersData === void 0 ? void 0 : filtersData.find(function(x) {
165
167
  return x.name === 'Brands';
166
- })) === null || ref === void 0 ? void 0 : (ref10 = ref.items) === null || ref10 === void 0 ? void 0 : ref10.find(function(x) {
168
+ })) === null || ref === void 0 ? void 0 : (ref11 = ref.items) === null || ref11 === void 0 ? void 0 : ref11.find(function(x) {
167
169
  return x.data.key === brandId;
168
170
  });
169
- return (0, _utils).getTranslatableField(brand === null || brand === void 0 ? void 0 : (ref11 = brand.meta) === null || ref11 === void 0 ? void 0 : ref11.name);
171
+ return (0, _utils).getTranslatableField(brand === null || brand === void 0 ? void 0 : (ref12 = brand.meta) === null || ref12 === void 0 ? void 0 : ref12.name);
170
172
  }
171
173
  function getCategoryName(router, categories) {
172
174
  var categoryId = getFilterByType('category', router);
@@ -64,7 +64,7 @@ var buildCategoryQuery = function(param) {
64
64
  filter += (ref = config === null || config === void 0 ? void 0 : config.filterExtension) !== null && ref !== void 0 ? ref : '';
65
65
  }
66
66
  if (postFilter) {
67
- if (router.query.cat) filter += '&';
67
+ if (filter) filter += '&';
68
68
  filter += postFilter;
69
69
  }
70
70
  break;
@@ -81,6 +81,14 @@ var buildCategoryQuery = function(param) {
81
81
  filter += "text;eq;\"".concat(searchQuery, "\"");
82
82
  if (postFilter) filter += "&".concat(postFilter);
83
83
  break;
84
+ case _index.ListingTypesEnum.View:
85
+ filter += applyViewsPostFilter({
86
+ postFilter: postFilter
87
+ });
88
+ if (config === null || config === void 0 ? void 0 : config.filterExtension) {
89
+ filter += filter ? "&".concat(config === null || config === void 0 ? void 0 : config.filterExtension) : config === null || config === void 0 ? void 0 : config.filterExtension;
90
+ }
91
+ break;
84
92
  default:
85
93
  return "".concat((config === null || config === void 0 ? void 0 : config.filterExtension) + "".concat(postFilter !== null && postFilter !== void 0 ? postFilter : ''));
86
94
  }
@@ -113,3 +121,16 @@ var applyBrandsPostFilter = function(param) {
113
121
  }
114
122
  return '';
115
123
  };
124
+ var applyViewsPostFilter = function(param) {
125
+ var postFilter = param.postFilter;
126
+ if (postFilter) {
127
+ var filtersArr = postFilter.split('&');
128
+ var filters = filtersArr.reduce(function(res, val, i) {
129
+ if (val.includes('category')) return res;
130
+ if (!res) return res + "".concat(val);
131
+ return res += "&".concat(val);
132
+ }, '');
133
+ return "".concat(filters);
134
+ }
135
+ return '';
136
+ };
@@ -31,6 +31,7 @@ var TranslationsMeta = function() {
31
31
  var defaultTranslation = translationsMap[defaultLocale];
32
32
  var isError = router.route === '/404' || router.route === '/_error';
33
33
  if (isError) return null;
34
+ if ((allLocales === null || allLocales === void 0 ? void 0 : allLocales.length) < 2) return null;
34
35
  var domain = defaultTranslation === null || defaultTranslation === void 0 ? void 0 : defaultTranslation.domain;
35
36
  return(/*#__PURE__*/ _react.default.createElement(_head.default, null, allLocales === null || allLocales === void 0 ? void 0 : allLocales.map(function(locale) {
36
37
  var translation = translationsMap === null || translationsMap === void 0 ? void 0 : translationsMap[locale];
@@ -4,12 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  exports.writeToLocalStorage = exports.readFromLocalStorage = void 0;
5
5
  var readFromLocalStorage = function(key) {
6
6
  if (typeof window !== 'undefined') {
7
- return JSON.parse(localStorage.getItem(key));
7
+ try {
8
+ return JSON.parse(localStorage.getItem(key));
9
+ } catch (e) {
10
+ console.log(e);
11
+ return null;
12
+ }
8
13
  }
9
14
  };
10
15
  exports.readFromLocalStorage = readFromLocalStorage;
11
16
  var writeToLocalStorage = function(key, data) {
12
- if (typeof window !== 'undefined') {
17
+ if (typeof window !== 'undefined' && data !== undefined) {
13
18
  localStorage.setItem(key, JSON.stringify(data));
14
19
  }
15
20
  };
@@ -1 +1,2 @@
1
1
  export * from './useReplaceBasketMutation';
2
+ export * from './useChangeGiftVariant';