@sentecacommerce-theme/lib 0.13.2 → 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.
@@ -29,11 +29,12 @@ function _objectSpread(target) {
29
29
  }
30
30
  return target;
31
31
  }
32
+ export { useLineItemFunctions, useLineItemState, LineItemStateProvider } from './LineItemContext';
32
33
  export var useLineItem = function(props) {
33
- var ref16 = usePrefetchProduct(getTranslatableField(props === null || props === void 0 ? void 0 : props.slug)), onMouseEnter = ref16.onMouseEnter, onMouseLeave = ref16.onMouseLeave, onMouseDown = ref16.onMouseDown;
34
+ var ref17 = usePrefetchProduct(getTranslatableField(props === null || props === void 0 ? void 0 : props.slug)), onMouseEnter = ref17.onMouseEnter, onMouseLeave = ref17.onMouseLeave, onMouseDown = ref17.onMouseDown;
34
35
  var data = React.useMemo(function() {
35
- var ref17, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, ref10, ref11, ref12;
36
- var mappedAttributes = (ref17 = Object.keys(props === null || props === void 0 ? void 0 : props.attributes)) === null || ref17 === void 0 ? void 0 : ref17.reduce(function(map, key) {
36
+ var ref18, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, ref10, ref11, ref12, ref13;
37
+ var mappedAttributes = (ref18 = Object.keys(props === null || props === void 0 ? void 0 : props.attributes)) === null || ref18 === void 0 ? void 0 : ref18.reduce(function(map, key) {
37
38
  var current = props === null || props === void 0 ? void 0 : props.attributes[key];
38
39
  var ref;
39
40
  map[key] = {
@@ -54,7 +55,7 @@ export var useLineItem = function(props) {
54
55
  }
55
56
  return map;
56
57
  }, {});
57
- var ref13, ref14, ref15;
58
+ var ref14, ref15, ref16;
58
59
  return {
59
60
  _id: props === null || props === void 0 ? void 0 : props._id,
60
61
  name: getTranslatableField(props === null || props === void 0 ? void 0 : props.name),
@@ -62,18 +63,21 @@ export var useLineItem = function(props) {
62
63
  name: getTranslatableField(props === null || props === void 0 ? void 0 : (ref2 = props.brands) === null || ref2 === void 0 ? void 0 : (ref3 = ref2[0]) === null || ref3 === void 0 ? void 0 : ref3.name),
63
64
  slug: getTranslatableField(props === null || props === void 0 ? void 0 : (ref4 = props.brands) === null || ref4 === void 0 ? void 0 : (ref5 = ref4[0]) === null || ref5 === void 0 ? void 0 : ref5.slug)
64
65
  },
66
+ attributes: props === null || props === void 0 ? void 0 : props.attributes,
67
+ variantAttributes: (ref6 = props) === null || ref6 === void 0 ? void 0 : ref6.variantAttributes,
68
+ variants: props === null || props === void 0 ? void 0 : props.variants,
65
69
  slug: getTranslatableField(props === null || props === void 0 ? void 0 : props.slug),
66
70
  collapseKey: props === null || props === void 0 ? void 0 : props.collapseKey,
67
71
  variantId: props === null || props === void 0 ? void 0 : props.variantId,
68
- offerId: props === null || props === void 0 ? void 0 : (ref6 = props.offer) === null || ref6 === void 0 ? void 0 : ref6._id,
72
+ offerId: props === null || props === void 0 ? void 0 : (ref7 = props.offer) === null || ref7 === void 0 ? void 0 : ref7._id,
69
73
  offer: props === null || props === void 0 ? void 0 : props.offer,
70
74
  sku: props === null || props === void 0 ? void 0 : props.sku,
71
75
  images: (props === null || props === void 0 ? void 0 : props.images) || {},
72
76
  ratings: props === null || props === void 0 ? void 0 : props.reviewRatingStatistics,
73
- price: props === null || props === void 0 ? void 0 : (ref7 = props.offer) === null || ref7 === void 0 ? void 0 : ref7.originalPrice,
74
- discountedPrice: props === null || props === void 0 ? void 0 : (ref8 = props.offer) === null || ref8 === void 0 ? void 0 : ref8.discountedPrice,
75
- variantOptions: (ref13 = props === null || props === void 0 ? void 0 : props.variantOptions) !== null && ref13 !== void 0 ? ref13 : 0,
76
- variantsCount: (ref14 = props === null || props === void 0 ? void 0 : props.variantsCount) !== null && ref14 !== void 0 ? ref14 : 0,
77
+ price: props === null || props === void 0 ? void 0 : (ref8 = props.offer) === null || ref8 === void 0 ? void 0 : ref8.originalPrice,
78
+ discountedPrice: props === null || props === void 0 ? void 0 : (ref9 = props.offer) === null || ref9 === void 0 ? void 0 : ref9.discountedPrice,
79
+ variantOptions: (ref14 = props === null || props === void 0 ? void 0 : props.variantOptions) !== null && ref14 !== void 0 ? ref14 : 0,
80
+ variantsCount: (ref15 = props === null || props === void 0 ? void 0 : props.variantsCount) !== null && ref15 !== void 0 ? ref15 : 0,
77
81
  categories: props === null || props === void 0 ? void 0 : props.categories.map(function(category) {
78
82
  return {
79
83
  name: getTranslatableField(category.name),
@@ -81,9 +85,9 @@ export var useLineItem = function(props) {
81
85
  };
82
86
  }),
83
87
  inventory: {
84
- hasAvailableQuantity: (props === null || props === void 0 ? void 0 : (ref9 = props.inventorySnapshot) === null || ref9 === void 0 ? void 0 : ref9.canOrder) ? true : false,
85
- availableQuantity: (props === null || props === void 0 ? void 0 : (ref10 = props.inventorySnapshot) === null || ref10 === void 0 ? void 0 : ref10.canOrder) ? (ref15 = props === null || props === void 0 ? void 0 : (ref11 = props.inventorySnapshot) === null || ref11 === void 0 ? void 0 : ref11.availableQuantity) !== null && ref15 !== void 0 ? ref15 : 0 : 0,
86
- maxQuantity: props === null || props === void 0 ? void 0 : (ref12 = props.offer) === null || ref12 === void 0 ? void 0 : ref12.maxQuantity
88
+ hasAvailableQuantity: (props === null || props === void 0 ? void 0 : (ref10 = props.inventorySnapshot) === null || ref10 === void 0 ? void 0 : ref10.canOrder) ? true : false,
89
+ availableQuantity: (props === null || props === void 0 ? void 0 : (ref11 = props.inventorySnapshot) === null || ref11 === void 0 ? void 0 : ref11.canOrder) ? (ref16 = props === null || props === void 0 ? void 0 : (ref12 = props.inventorySnapshot) === null || ref12 === void 0 ? void 0 : ref12.availableQuantity) !== null && ref16 !== void 0 ? ref16 : 0 : 0,
90
+ maxQuantity: props === null || props === void 0 ? void 0 : (ref13 = props.offer) === null || ref13 === void 0 ? void 0 : ref13.maxQuantity
87
91
  },
88
92
  labels: mapLabelData(props === null || props === void 0 ? void 0 : props.labels),
89
93
  getCustomFieldByKey: function(key) {
@@ -1,281 +1,46 @@
1
1
  import React from 'react';
2
2
  import { getTranslatableField } from '../../';
3
- import { assignCombinationsToAttributeRules, createCombinationsMap, createCustomFieldsMap, createProductContent, createAttributeRulesMap, createMappedAttributes, processAvailabilityPerStore, getProductVideos, createMappedOptions, createSelectedOption2, formatCategories, createLabelsMap, createCollapseKeyImagesMap } from './utils';
3
+ import { createProductContent, getProductVideos, formatCategories, createCollapseKeyImagesMap } from './utils';
4
4
  import { productsApi } from '../../api/productsApi';
5
5
  import { assetsFieldsToMap } from '../../utils/assetsToMap';
6
- function _arrayLikeToArray(arr, len) {
7
- if (len == null || len > arr.length) len = arr.length;
8
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
9
- return arr2;
10
- }
11
- function _arrayWithHoles(arr) {
12
- if (Array.isArray(arr)) return arr;
13
- }
14
- function _arrayWithoutHoles(arr) {
15
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
16
- }
17
- function _defineProperty(obj, key, value) {
18
- if (key in obj) {
19
- Object.defineProperty(obj, key, {
20
- value: value,
21
- enumerable: true,
22
- configurable: true,
23
- writable: true
24
- });
25
- } else {
26
- obj[key] = value;
27
- }
28
- return obj;
29
- }
30
- function _iterableToArray(iter) {
31
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
32
- }
33
- function _iterableToArrayLimit(arr, i) {
34
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
35
- if (_i == null) return;
36
- var _arr = [];
37
- var _n = true;
38
- var _d = false;
39
- var _s, _e;
40
- try {
41
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
42
- _arr.push(_s.value);
43
- if (i && _arr.length === i) break;
44
- }
45
- } catch (err) {
46
- _d = true;
47
- _e = err;
48
- } finally{
49
- try {
50
- if (!_n && _i["return"] != null) _i["return"]();
51
- } finally{
52
- if (_d) throw _e;
53
- }
54
- }
55
- return _arr;
56
- }
57
- function _nonIterableRest() {
58
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
59
- }
60
- function _nonIterableSpread() {
61
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
62
- }
63
- function _objectSpread(target) {
64
- for(var i = 1; i < arguments.length; i++){
65
- var source = arguments[i] != null ? arguments[i] : {};
66
- var ownKeys = Object.keys(source);
67
- if (typeof Object.getOwnPropertySymbols === "function") {
68
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
69
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
70
- }));
71
- }
72
- ownKeys.forEach(function(key) {
73
- _defineProperty(target, key, source[key]);
74
- });
75
- }
76
- return target;
77
- }
78
- function _slicedToArray(arr, i) {
79
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
80
- }
81
- function _toConsumableArray(arr) {
82
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
83
- }
84
- function _unsupportedIterableToArray(o, minLen) {
85
- if (!o) return;
86
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
87
- var n = Object.prototype.toString.call(o).slice(8, -1);
88
- if (n === "Object" && o.constructor) n = o.constructor.name;
89
- if (n === "Map" || n === "Set") return Array.from(n);
90
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
91
- }
6
+ import { useProductVariants } from '../useProductVariants';
92
7
  var ProductStateContext = /*#__PURE__*/ React.createContext(undefined);
93
8
  var CountDispatchContext = /*#__PURE__*/ React.createContext(undefined);
94
9
  export function ProductProvider(param) {
95
10
  var product = param.product, children = param.children, defaultVariantId = param.defaultVariantId, _includeBrandInName = param.includeBrandInName, includeBrandInName = _includeBrandInName === void 0 ? false : _includeBrandInName;
96
- var getVariantsWithInventory = function getVariantsWithInventory() {
97
- var ref9;
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) {
99
- var ref10, ref6, ref7, ref8;
100
- var currentVariant = arr[index];
101
- var mappedAttributes = createMappedAttributes(currentVariant);
102
- var mappedOptions = createMappedOptions(currentVariant === null || currentVariant === void 0 ? void 0 : currentVariant.availableOptions) || [];
103
- var isAvailable = currentVariant === null || currentVariant === void 0 ? void 0 : (ref10 = currentVariant.inventorySnapshot) === null || ref10 === void 0 ? void 0 : ref10.canOrder;
104
- var updatedVariant = _objectSpread({}, currentVariant, {
105
- inventory: {
106
- hasAvailableQuantity: (ref6 = currentVariant.inventorySnapshot) === null || ref6 === void 0 ? void 0 : ref6.canOrder,
107
- availableQuantity: (ref7 = currentVariant.inventorySnapshot) === null || ref7 === void 0 ? void 0 : ref7.availableQuantity
108
- },
109
- isAvailable: isAvailable ? true : false,
110
- quantity: isAvailable ? currentVariant === null || currentVariant === void 0 ? void 0 : (ref8 = currentVariant.inventorySnapshot) === null || ref8 === void 0 ? void 0 : ref8.availableQuantity : 0,
111
- attributes: mappedAttributes,
112
- options: mappedOptions,
113
- selectedOptions: [],
114
- labels: createLabelsMap(currentVariant.labels),
115
- getAttribute: function(rule) {
116
- return getSelectedAttribute(rule, mappedAttributes);
117
- },
118
- getAttributeByKey: function(key) {
119
- var ref;
120
- return (ref = mappedAttributes.find(function(a) {
121
- return a.name === key;
122
- })) === null || ref === void 0 ? void 0 : ref.value;
123
- },
124
- getAvailabilityByStore: function() {
125
- var ref;
126
- return processAvailabilityPerStore(currentVariant === null || currentVariant === void 0 ? void 0 : (ref = currentVariant.inventorySnapshot) === null || ref === void 0 ? void 0 : ref.availabilities);
127
- }
128
- });
129
- map[currentVariant._id] = updatedVariant;
130
- return map;
131
- }, {});
132
- return variantsWithInventory || {};
133
- };
134
- var getCombinationsAndAttributeRules = function getCombinationsAndAttributeRules() {
135
- var mappedAttributeRules = createAttributeRulesMap(product);
136
- var attributesWithId = Object.keys(variants || {}).map(function(key) {
137
- return {
138
- variantId: variants === null || variants === void 0 ? void 0 : variants[key]._id,
139
- attributes: variants === null || variants === void 0 ? void 0 : variants[key].attributes
140
- };
141
- });
142
- var combinationsMap = createCombinationsMap(Object.keys(mappedAttributeRules), attributesWithId);
143
- assignCombinationsToAttributeRules(mappedAttributeRules, combinationsMap);
144
- return {
145
- combinations: combinationsMap,
146
- attributeRules: mappedAttributeRules
147
- };
148
- };
149
- var getDefaultVariant = function getDefaultVariant() {
150
- if (!defaultVariantId) return null;
151
- return variants[defaultVariantId];
152
- };
153
- var selectVariantById = function selectVariantById(id) {
154
- setSelectedVariant(variants[id]);
155
- };
156
- var selectVariantByAttribute = function selectVariantByAttribute(key) {
157
- var ref;
158
- // Get by collapseKey for SD
159
- var split = key.split(':');
160
- if (split[0] === 'collapseKey') {
161
- var id = Object.keys(variants).find(function(el) {
162
- return variants[el].collapseKey === split[1];
163
- });
164
- return setSelectedVariant(variants[id]);
165
- }
166
- var id1 = (ref = combinations[key]) === null || ref === void 0 ? void 0 : ref.value;
167
- setSelectedVariant(variants[id1]);
168
- };
169
- var selectVariantByCombination = function selectVariantByCombination(key, value) {
170
- // Take collapseKey for SD
171
- var split = value.split(':');
172
- if (split[0] === 'collapseKey') {
173
- var id = Object.keys(variants).find(function(el) {
174
- var ref;
175
- return variants[el].collapseKey === split[1] && ((ref = variants[el].attributes.find(function(attr) {
176
- return attr.name === 'size';
177
- })) === null || ref === void 0 ? void 0 : ref.value) === key;
178
- });
179
- return setSelectedVariant(variants[id]);
180
- }
181
- var id2 = combinations[key].params[value];
182
- setSelectedVariant(variants[id2]);
183
- };
184
- var selectVariantOptions = function selectVariantOptions(definitionKey, optionKey) {
185
- if (selectedVariant) {
186
- var newSelectedVariant = _objectSpread({}, selectedVariant);
187
- newSelectedVariant.selectedOptions = newSelectedVariant.selectedOptions.filter(function(opt) {
188
- return opt.definitionKey !== definitionKey;
189
- });
190
- newSelectedVariant.selectedOptions = _toConsumableArray(newSelectedVariant.selectedOptions).concat([
191
- {
192
- definitionKey: definitionKey,
193
- optionKey: optionKey
194
- },
195
- ]);
196
- newSelectedVariant.mappedSelectedOptions = newSelectedVariant.selectedOptions.map(function(option) {
197
- return createSelectedOption2(newSelectedVariant.options, option);
198
- });
199
- setSelectedVariant(newSelectedVariant);
200
- }
201
- };
202
- var getSelectedAttribute = function getSelectedAttribute(rule, attributes) {
203
- var ref;
204
- var attributeRule = (ref = attributeRules[rule]) === null || ref === void 0 ? void 0 : ref.values;
205
- var result;
206
- attributes.forEach(function(currentKey) {
207
- var found = attributeRule === null || attributeRule === void 0 ? void 0 : attributeRule[currentKey.value];
208
- if (found) result = _objectSpread({
209
- id: currentKey.value,
210
- name: rule
211
- }, found);
212
- });
213
- return result;
214
- };
215
- var getVariantById = function getVariantById(id) {
216
- return variants === null || variants === void 0 ? void 0 : variants[id];
217
- };
218
- var getVariantByAttribute = function getVariantByAttribute(key) {
219
- var ref;
220
- var id = (ref = combinations[key]) === null || ref === void 0 ? void 0 : ref.value;
221
- return variants === null || variants === void 0 ? void 0 : variants[id];
222
- };
223
- var getVariantByCombination = function getVariantByCombination(key, value) {
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];
237
- };
238
- var getCustomFieldValue = function getCustomFieldValue(field) {
239
- return customFields === null || customFields === void 0 ? void 0 : customFields[field];
240
- };
241
- var getCombinationsForAttributeRule = function getCombinationsForAttributeRule(key, 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];
244
- return result;
245
- };
246
- var ref5 = _slicedToArray(React.useState(false), 2), mounted = ref5[0], setMounted = ref5[1];
247
- var ref1 = _slicedToArray(React.useState(getCombinationsAndAttributeRules), 2), ref2 = ref1[0], combinations = ref2.combinations, attributeRules = ref2.attributeRules, setCombinationsAndAttributeRules = ref1[1];
248
- var ref3 = _slicedToArray(React.useState(getVariantsWithInventory), 2), variants = ref3[0], setVariants = ref3[1];
249
- var ref4 = _slicedToArray(React.useState(getDefaultVariant), 2), selectedVariant = ref4[0], setSelectedVariant = ref4[1];
11
+ var ref38 = useProductVariants({
12
+ product: product,
13
+ defaultVariantId: defaultVariantId
14
+ }), selectedVariant = ref38.selectedVariant, attributeRules = ref38.attributeRules, variants = ref38.variants, getVariantById = ref38.getVariantById, getVariantByAttribute = ref38.getVariantByAttribute, getVariantByCombination = ref38.getVariantByCombination, getCustomFieldValue = ref38.getCustomFieldValue, getCombinationsForAttributeRule = ref38.getCombinationsForAttributeRule, selectVariantById = ref38.selectVariantById, selectVariantByAttribute = ref38.selectVariantByAttribute, selectVariantByCombination = ref38.selectVariantByCombination, selectVariantOptions = ref38.selectVariantOptions;
250
15
  var metaData = React.useMemo(function() {
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;
16
+ var ref, ref1, ref2, ref3, ref4, 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;
252
17
  var rootCategory = product === null || product === void 0 ? void 0 : (ref = product.categories) === null || ref === void 0 ? void 0 : ref[0];
253
18
  var rootCategoryId = rootCategory === null || rootCategory === void 0 ? void 0 : rootCategory.resourceId;
254
19
  var metaObj = {
255
20
  _id: product === null || product === void 0 ? void 0 : product._id,
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),
21
+ name: includeBrandInName && (product === null || product === void 0 ? void 0 : (ref1 = product.brands) === null || ref1 === void 0 ? void 0 : (ref2 = ref1[0]) === null || ref2 === void 0 ? void 0 : (ref3 = ref2.resource) === null || ref3 === void 0 ? void 0 : ref3.name) ? "".concat(getTranslatableField(product === null || product === void 0 ? void 0 : (ref4 = product.brands) === null || ref4 === void 0 ? void 0 : (ref5 = ref4[0]) === null || ref5 === void 0 ? void 0 : (ref6 = ref5.resource) === null || ref6 === void 0 ? void 0 : ref6.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),
257
22
  slug: getTranslatableField(product === null || product === void 0 ? void 0 : product.slug),
258
23
  description: getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.description) || getTranslatableField(product === null || product === void 0 ? void 0 : product.description),
259
24
  shortDescription: getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.metaDescription) || getTranslatableField(product === null || product === void 0 ? void 0 : product.metaDescription),
260
25
  brand: {
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
26
+ _id: 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 : ref8.resourceId,
27
+ name: getTranslatableField(product === null || product === void 0 ? void 0 : (ref9 = product.brands) === null || ref9 === void 0 ? void 0 : (ref10 = ref9[0]) === null || ref10 === void 0 ? void 0 : (ref11 = ref10.resource) === null || ref11 === void 0 ? void 0 : ref11.name),
28
+ slug: getTranslatableField(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 : (ref14 = ref13.resource) === null || ref14 === void 0 ? void 0 : ref14.slug),
29
+ logo: product === null || product === void 0 ? void 0 : (ref15 = product.brands) === null || ref15 === void 0 ? void 0 : (ref16 = ref15[0]) === null || ref16 === void 0 ? void 0 : (ref17 = ref16.resource) === null || ref17 === void 0 ? void 0 : (ref18 = ref17.assets) === null || ref18 === void 0 ? void 0 : (ref19 = ref18[0]) === null || ref19 === void 0 ? void 0 : (ref20 = ref19.sources) === null || ref20 === void 0 ? void 0 : (ref21 = ref20[0]) === null || ref21 === void 0 ? void 0 : ref21.url
265
30
  },
266
31
  category: {
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)
32
+ _id: product === null || product === void 0 ? void 0 : (ref23 = product.categories) === null || ref23 === void 0 ? void 0 : (ref24 = ref23[(product === null || product === void 0 ? void 0 : (ref22 = product.categories) === null || ref22 === void 0 ? void 0 : ref22.length) - 1]) === null || ref24 === void 0 ? void 0 : ref24.resourceId,
33
+ name: getTranslatableField(product === null || product === void 0 ? void 0 : (ref26 = product.categories) === null || ref26 === void 0 ? void 0 : (ref27 = ref26[(product === null || product === void 0 ? void 0 : (ref25 = product.categories) === null || ref25 === void 0 ? void 0 : ref25.length) - 1]) === null || ref27 === void 0 ? void 0 : (ref28 = ref27.resource) === null || ref28 === void 0 ? void 0 : ref28.name),
34
+ slug: 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.slug)
270
35
  },
271
36
  rootCategory: {
272
37
  _id: rootCategoryId,
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)
38
+ name: getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (ref33 = rootCategory.resource) === null || ref33 === void 0 ? void 0 : ref33.name),
39
+ slug: getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (ref34 = rootCategory.resource) === null || ref34 === void 0 ? void 0 : ref34.slug)
275
40
  },
