@sentecacommerce-theme/lib 0.12.97 → 0.12.101

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.
@@ -10,6 +10,7 @@ var _utils = require("../../utils");
10
10
  var _getSDKConfig = require("../getSDKConfig");
11
11
  var _utils1 = require("./utils");
12
12
  var _promoCode = require("../../api.v2/core/misc/promo-code");
13
+ var _ = require("../..");
13
14
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
14
15
  try {
15
16
  var info = gen[key](arg);
@@ -122,6 +123,7 @@ var MyCartApiFactory = function() {
122
123
  }(),
123
124
  useGet: function() {
124
125
  var queryCache = (0, _reactQuery).useQueryCache();
126
+ var isLoading = (0, _).useIsAuthenticated().isLoading;
125
127
  return (0, _reactQuery).useQuery(myCartCacheKeys.useGet, _asyncToGenerator(_regeneratorRuntime.default.mark(function _callee() {
126
128
  var data;
127
129
  return _regeneratorRuntime.default.wrap(function _callee$(_ctx) {
@@ -140,12 +142,14 @@ var MyCartApiFactory = function() {
140
142
  }
141
143
  }, _callee);
142
144
  })), {
145
+ enabled: !isLoading,
143
146
  retry: false,
144
- refetchOnMount: false,
147
+ refetchOnMount: true,
145
148
  refetchOnWindowFocus: false
146
149
  });
147
150
  },
148
151
  useGetCompact: function() {
152
+ var isLoading = (0, _).useIsAuthenticated().isLoading;
149
153
  return (0, _reactQuery).useQuery(myCartCacheKeys.useGetCompact, _asyncToGenerator(_regeneratorRuntime.default.mark(function _callee() {
150
154
  var compactBasket;
151
155
  return _regeneratorRuntime.default.wrap(function _callee$(_ctx) {
@@ -158,7 +162,9 @@ var MyCartApiFactory = function() {
158
162
  return _ctx.stop();
159
163
  }
160
164
  }, _callee);
161
- })));
165
+ })), {
166
+ enabled: !isLoading
167
+ });
162
168
  },
163
169
  useIsExisting: function(productId, variantId, collapseKey) {
164
170
  return (0, _reactQuery).useQuery([
@@ -70,7 +70,7 @@ var useAvailability = function(param) {
70
70
  setStatus(ProductQuantityStatusEnum.OutOfStock);
71
71
  return;
72
72
  }
73
- if ((quantity !== null && quantity !== void 0 ? quantity : 0) < (quantityInBasket || 1)) {
73
+ if (quantity - (quantityInBasket || 0) < 1) {
74
74
  setStatus(ProductQuantityStatusEnum.MaxQuantityReached);
75
75
  return;
76
76
  }
@@ -104,40 +104,40 @@ function _unsupportedIterableToArray(o, minLen) {
104
104
  var ProductStateContext = /*#__PURE__*/ _react.default.createContext(undefined);
105
105
  var CountDispatchContext = /*#__PURE__*/ _react.default.createContext(undefined);
106
106
  function ProductProvider(param) {
107
- var product = param.product, children = param.children, defaultVariantId = param.defaultVariantId;
108
- var ref36 = _slicedToArray(_react.default.useState(false), 2), mounted = ref36[0], setMounted = ref36[1];
107
+ var product = param.product, children = param.children, defaultVariantId = param.defaultVariantId, _includeBrandInName = param.includeBrandInName, includeBrandInName = _includeBrandInName === void 0 ? false : _includeBrandInName;
108
+ var ref42 = _slicedToArray(_react.default.useState(false), 2), mounted = ref42[0], setMounted = ref42[1];
109
109
  var ref1 = _slicedToArray(_react.default.useState(getCombinationsAndAttributeRules), 2), ref2 = ref1[0], combinations = ref2.combinations, attributeRules = ref2.attributeRules, setCombinationsAndAttributeRules = ref1[1];
110
110
  var ref3 = _slicedToArray(_react.default.useState(getVariantsWithInventory), 2), variants = ref3[0], setVariants = ref3[1];
111
111
  var ref4 = _slicedToArray(_react.default.useState(getDefaultVariant), 2), selectedVariant = ref4[0], setSelectedVariant = ref4[1];
112
112
  var metaData = _react.default.useMemo(function() {
113
- var ref, ref5, ref6, ref7, ref8, ref9, ref10, ref11, ref12, ref13, ref14, ref15, ref16, ref17, ref18, ref19, ref20, ref21, ref22, ref23, ref24, ref25, ref26, ref27, ref28, ref29, ref30, ref31, ref32, ref33, ref34, ref35;
113
+ var ref, ref5, ref6, ref7, ref8, ref9, ref10, ref11, ref12, ref13, ref14, ref15, ref16, ref17, ref18, ref19, ref20, ref21, ref22, ref23, ref24, ref25, ref26, ref27, ref28, ref29, ref30, ref31, ref32, ref33, ref34, ref35, ref36, ref37, ref38, ref39, ref40, ref41;
114
114
  var rootCategory = product === null || product === void 0 ? void 0 : (ref = product.categories) === null || ref === void 0 ? void 0 : ref[0];
115
115
  var rootCategoryId = rootCategory === null || rootCategory === void 0 ? void 0 : rootCategory.resourceId;
116
116
  var metaObj = {
117
117
  _id: product === null || product === void 0 ? void 0 : product._id,
118
- name: (0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.name),
118
+ name: includeBrandInName && (product === null || product === void 0 ? void 0 : (ref5 = product.brands) === null || ref5 === void 0 ? void 0 : (ref6 = ref5[0]) === null || ref6 === void 0 ? void 0 : (ref7 = ref6.resource) === null || ref7 === void 0 ? void 0 : ref7.name) ? "".concat((0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (ref8 = product.brands) === null || ref8 === void 0 ? void 0 : (ref9 = ref8[0]) === null || ref9 === void 0 ? void 0 : (ref10 = ref9.resource) === null || ref10 === void 0 ? void 0 : ref10.name), " ").concat((0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.name)) : (0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.name),
119
119
  slug: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.slug),
120
120
  description: (0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.description) || (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.description),
121
121
  shortDescription: (0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.metaDescription) || (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.metaDescription),
122
122
  brand: {
123
- _id: product === null || product === void 0 ? void 0 : (ref5 = product.brands) === null || ref5 === void 0 ? void 0 : (ref6 = ref5[0]) === null || ref6 === void 0 ? void 0 : ref6.resourceId,
124
- name: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (ref7 = product.brands) === null || ref7 === void 0 ? void 0 : (ref8 = ref7[0]) === null || ref8 === void 0 ? void 0 : (ref9 = ref8.resource) === null || ref9 === void 0 ? void 0 : ref9.name),
125
- slug: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (ref10 = product.brands) === null || ref10 === void 0 ? void 0 : (ref11 = ref10[0]) === null || ref11 === void 0 ? void 0 : (ref12 = ref11.resource) === null || ref12 === void 0 ? void 0 : ref12.slug),
126
- logo: product === null || product === void 0 ? void 0 : (ref13 = product.brands) === null || ref13 === void 0 ? void 0 : (ref14 = ref13[0]) === null || ref14 === void 0 ? void 0 : (ref15 = ref14.resource) === null || ref15 === void 0 ? void 0 : (ref16 = ref15.assets) === null || ref16 === void 0 ? void 0 : (ref17 = ref16[0]) === null || ref17 === void 0 ? void 0 : (ref18 = ref17.sources) === null || ref18 === void 0 ? void 0 : (ref19 = ref18[0]) === null || ref19 === void 0 ? void 0 : ref19.url
123
+ _id: product === null || product === void 0 ? void 0 : (ref11 = product.brands) === null || ref11 === void 0 ? void 0 : (ref12 = ref11[0]) === null || ref12 === void 0 ? void 0 : ref12.resourceId,
124
+ name: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (ref13 = product.brands) === null || ref13 === void 0 ? void 0 : (ref14 = ref13[0]) === null || ref14 === void 0 ? void 0 : (ref15 = ref14.resource) === null || ref15 === void 0 ? void 0 : ref15.name),
125
+ slug: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (ref16 = product.brands) === null || ref16 === void 0 ? void 0 : (ref17 = ref16[0]) === null || ref17 === void 0 ? void 0 : (ref18 = ref17.resource) === null || ref18 === void 0 ? void 0 : ref18.slug),
126
+ logo: product === null || product === void 0 ? void 0 : (ref19 = product.brands) === null || ref19 === void 0 ? void 0 : (ref20 = ref19[0]) === null || ref20 === void 0 ? void 0 : (ref21 = ref20.resource) === null || ref21 === void 0 ? void 0 : (ref22 = ref21.assets) === null || ref22 === void 0 ? void 0 : (ref23 = ref22[0]) === null || ref23 === void 0 ? void 0 : (ref24 = ref23.sources) === null || ref24 === void 0 ? void 0 : (ref25 = ref24[0]) === null || ref25 === void 0 ? void 0 : ref25.url
127
127
  },
128
128
  category: {
129
- _id: product === null || product === void 0 ? void 0 : (ref21 = product.categories) === null || ref21 === void 0 ? void 0 : (ref22 = ref21[(product === null || product === void 0 ? void 0 : (ref20 = product.categories) === null || ref20 === void 0 ? void 0 : ref20.length) - 1]) === null || ref22 === void 0 ? void 0 : ref22.resourceId,
130
- name: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (ref24 = product.categories) === null || ref24 === void 0 ? void 0 : (ref25 = ref24[(product === null || product === void 0 ? void 0 : (ref23 = product.categories) === null || ref23 === void 0 ? void 0 : ref23.length) - 1]) === null || ref25 === void 0 ? void 0 : (ref26 = ref25.resource) === null || ref26 === void 0 ? void 0 : ref26.name),
131
- slug: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (ref28 = product.categories) === null || ref28 === void 0 ? void 0 : (ref29 = ref28[(product === null || product === void 0 ? void 0 : (ref27 = product.categories) === null || ref27 === void 0 ? void 0 : ref27.length) - 1]) === null || ref29 === void 0 ? void 0 : (ref30 = ref29.resource) === null || ref30 === void 0 ? void 0 : ref30.slug)
129
+ _id: product === null || product === void 0 ? void 0 : (ref27 = product.categories) === null || ref27 === void 0 ? void 0 : (ref28 = ref27[(product === null || product === void 0 ? void 0 : (ref26 = product.categories) === null || ref26 === void 0 ? void 0 : ref26.length) - 1]) === null || ref28 === void 0 ? void 0 : ref28.resourceId,
130
+ name: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (ref30 = product.categories) === null || ref30 === void 0 ? void 0 : (ref31 = ref30[(product === null || product === void 0 ? void 0 : (ref29 = product.categories) === null || ref29 === void 0 ? void 0 : ref29.length) - 1]) === null || ref31 === void 0 ? void 0 : (ref32 = ref31.resource) === null || ref32 === void 0 ? void 0 : ref32.name),
131
+ slug: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (ref34 = product.categories) === null || ref34 === void 0 ? void 0 : (ref35 = ref34[(product === null || product === void 0 ? void 0 : (ref33 = product.categories) === null || ref33 === void 0 ? void 0 : ref33.length) - 1]) === null || ref35 === void 0 ? void 0 : (ref36 = ref35.resource) === null || ref36 === void 0 ? void 0 : ref36.slug)
132
132
  },