276
41
  categories: formatCategories(product === null || product === void 0 ? void 0 : product.categories, rootCategoryId),
277
42
  reviewRatingStatistics: product === null || product === void 0 ? void 0 : product.reviewRatingStatistics,
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),
43
+ content: Boolean(selectedVariant === null || selectedVariant === void 0 ? void 0 : (ref35 = selectedVariant.content) === null || ref35 === void 0 ? void 0 : ref35.map(createProductContent).length) ? selectedVariant === null || selectedVariant === void 0 ? void 0 : (ref36 = selectedVariant.content) === null || ref36 === void 0 ? void 0 : ref36.map(createProductContent) : product === null || product === void 0 ? void 0 : (ref37 = product.content) === null || ref37 === void 0 ? void 0 : ref37.map(createProductContent),
279
44
  assets: assetsFieldsToMap(product === null || product === void 0 ? void 0 : product.assets)
280
45
  };
281
46
  return metaObj;
@@ -303,30 +68,6 @@ export function ProductProvider(param) {
303
68
  product === null || product === void 0 ? void 0 : product.metaTitle,
304
69
  selectedVariant,
305
70
  ]);
306
- var customFields = React.useMemo(function() {
307
- var mappedFields = createCustomFieldsMap(product === null || product === void 0 ? void 0 : product.custom);
308
- return mappedFields;
309
- }, [
310
- product === null || product === void 0 ? void 0 : product.custom
311
- ]);
312
- React.useEffect(function() {
313
- // prevent unnecessary calculations
314
- if (mounted) {
315
- setVariants(getVariantsWithInventory());
316
- }
317
- }, [
318
- product
319
- ]);
320
- React.useMemo(function() {
321
- // prevent unnecessary calculations
322
- if (!mounted) {
323
- return setMounted(true);
324
- }
325
- var data = getCombinationsAndAttributeRules();
326
- setCombinationsAndAttributeRules(data);
327
- }, [
328
- variants
329
- ]);
330
71
  var collapsedImages = createCollapseKeyImagesMap(product);
331
72
  var state = {
332
73
  metaData: metaData,
@@ -133,8 +133,9 @@ export var createCollapseKeyImagesMap = function(product) {
133
133
  return mappedKeys;
134
134
  };
135
135
  export var createAttributeRulesMap = function(product) {
136
+ var isLineItem = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
136
137
  var ref, ref1;
137
- var uniqueRules = product === null || product === void 0 ? void 0 : (ref = product.attributeRules) === null || ref === void 0 ? void 0 : ref.filter(function(x) {
138
+ var uniqueRules = isLineItem ? product === null || product === void 0 ? void 0 : product.attributeRules : product === null || product === void 0 ? void 0 : (ref = product.attributeRules) === null || ref === void 0 ? void 0 : ref.filter(function(x) {
138
139
  return x.constraint === AttributeRuleDTOConstraintEnum.CombinationUnique;
139
140
  });
140
141
  var reduceVariantsToAttributeRuleValues = function(map, attribute) {
@@ -158,7 +159,7 @@ export var createAttributeRulesMap = function(product) {
158
159
  return map;
159
160
  };
160
161
  var mappedAttributeRules = product === null || product === void 0 ? void 0 : (ref1 = product.variants) === null || ref1 === void 0 ? void 0 : ref1.map(function(v) {
161
- return v.attributes;
162
+ return isLineItem ? remapLineItemAttributes(v.attributes) : v.attributes;
162
163
  }).flat().reduce(reduceVariantsToAttributeRuleValues, {});
163
164
  return mappedAttributeRules;
164
165
  };
@@ -214,12 +215,13 @@ export var createSelectedOption = function(options, selectedOption) {
214
215
  };
215
216
  };
216
217
  export var createMappedAttributes = function(currentVariant) {
217
- var ref;
218
- var mappedAttributes = ((ref = currentVariant.attributes) === null || ref === void 0 ? void 0 : ref.reduce(function(attributeArray, attribute) {
218
+ var isLineItem = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
219
+ var ref, ref2;
220
+ var mappedAttributes = ((ref2 = isLineItem ? (ref = currentVariant) === null || ref === void 0 ? void 0 : ref.variantAttributes : currentVariant === null || currentVariant === void 0 ? void 0 : currentVariant.attributes) === null || ref2 === void 0 ? void 0 : ref2.reduce(function(attributeArray, attribute) {
219
221
  attributeArray.push({
220
222
  name: attribute.name,
221
223
  value: attribute.value,
222
- valueData: attribute.valueData
224
+ valueData: isLineItem ? attribute : attribute.valueData
223
225
  });
224
226
  return attributeArray;
225
227
  }, [])) || [];
@@ -257,15 +259,15 @@ export var getProductVideos = function(assets) {
257
259
  return [];
258
260
  };
259
261
  export var formatCategories = function(categories, rootCategoryId) {
260
- var ref5;
262
+ var ref6;
261
263
  var results;
262
264
  if (categories === null || categories === void 0 ? void 0 : categories.some(function(cat) {
263
- var ref, ref4;
264
- return (ref = cat.resource) === null || ref === void 0 ? void 0 : (ref4 = ref.custom) === null || ref4 === void 0 ? void 0 : ref4.some(function(customField) {
265
+ var ref, ref5;
266
+ return (ref = cat.resource) === null || ref === void 0 ? void 0 : (ref5 = ref.custom) === null || ref5 === void 0 ? void 0 : ref5.some(function(customField) {
265
267
  return customField.field === 'isTemporary';
266
268
  });
267
269
  })) {
268
- var ref2;
270
+ var ref3;
269
271
  var cats = categories.reduce(function(result, category) {
270
272
  result[category.resourceId] = _objectSpread({}, category.resource, {
271
273
  hasChildCategories: false
@@ -285,8 +287,8 @@ export var formatCategories = function(categories, rootCategoryId) {
285
287
  ]);
286
288
  return result;
287
289
  }, {});
288
- var ref3;
289
- var mainPaths = (ref2 = Object.values(cats).filter(function(category) {
290
+ var ref4;
291
+ var mainPaths = (ref3 = Object.values(cats).filter(function(category) {
290
292
  return category.hasChildCategories === false;
291
293
  }).map(function(category) {
292
294
  return paths1 === null || paths1 === void 0 ? void 0 : paths1[category._id];
@@ -296,22 +298,22 @@ export var formatCategories = function(categories, rootCategoryId) {
296
298
  });
297
299
  }).filter(function(paths) {
298
300
  return !paths.some(function(path) {
299
- var ref, ref6;
300
- return (ref3 = (ref6 = path === null || path === void 0 ? void 0 : (ref = path.custom) === null || ref === void 0 ? void 0 : ref.find(function(custom) {
301
+ var ref, ref7;
302
+ return (ref4 = (ref7 = path === null || path === void 0 ? void 0 : (ref = path.custom) === null || ref === void 0 ? void 0 : ref.find(function(custom) {
301
303
  return custom.field === 'isTemporary';
302
- })) === null || ref6 === void 0 ? void 0 : ref6.value) !== null && ref3 !== void 0 ? ref3 : false;
304
+ })) === null || ref7 === void 0 ? void 0 : ref7.value) !== null && ref4 !== void 0 ? ref4 : false;
303
305
  });
304
- })) === null || ref2 === void 0 ? void 0 : ref2[0].flat();
306
+ })) === null || ref3 === void 0 ? void 0 : ref3[0].flat();
305
307
  results = mainPaths;
306
308
  } else {
307
309
  results = categories === null || categories === void 0 ? void 0 : categories.filter(function(cat) {
308
- var ref, ref7;
309
- return (cat === null || cat === void 0 ? void 0 : cat.resourceId) === rootCategoryId || (cat === null || cat === void 0 ? void 0 : (ref = cat.resource) === null || ref === void 0 ? void 0 : (ref7 = ref.ancestors) === null || ref7 === void 0 ? void 0 : ref7.some(function(ancestor) {
310
+ var ref, ref8;
311
+ return (cat === null || cat === void 0 ? void 0 : cat.resourceId) === rootCategoryId || (cat === null || cat === void 0 ? void 0 : (ref = cat.resource) === null || ref === void 0 ? void 0 : (ref8 = ref.ancestors) === null || ref8 === void 0 ? void 0 : ref8.some(function(ancestor) {
310
312
  return ancestor.resource === rootCategoryId;
311
313
  }));
312
314
  });
313
315
  }
314
- var formattedResults = (ref5 = results) === null || ref5 === void 0 ? void 0 : ref5.map(function(category) {
316
+ var formattedResults = (ref6 = results) === null || ref6 === void 0 ? void 0 : ref6.map(function(category) {
315
317
  if (category.resource) {
316
318
  var resource = category.resource;
317
319
  return {
@@ -343,3 +345,27 @@ export var createLabelsMap = function(data) {
343
345
  return el.key;
344
346
  });
345
347
  };
348
+ // object of objects to array of objects remapping for attributes of line items from catalog search api
349
+ export function remapLineItemAttributes(attributes) {
350
+ var arr = [];
351
+ Object.keys(attributes).forEach(function(key) {
352
+ // handles the remapping for lineItem.variantAttributes or lineItem[index].variantAttributes
353
+ if (Array.isArray(attributes[key])) {
354
+ attributes[key].forEach(function(attr, index) {
355
+ arr.push(_objectSpread({
356
+ attributeName: key,
357
+ name: key,
358
+ data: attributes[key][index],
359
+ valueData: attributes[key][index]
360
+ }, attributes[key][index]));
361
+ });
362
+ } else {
363
+ arr.push({
364
+ name: key,
365
+ data: attributes[key][0],
366
+ value: attributes[key][0]
367
+ });
368
+ }
369
+ });
370
+ return arr;
371
+ }