133
133
  rootCategory: {
134
134
  _id: rootCategoryId,
135
- name: (0, _).getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (ref31 = rootCategory.resource) === null || ref31 === void 0 ? void 0 : ref31.name),
136
- slug: (0, _).getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (ref32 = rootCategory.resource) === null || ref32 === void 0 ? void 0 : ref32.slug)
135
+ name: (0, _).getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (ref37 = rootCategory.resource) === null || ref37 === void 0 ? void 0 : ref37.name),
136
+ slug: (0, _).getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (ref38 = rootCategory.resource) === null || ref38 === void 0 ? void 0 : ref38.slug)
137
137
  },
138
138
  categories: (0, _utils).formatCategories(product === null || product === void 0 ? void 0 : product.categories, rootCategoryId),
139
139
  reviewRatingStatistics: product === null || product === void 0 ? void 0 : product.reviewRatingStatistics,
140
- content: Boolean(selectedVariant === null || selectedVariant === void 0 ? void 0 : (ref33 = selectedVariant.content) === null || ref33 === void 0 ? void 0 : ref33.map(_utils.createProductContent).length) ? selectedVariant === null || selectedVariant === void 0 ? void 0 : (ref34 = selectedVariant.content) === null || ref34 === void 0 ? void 0 : ref34.map(_utils.createProductContent) : product === null || product === void 0 ? void 0 : (ref35 = product.content) === null || ref35 === void 0 ? void 0 : ref35.map(_utils.createProductContent),
140
+ content: Boolean(selectedVariant === null || selectedVariant === void 0 ? void 0 : (ref39 = selectedVariant.content) === null || ref39 === void 0 ? void 0 : ref39.map(_utils.createProductContent).length) ? selectedVariant === null || selectedVariant === void 0 ? void 0 : (ref40 = selectedVariant.content) === null || ref40 === void 0 ? void 0 : ref40.map(_utils.createProductContent) : product === null || product === void 0 ? void 0 : (ref41 = product.content) === null || ref41 === void 0 ? void 0 : ref41.map(_utils.createProductContent),
141
141
  assets: (0, _assetsToMap).assetsFieldsToMap(product === null || product === void 0 ? void 0 : product.assets)
142
142
  };
143
143
  return metaObj;
@@ -190,20 +190,20 @@ function ProductProvider(param) {
190
190
  variants
191
191
  ]);
192
192
  function getVariantsWithInventory() {
193
- var ref40;
194
- var variantsWithInventory = product === null || product === void 0 ? void 0 : (ref40 = product.variants) === null || ref40 === void 0 ? void 0 : ref40.reduce(function(map, _, index, arr) {
195
- var ref41, ref37, ref38, ref39;
193
+ var ref46;
194
+ var variantsWithInventory = product === null || product === void 0 ? void 0 : (ref46 = product.variants) === null || ref46 === void 0 ? void 0 : ref46.reduce(function(map, _, index, arr) {
195
+ var ref47, ref43, ref44, ref45;
196
196
  var currentVariant = arr[index];
197
197
  var mappedAttributes = (0, _utils).createMappedAttributes(currentVariant);
198
198
  var mappedOptions = (0, _utils).createMappedOptions(currentVariant === null || currentVariant === void 0 ? void 0 : currentVariant.availableOptions) || [];
199
- var isAvailable = currentVariant === null || currentVariant === void 0 ? void 0 : (ref41 = currentVariant.inventorySnapshot) === null || ref41 === void 0 ? void 0 : ref41.canOrder;
199
+ var isAvailable = currentVariant === null || currentVariant === void 0 ? void 0 : (ref47 = currentVariant.inventorySnapshot) === null || ref47 === void 0 ? void 0 : ref47.canOrder;
200
200
  var updatedVariant = _objectSpread({}, currentVariant, {
201
201
  inventory: {
202
- hasAvailableQuantity: (ref37 = currentVariant.inventorySnapshot) === null || ref37 === void 0 ? void 0 : ref37.canOrder,
203
- availableQuantity: (ref38 = currentVariant.inventorySnapshot) === null || ref38 === void 0 ? void 0 : ref38.availableQuantity
202
+ hasAvailableQuantity: (ref43 = currentVariant.inventorySnapshot) === null || ref43 === void 0 ? void 0 : ref43.canOrder,
203
+ availableQuantity: (ref44 = currentVariant.inventorySnapshot) === null || ref44 === void 0 ? void 0 : ref44.availableQuantity
204
204
  },
205
205
  isAvailable: isAvailable ? true : false,
206
- quantity: isAvailable ? currentVariant === null || currentVariant === void 0 ? void 0 : (ref39 = currentVariant.inventorySnapshot) === null || ref39 === void 0 ? void 0 : ref39.availableQuantity : 0,
206
+ quantity: isAvailable ? currentVariant === null || currentVariant === void 0 ? void 0 : (ref45 = currentVariant.inventorySnapshot) === null || ref45 === void 0 ? void 0 : ref45.availableQuantity : 0,
207
207
  attributes: mappedAttributes,
208
208
  options: mappedOptions,
209
209
  selectedOptions: [],
@@ -317,16 +317,26 @@ function ProductProvider(param) {
317
317
  return variants === null || variants === void 0 ? void 0 : variants[id];
318
318
  }
319
319
  function getVariantByCombination(key, value) {
320
- var ref;
321
- var id = (ref = combinations[key]) === null || ref === void 0 ? void 0 : ref.params[value];
322
- return variants === null || variants === void 0 ? void 0 : variants[id];
320
+ var ref48;
321
+ var split = value === null || value === void 0 ? void 0 : value.split(':');
322
+ if ((split === null || split === void 0 ? void 0 : split[0]) === 'collapseKey') {
323
+ var id = Object.keys(variants).find(function(el) {
324
+ var ref;
325
+ return variants[el].collapseKey === (split === null || split === void 0 ? void 0 : split[1]) && ((ref = variants[el].attributes.find(function(attr) {
326
+ return attr.name === 'size';
327
+ })) === null || ref === void 0 ? void 0 : ref.value) === key;
328
+ });
329
+ return variants[id];
330
+ }
331
+ var id3 = (ref48 = combinations[key]) === null || ref48 === void 0 ? void 0 : ref48.params[value];
332
+ return variants === null || variants === void 0 ? void 0 : variants[id3];
323
333
  }
324
334
  function getCustomFieldValue(field) {
325
335
  return customFields === null || customFields === void 0 ? void 0 : customFields[field];
326
336
  }
327
337
  function getCombinationsForAttributeRule(key, id) {
328
- var ref, ref42;
329
- var result = attributeRules === null || attributeRules === void 0 ? void 0 : (ref = attributeRules[key]) === null || ref === void 0 ? void 0 : (ref42 = ref.values) === null || ref42 === void 0 ? void 0 : ref42[id];
338
+ var ref, ref49;
339
+ var result = attributeRules === null || attributeRules === void 0 ? void 0 : (ref = attributeRules[key]) === null || ref === void 0 ? void 0 : (ref49 = ref.values) === null || ref49 === void 0 ? void 0 : ref49[id];
330
340
  return result;
331
341
  }
332
342
  var collapsedImages = (0, _utils).createCollapseKeyImagesMap(product);
@@ -60,7 +60,7 @@ function _prefetchCategories() {
60
60
  predicate: predicate,
61
61
  slug: aliasedSlug,
62
62
  aggregates: aggregates,
63
- postFilter: undefined,
63
+ postFilter: (0, _utils).getPostFilters(router),
64
64
  config: config
65
65
  });
66
66
  _ctx.next = 5;
@@ -6,6 +6,7 @@ import { readFromLocalStorage, writeToLocalStorage, getTranslatableField } from
6
6
  import { getSDKConfig } from '../getSDKConfig';
7
7
  import { syncResponse, getLineItemId, onMutate } from './utils';
8
8
  import { queryKey as promoCodeQueryKey } from '../../api.v2/core/misc/promo-code';
9
+ import { useIsAuthenticated } from '../..';
9
10
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
11
  try {
11
12
  var info = gen[key](arg);
@@ -110,6 +111,7 @@ export var MyCartApiFactory = function() {
110
111
  }(),
111
112
  useGet: function() {
112
113
  var queryCache = useQueryCache();
114
+ var isLoading = useIsAuthenticated().isLoading;
113
115
  return useQuery(myCartCacheKeys.useGet, _asyncToGenerator(regeneratorRuntime.mark(function _callee() {
114
116
  var data;
115
117
  return regeneratorRuntime.wrap(function _callee$(_ctx) {
@@ -128,12 +130,14 @@ export var MyCartApiFactory = function() {
128
130
  }
129
131
  }, _callee);
130
132
  })), {
133
+ enabled: !isLoading,
131
134
  retry: false,
132
- refetchOnMount: false,
135
+ refetchOnMount: true,
133
136
  refetchOnWindowFocus: false
134
137
  });
135
138
  },
136
139
  useGetCompact: function() {
140
+ var isLoading = useIsAuthenticated().isLoading;
137
141
  return useQuery(myCartCacheKeys.useGetCompact, _asyncToGenerator(regeneratorRuntime.mark(function _callee() {
138
142
  var compactBasket;
139
143
  return regeneratorRuntime.wrap(function _callee$(_ctx) {
@@ -146,7 +150,9 @@ export var MyCartApiFactory = function() {
146
150
  return _ctx.stop();
147
151
  }
148
152
  }, _callee);
149
- })));
153
+ })), {
154
+ enabled: !isLoading
155
+ });
150
156
  },
151
157
  useIsExisting: function(productId, variantId, collapseKey) {
152
158
  return useQuery([
@@ -65,7 +65,7 @@ export var useAvailability = function(param) {
65
65
  setStatus(ProductQuantityStatusEnum.OutOfStock);
66
66
  return;
67
67
  }
68
- if ((quantity !== null && quantity !== void 0 ? quantity : 0) < (quantityInBasket || 1)) {
68
+ if (quantity - (quantityInBasket || 0) < 1) {
69
69
  setStatus(ProductQuantityStatusEnum.MaxQuantityReached);
70
70
  return;
71
71
  }
@@ -92,7 +92,7 @@ function _unsupportedIterableToArray(o, minLen) {
92
92
  var ProductStateContext = /*#__PURE__*/ React.createContext(undefined);
93
93
  var CountDispatchContext = /*#__PURE__*/ React.createContext(undefined);
94
94
  export function ProductProvider(param) {
95
- var product = param.product, children = param.children, defaultVariantId = param.defaultVariantId;
95
+ var product = param.product, children = param.children, defaultVariantId = param.defaultVariantId, _includeBrandInName = param.includeBrandInName, includeBrandInName = _includeBrandInName === void 0 ? false : _includeBrandInName;
96
96
  var getVariantsWithInventory = function getVariantsWithInventory() {
97
97
  var ref9;
98
98
  var variantsWithInventory = product === null || product === void 0 ? void 0 : (ref9 = product.variants) === null || ref9 === void 0 ? void 0 : ref9.reduce(function(map, _, index, arr) {
@@ -221,16 +221,26 @@ export function ProductProvider(param) {
221
221
  return variants === null || variants === void 0 ? void 0 : variants[id];
222
222
  };
223
223
  var getVariantByCombination = function getVariantByCombination(key, value) {
224
- var ref;
225
- var id = (ref = combinations[key]) === null || ref === void 0 ? void 0 : ref.params[value];
226
- return variants === null || variants === void 0 ? void 0 : variants[id];
224
+ var ref11;
225
+ var split = value === null || value === void 0 ? void 0 : value.split(':');
226
+ if ((split === null || split === void 0 ? void 0 : split[0]) === 'collapseKey') {
227
+ var id = Object.keys(variants).find(function(el) {
228
+ var ref;
229
+ return variants[el].collapseKey === (split === null || split === void 0 ? void 0 : split[1]) && ((ref = variants[el].attributes.find(function(attr) {
230
+ return attr.name === 'size';
231
+ })) === null || ref === void 0 ? void 0 : ref.value) === key;
232
+ });
233
+ return variants[id];
234
+ }
235
+ var id3 = (ref11 = combinations[key]) === null || ref11 === void 0 ? void 0 : ref11.params[value];
236
+ return variants === null || variants === void 0 ? void 0 : variants[id3];
227
237
  };
228
238
  var getCustomFieldValue = function getCustomFieldValue(field) {
229
239
  return customFields === null || customFields === void 0 ? void 0 : customFields[field];
230
240
  };
231
241
  var getCombinationsForAttributeRule = function getCombinationsForAttributeRule(key, id) {
232
- var ref, ref11;
233
- var result = attributeRules === null || attributeRules === void 0 ? void 0 : (ref = attributeRules[key]) === null || ref === void 0 ? void 0 : (ref11 = ref.values) === null || ref11 === void 0 ? void 0 : ref11[id];
242
+ var ref, ref12;
243
+ 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];
234
244
  return result;
235
245
  };
236
246
  var ref5 = _slicedToArray(React.useState(false), 2), mounted = ref5[0], setMounted = ref5[1];
@@ -238,34 +248,34 @@ export function ProductProvider(param) {
238
248
  var ref3 = _slicedToArray(React.useState(getVariantsWithInventory), 2), variants = ref3[0], setVariants = ref3[1];
239
249
  var ref4 = _slicedToArray(React.useState(getDefaultVariant), 2), selectedVariant = ref4[0], setSelectedVariant = ref4[1];
240
250
  var metaData = React.useMemo(function() {
241
- var ref, ref12, ref13, ref14, ref15, ref16, ref17, ref18, ref19, ref20, ref21, ref22, ref23, ref24, ref25, ref26, ref27, ref28, ref29, ref30, ref31, ref32, ref33, ref34, ref35, ref36, ref37, ref38, ref39, ref40, ref41, ref42;
251
+ var ref, ref13, ref14, ref15, ref16, ref17, ref18, ref19, ref20, ref21, ref22, ref23, ref24, ref25, ref26, ref27, ref28, ref29, ref30, ref31, ref32, ref33, ref34, ref35, ref36, ref37, ref38, ref39, ref40, ref41, ref42, ref43, ref44, ref45, ref46, ref47, ref48, ref49;
242
252
  var rootCategory = product === null || product === void 0 ? void 0 : (ref = product.categories) === null || ref === void 0 ? void 0 : ref[0];
243
253
  var rootCategoryId = rootCategory === null || rootCategory === void 0 ? void 0 : rootCategory.resourceId;
244
254
  var metaObj = {
245
255
  _id: product === null || product === void 0 ? void 0 : product._id,
246
- name: getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || getTranslatableField(product === null || product === void 0 ? void 0 : product.name),
256
+ name: includeBrandInName && (product === null || product === void 0 ? void 0 : (ref13 = product.brands) === null || ref13 === void 0 ? void 0 : (ref14 = ref13[0]) === null || ref14 === void 0 ? void 0 : (ref15 = ref14.resource) === null || ref15 === void 0 ? void 0 : ref15.name) ? "".concat(getTranslatableField(product === null || product === void 0 ? void 0 : (ref16 = product.brands) === null || ref16 === void 0 ? void 0 : (ref17 = ref16[0]) === null || ref17 === void 0 ? void 0 : (ref18 = ref17.resource) === null || ref18 === void 0 ? void 0 : ref18.name), " ").concat(getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || getTranslatableField(product === null || product === void 0 ? void 0 : product.name)) : getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name) || getTranslatableField(product === null || product === void 0 ? void 0 : product.name),
247
257
  slug: getTranslatableField(product === null || product === void 0 ? void 0 : product.slug),
248
258
  description: getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.description) || getTranslatableField(product === null || product === void 0 ? void 0 : product.description),
249
259
  shortDescription: getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.metaDescription) || getTranslatableField(product === null || product === void 0 ? void 0 : product.metaDescription),
250
260
  brand: {
251
- _id: product === null || product === void 0 ? void 0 : (ref12 = product.brands) === null || ref12 === void 0 ? void 0 : (ref13 = ref12[0]) === null || ref13 === void 0 ? void 0 : ref13.resourceId,
252
- name: getTranslatableField(product === null || product === void 0 ? void 0 : (ref14 = product.brands) === null || ref14 === void 0 ? void 0 : (ref15 = ref14[0]) === null || ref15 === void 0 ? void 0 : (ref16 = ref15.resource) === null || ref16 === void 0 ? void 0 : ref16.name),
253
- slug: getTranslatableField(product === null || product === void 0 ? void 0 : (ref17 = product.brands) === null || ref17 === void 0 ? void 0 : (ref18 = ref17[0]) === null || ref18 === void 0 ? void 0 : (ref19 = ref18.resource) === null || ref19 === void 0 ? void 0 : ref19.slug),
254
- logo: product === null || product === void 0 ? void 0 : (ref20 = product.brands) === null || ref20 === void 0 ? void 0 : (ref21 = ref20[0]) === null || ref21 === void 0 ? void 0 : (ref22 = ref21.resource) === null || ref22 === void 0 ? void 0 : (ref23 = ref22.assets) === null || ref23 === void 0 ? void 0 : (ref24 = ref23[0]) === null || ref24 === void 0 ? void 0 : (ref25 = ref24.sources) === null || ref25 === void 0 ? void 0 : (ref26 = ref25[0]) === null || ref26 === void 0 ? void 0 : ref26.url
261
+ _id: product === null || product === void 0 ? void 0 : (ref19 = product.brands) === null || ref19 === void 0 ? void 0 : (ref20 = ref19[0]) === null || ref20 === void 0 ? void 0 : ref20.resourceId,
262
+ name: getTranslatableField(product === null || product === void 0 ? void 0 : (ref21 = product.brands) === null || ref21 === void 0 ? void 0 : (ref22 = ref21[0]) === null || ref22 === void 0 ? void 0 : (ref23 = ref22.resource) === null || ref23 === void 0 ? void 0 : ref23.name),
263
+ slug: getTranslatableField(product === null || product === void 0 ? void 0 : (ref24 = product.brands) === null || ref24 === void 0 ? void 0 : (ref25 = ref24[0]) === null || ref25 === void 0 ? void 0 : (ref26 = ref25.resource) === null || ref26 === void 0 ? void 0 : ref26.slug),
264
+ logo: product === null || product === void 0 ? void 0 : (ref27 = product.brands) === null || ref27 === void 0 ? void 0 : (ref28 = ref27[0]) === null || ref28 === void 0 ? void 0 : (ref29 = ref28.resource) === null || ref29 === void 0 ? void 0 : (ref30 = ref29.assets) === null || ref30 === void 0 ? void 0 : (ref31 = ref30[0]) === null || ref31 === void 0 ? void 0 : (ref32 = ref31.sources) === null || ref32 === void 0 ? void 0 : (ref33 = ref32[0]) === null || ref33 === void 0 ? void 0 : ref33.url
255
265
  },
256
266
  category: {
257
- _id: product === null || product === void 0 ? void 0 : (ref28 = product.categories) === null || ref28 === void 0 ? void 0 : (ref29 = ref28[(product === null || product === void 0 ? void 0 : (ref27 = product.categories) === null || ref27 === void 0 ? void 0 : ref27.length) - 1]) === null || ref29 === void 0 ? void 0 : ref29.resourceId,
258
- name: getTranslatableField(product === null || product === void 0 ? void 0 : (ref31 = product.categories) === null || ref31 === void 0 ? void 0 : (ref32 = ref31[(product === null || product === void 0 ? void 0 : (ref30 = product.categories) === null || ref30 === void 0 ? void 0 : ref30.length) - 1]) === null || ref32 === void 0 ? void 0 : (ref33 = ref32.resource) === null || ref33 === void 0 ? void 0 : ref33.name),
259
- slug: getTranslatableField(product === null || product === void 0 ? void 0 : (ref35 = product.categories) === null || ref35 === void 0 ? void 0 : (ref36 = ref35[(product === null || product === void 0 ? void 0 : (ref34 = product.categories) === null || ref34 === void 0 ? void 0 : ref34.length) - 1]) === null || ref36 === void 0 ? void 0 : (ref37 = ref36.resource) === null || ref37 === void 0 ? void 0 : ref37.slug)
267
+ _id: product === null || product === void 0 ? void 0 : (ref35 = product.categories) === null || ref35 === void 0 ? void 0 : (ref36 = ref35[(product === null || product === void 0 ? void 0 : (ref34 = product.categories) === null || ref34 === void 0 ? void 0 : ref34.length) - 1]) === null || ref36 === void 0 ? void 0 : ref36.resourceId,
268
+ name: getTranslatableField(product === null || product === void 0 ? void 0 : (ref38 = product.categories) === null || ref38 === void 0 ? void 0 : (ref39 = ref38[(product === null || product === void 0 ? void 0 : (ref37 = product.categories) === null || ref37 === void 0 ? void 0 : ref37.length) - 1]) === null || ref39 === void 0 ? void 0 : (ref40 = ref39.resource) === null || ref40 === void 0 ? void 0 : ref40.name),
269
+ slug: getTranslatableField(product === null || product === void 0 ? void 0 : (ref42 = product.categories) === null || ref42 === void 0 ? void 0 : (ref43 = ref42[(product === null || product === void 0 ? void 0 : (ref41 = product.categories) === null || ref41 === void 0 ? void 0 : ref41.length) - 1]) === null || ref43 === void 0 ? void 0 : (ref44 = ref43.resource) === null || ref44 === void 0 ? void 0 : ref44.slug)
260
270
  },
261
271
  rootCategory: {
262
272
  _id: rootCategoryId,
263
- name: getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (ref38 = rootCategory.resource) === null || ref38 === void 0 ? void 0 : ref38.name),
264
- slug: getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (ref39 = rootCategory.resource) === null || ref39 === void 0 ? void 0 : ref39.slug)
273
+ name: getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (ref45 = rootCategory.resource) === null || ref45 === void 0 ? void 0 : ref45.name),
274
+ slug: getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (ref46 = rootCategory.resource) === null || ref46 === void 0 ? void 0 : ref46.slug)
265
275
  },
266
276
  categories: formatCategories(product === null || product === void 0 ? void 0 : product.categories, rootCategoryId),
267
277
  reviewRatingStatistics: product === null || product === void 0 ? void 0 : product.reviewRatingStatistics,
268
- content: Boolean(selectedVariant === null || selectedVariant === void 0 ? void 0 : (ref40 = selectedVariant.content) === null || ref40 === void 0 ? void 0 : ref40.map(createProductContent).length) ? selectedVariant === null || selectedVariant === void 0 ? void 0 : (ref41 = selectedVariant.content) === null || ref41 === void 0 ? void 0 : ref41.map(createProductContent) : product === null || product === void 0 ? void 0 : (ref42 = product.content) === null || ref42 === void 0 ? void 0 : ref42.map(createProductContent),
278
+ content: Boolean(selectedVariant === null || selectedVariant === void 0 ? void 0 : (ref47 = selectedVariant.content) === null || ref47 === void 0 ? void 0 : ref47.map(createProductContent).length) ? selectedVariant === null || selectedVariant === void 0 ? void 0 : (ref48 = selectedVariant.content) === null || ref48 === void 0 ? void 0 : ref48.map(createProductContent) : product === null || product === void 0 ? void 0 : (ref49 = product.content) === null || ref49 === void 0 ? void 0 : ref49.map(createProductContent),
269
279
  assets: assetsFieldsToMap(product === null || product === void 0 ? void 0 : product.assets)
270
280
  };
271
281
  return metaObj;
@@ -51,7 +51,7 @@ function _prefetchCategories() {
51
51
  predicate: predicate,
52
52
  slug: aliasedSlug,
53
53
  aggregates: aggregates,
54
- postFilter: undefined,
54
+ postFilter: getPostFilters(router),
55
55
  config: config
56
56
  });
57
57
  _ctx.next = 5;
@@ -128,6 +128,7 @@ declare type ProductProviderProps = {
128
128
  expand?: string;
129
129
  project?: string;
130
130
  };
131
+ includeBrandInName?: boolean;
131
132
  };
132
133
  declare type ProductStateContextType = {
133
134
  attributeRules: AttributeRulesMap;
@@ -163,7 +164,7 @@ declare type CountFunctionsContextType = {
163
164
  };
164
165
  getProductVideos: () => VideoType[];
165
166
  };
166
- export declare function ProductProvider({ product, children, defaultVariantId, }: ProductProviderProps): JSX.Element;
167
+ export declare function ProductProvider({ product, children, defaultVariantId, includeBrandInName, }: ProductProviderProps): JSX.Element;
167
168
  export declare function useProductState(): ProductStateContextType;
168
169
  export declare function useProductFunctions(): CountFunctionsContextType;
169
170
  export declare function useProduct(slug: string, config?: getProductBySlugConfig): import("react-query").QueryResult<ProductDTO, unknown>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sentecacommerce-theme/lib",
3
3
  "sideEffects": false,
4
- "version": "0.12.97",
4
+ "version": "0.12.101",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/types/index.d.ts",
@@ -31,13 +31,13 @@
31
31
  "watch:cjs": "swc src --out-dir dist/cjs -w",
32
32
  "watch:esm": "swc src --out-dir dist/esm --no-swcrc -w"
33
33
  },
34
- "gitHead": "d71d565067baef7c428849d6ccd7280f74d9fcf3",
34
+ "gitHead": "b48bfd0a30f37d4720d671c959e84d4943fb4f6d",
35
35
  "peerDependencies": {
36
36
  "react-query": "^2.26.2"
37
37
  },
38
38
  "dependencies": {
39
- "@sentecacommerce-theme/base": "^0.12.97",
40
- "@sentecacommerce-theme/cms": "^0.12.97",
39
+ "@sentecacommerce-theme/base": "^0.12.101",
40
+ "@sentecacommerce-theme/cms": "^0.12.101",
41
41
  "@sentecacommerce/sdk": "2.0.161",
42
42
  "body-scroll-lock": "^3.1.5",
43
43
  "copy-to-clipboard": "^3.3.1",