@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
@@ -10,134 +10,49 @@ var _ = require("../../");
10
10
  var _utils = require("./utils");
11
11
  var _productsApi = require("../../api/productsApi");
12
12
  var _assetsToMap = require("../../utils/assetsToMap");
13
- function _arrayLikeToArray(arr, len) {
14
- if (len == null || len > arr.length) len = arr.length;
15
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
16
- return arr2;
17
- }
18
- function _arrayWithHoles(arr) {
19
- if (Array.isArray(arr)) return arr;
20
- }
21
- function _arrayWithoutHoles(arr) {
22
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
23
- }
24
- function _defineProperty(obj, key, value) {
25
- if (key in obj) {
26
- Object.defineProperty(obj, key, {
27
- value: value,
28
- enumerable: true,
29
- configurable: true,
30
- writable: true
31
- });
32
- } else {
33
- obj[key] = value;
34
- }
35
- return obj;
36
- }
13
+ var _useProductVariants = require("../useProductVariants");
37
14
  function _interopRequireDefault(obj) {
38
15
  return obj && obj.__esModule ? obj : {
39
16
  default: obj
40
17
  };
41
18
  }
42
- function _iterableToArray(iter) {
43
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
44
- }
45
- function _iterableToArrayLimit(arr, i) {
46
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
47
- if (_i == null) return;
48
- var _arr = [];
49
- var _n = true;
50
- var _d = false;
51
- var _s, _e;
52
- try {
53
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
54
- _arr.push(_s.value);
55
- if (i && _arr.length === i) break;
56
- }
57
- } catch (err) {
58
- _d = true;
59
- _e = err;
60
- } finally{
61
- try {
62
- if (!_n && _i["return"] != null) _i["return"]();
63
- } finally{
64
- if (_d) throw _e;
65
- }
66
- }
67
- return _arr;
68
- }
69
- function _nonIterableRest() {
70
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
71
- }
72
- function _nonIterableSpread() {
73
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
74
- }
75
- function _objectSpread(target) {
76
- for(var i = 1; i < arguments.length; i++){
77
- var source = arguments[i] != null ? arguments[i] : {};
78
- var ownKeys = Object.keys(source);
79
- if (typeof Object.getOwnPropertySymbols === "function") {
80
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
81
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
82
- }));
83
- }
84
- ownKeys.forEach(function(key) {
85
- _defineProperty(target, key, source[key]);
86
- });
87
- }
88
- return target;
89
- }
90
- function _slicedToArray(arr, i) {
91
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
92
- }
93
- function _toConsumableArray(arr) {
94
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
95
- }
96
- function _unsupportedIterableToArray(o, minLen) {
97
- if (!o) return;
98
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
99
- var n = Object.prototype.toString.call(o).slice(8, -1);
100
- if (n === "Object" && o.constructor) n = o.constructor.name;
101
- if (n === "Map" || n === "Set") return Array.from(n);
102
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
103
- }
104
19
  var ProductStateContext = /*#__PURE__*/ _react.default.createContext(undefined);
105
20
  var CountDispatchContext = /*#__PURE__*/ _react.default.createContext(undefined);
106
21
  function ProductProvider(param) {
107
22
  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
- var ref1 = _slicedToArray(_react.default.useState(getCombinationsAndAttributeRules), 2), ref2 = ref1[0], combinations = ref2.combinations, attributeRules = ref2.attributeRules, setCombinationsAndAttributeRules = ref1[1];
110
- var ref3 = _slicedToArray(_react.default.useState(getVariantsWithInventory), 2), variants = ref3[0], setVariants = ref3[1];
111
- var ref4 = _slicedToArray(_react.default.useState(getDefaultVariant), 2), selectedVariant = ref4[0], setSelectedVariant = ref4[1];
23
+ var ref38 = (0, _useProductVariants).useProductVariants({
24
+ product: product,
25
+ defaultVariantId: defaultVariantId
26
+ }), 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;
112
27
  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, ref36, ref37, ref38, ref39, ref40, ref41;
28
+ 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;
114
29
  var rootCategory = product === null || product === void 0 ? void 0 : (ref = product.categories) === null || ref === void 0 ? void 0 : ref[0];
115
30
  var rootCategoryId = rootCategory === null || rootCategory === void 0 ? void 0 : rootCategory.resourceId;
116
31
  var metaObj = {
117
32
  _id: product === null || product === void 0 ? void 0 : product._id,
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),
33
+ 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((0, _).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((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
34
  slug: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.slug),
120
35
  description: (0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.description) || (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.description),
121
36
  shortDescription: (0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.metaDescription) || (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : product.metaDescription),
122
37
  brand: {
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
38
+ _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,
39
+ name: (0, _).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),
40
+ slug: (0, _).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),
41
+ 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
127
42
  },
128
43
  category: {
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)
44
+ _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,
45
+ name: (0, _).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),
46
+ slug: (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.slug)
132
47
  },
133
48
  rootCategory: {
134
49
  _id: rootCategoryId,
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)
50
+ name: (0, _).getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (ref33 = rootCategory.resource) === null || ref33 === void 0 ? void 0 : ref33.name),
51
+ slug: (0, _).getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (ref34 = rootCategory.resource) === null || ref34 === void 0 ? void 0 : ref34.slug)
137
52
  },
138
53
  categories: (0, _utils).formatCategories(product === null || product === void 0 ? void 0 : product.categories, rootCategoryId),
139
54
  reviewRatingStatistics: product === null || product === void 0 ? void 0 : product.reviewRatingStatistics,
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),
55
+ content: Boolean(selectedVariant === null || selectedVariant === void 0 ? void 0 : (ref35 = selectedVariant.content) === null || ref35 === void 0 ? void 0 : ref35.map(_utils.createProductContent).length) ? selectedVariant === null || selectedVariant === void 0 ? void 0 : (ref36 = selectedVariant.content) === null || ref36 === void 0 ? void 0 : ref36.map(_utils.createProductContent) : product === null || product === void 0 ? void 0 : (ref37 = product.content) === null || ref37 === void 0 ? void 0 : ref37.map(_utils.createProductContent),
141
56
  assets: (0, _assetsToMap).assetsFieldsToMap(product === null || product === void 0 ? void 0 : product.assets)
142
57
  };
143
58
  return metaObj;
@@ -165,180 +80,6 @@ function ProductProvider(param) {
165
80
  product === null || product === void 0 ? void 0 : product.metaTitle,
166
81
  selectedVariant,
167
82
  ]);
168
- var customFields = _react.default.useMemo(function() {
169
- var mappedFields = (0, _utils).createCustomFieldsMap(product === null || product === void 0 ? void 0 : product.custom);
170
- return mappedFields;
171
- }, [
172
- product === null || product === void 0 ? void 0 : product.custom
173
- ]);
174
- _react.default.useEffect(function() {
175
- // prevent unnecessary calculations
176
- if (mounted) {
177
- setVariants(getVariantsWithInventory());
178
- }
179
- }, [
180
- product
181
- ]);
182
- _react.default.useMemo(function() {
183
- // prevent unnecessary calculations
184
- if (!mounted) {
185
- return setMounted(true);
186
- }
187
- var data = getCombinationsAndAttributeRules();
188
- setCombinationsAndAttributeRules(data);
189
- }, [
190
- variants
191
- ]);
192
- function getVariantsWithInventory() {
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
- var currentVariant = arr[index];
197
- var mappedAttributes = (0, _utils).createMappedAttributes(currentVariant);
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 : (ref47 = currentVariant.inventorySnapshot) === null || ref47 === void 0 ? void 0 : ref47.canOrder;
200
- var updatedVariant = _objectSpread({}, currentVariant, {
201
- inventory: {
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
- },
205
- isAvailable: isAvailable ? true : false,
206
- quantity: isAvailable ? currentVariant === null || currentVariant === void 0 ? void 0 : (ref45 = currentVariant.inventorySnapshot) === null || ref45 === void 0 ? void 0 : ref45.availableQuantity : 0,
207
- attributes: mappedAttributes,
208
- options: mappedOptions,
209
- selectedOptions: [],
210
- labels: (0, _utils).createLabelsMap(currentVariant.labels),
211
- getAttribute: function(rule) {
212
- return getSelectedAttribute(rule, mappedAttributes);
213
- },
214
- getAttributeByKey: function(key) {
215
- var ref;
216
- return (ref = mappedAttributes.find(function(a) {
217
- return a.name === key;
218
- })) === null || ref === void 0 ? void 0 : ref.value;
219
- },
220
- getAvailabilityByStore: function() {
221
- var ref;
222
- return (0, _utils).processAvailabilityPerStore(currentVariant === null || currentVariant === void 0 ? void 0 : (ref = currentVariant.inventorySnapshot) === null || ref === void 0 ? void 0 : ref.availabilities);
223
- }
224
- });
225
- map[currentVariant._id] = updatedVariant;
226
- return map;
227
- }, {});
228
- return variantsWithInventory || {};
229
- }
230
- function getCombinationsAndAttributeRules() {
231
- var mappedAttributeRules = (0, _utils).createAttributeRulesMap(product);
232
- var attributesWithId = Object.keys(variants || {}).map(function(key) {
233
- return {
234
- variantId: variants === null || variants === void 0 ? void 0 : variants[key]._id,
235
- attributes: variants === null || variants === void 0 ? void 0 : variants[key].attributes
236
- };
237
- });
238
- var combinationsMap = (0, _utils).createCombinationsMap(Object.keys(mappedAttributeRules), attributesWithId);
239
- (0, _utils).assignCombinationsToAttributeRules(mappedAttributeRules, combinationsMap);
240
- return {
241
- combinations: combinationsMap,
242
- attributeRules: mappedAttributeRules
243
- };
244
- }
245
- function getDefaultVariant() {
246
- if (!defaultVariantId) return null;
247
- return variants[defaultVariantId];
248
- }
249
- function selectVariantById(id) {
250
- setSelectedVariant(variants[id]);
251
- }
252
- function selectVariantByAttribute(key) {
253
- var ref;
254
- // Get by collapseKey for SD
255
- var split = key.split(':');
256
- if (split[0] === 'collapseKey') {
257
- var id = Object.keys(variants).find(function(el) {
258
- return variants[el].collapseKey === split[1];
259
- });
260
- return setSelectedVariant(variants[id]);
261
- }
262
- var id1 = (ref = combinations[key]) === null || ref === void 0 ? void 0 : ref.value;
263
- setSelectedVariant(variants[id1]);
264
- }
265
- function selectVariantByCombination(key, value) {
266
- // Take collapseKey for SD
267
- var split = value.split(':');
268
- if (split[0] === 'collapseKey') {
269
- var id = Object.keys(variants).find(function(el) {
270
- var ref;
271
- return variants[el].collapseKey === split[1] && ((ref = variants[el].attributes.find(function(attr) {
272
- return attr.name === 'size';
273
- })) === null || ref === void 0 ? void 0 : ref.value) === key;
274
- });
275
- return setSelectedVariant(variants[id]);
276
- }
277
- var id2 = combinations[key].params[value];
278
- setSelectedVariant(variants[id2]);
279
- }
280
- function selectVariantOptions(definitionKey, optionKey) {
281
- if (selectedVariant) {
282
- var newSelectedVariant = _objectSpread({}, selectedVariant);
283
- newSelectedVariant.selectedOptions = newSelectedVariant.selectedOptions.filter(function(opt) {
284
- return opt.definitionKey !== definitionKey;
285
- });
286
- newSelectedVariant.selectedOptions = _toConsumableArray(newSelectedVariant.selectedOptions).concat([
287
- {
288
- definitionKey: definitionKey,
289
- optionKey: optionKey
290
- },
291
- ]);
292
- newSelectedVariant.mappedSelectedOptions = newSelectedVariant.selectedOptions.map(function(option) {
293
- return (0, _utils).createSelectedOption2(newSelectedVariant.options, option);
294
- });
295
- setSelectedVariant(newSelectedVariant);
296
- }
297
- }
298
- function getSelectedAttribute(rule, attributes) {
299
- var ref;
300
- var attributeRule = (ref = attributeRules[rule]) === null || ref === void 0 ? void 0 : ref.values;
301
- var result;
302
- attributes.forEach(function(currentKey) {
303
- var found = attributeRule === null || attributeRule === void 0 ? void 0 : attributeRule[currentKey.value];
304
- if (found) result = _objectSpread({
305
- id: currentKey.value,
306
- name: rule
307
- }, found);
308
- });
309
- return result;
310
- }
311
- function getVariantById(id) {
312
- return variants === null || variants === void 0 ? void 0 : variants[id];
313
- }
314
- function getVariantByAttribute(key) {
315
- var ref;
316
- var id = (ref = combinations[key]) === null || ref === void 0 ? void 0 : ref.value;
317
- return variants === null || variants === void 0 ? void 0 : variants[id];
318
- }
319
- function getVariantByCombination(key, value) {
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];
333
- }
334
- function getCustomFieldValue(field) {
335
- return customFields === null || customFields === void 0 ? void 0 : customFields[field];
336
- }
337
- function getCombinationsForAttributeRule(key, 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];
340
- return result;
341
- }
342
83
  var collapsedImages = (0, _utils).createCollapseKeyImagesMap(product);
343
84
  var state = {
344
85
  metaData: metaData,
@@ -1,6 +1,7 @@
1
1
  Object.defineProperty(exports, "__esModule", {
2
2
  value: true
3
3
  });
4
+ exports.remapLineItemAttributes = remapLineItemAttributes;
4
5
  exports.createLabelsMap = exports.formatCategories = exports.getProductVideos = exports.processAvailabilityPerStore = exports.createMappedAttributes = exports.createSelectedOption = exports.createSelectedOption2 = exports.createMappedOptions = exports.createAttributeRulesMap = exports.createCollapseKeyImagesMap = exports.createProductContent = exports.assignCombinationsToAttributeRules = exports.createCombinationsMap = exports.createCustomFieldsMap = void 0;
5
6
  var _sdk = require("@sentecacommerce/sdk");
6
7
  var _createEmbededVideo = require("./createEmbededVideo");
@@ -123,8 +124,9 @@ var createCollapseKeyImagesMap = function(product) {
123
124
  };
124
125
  exports.createCollapseKeyImagesMap = createCollapseKeyImagesMap;
125
126
  var createAttributeRulesMap = function(product) {
127
+ var isLineItem = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
126
128
  var ref, ref1;
127
- var uniqueRules = product === null || product === void 0 ? void 0 : (ref = product.attributeRules) === null || ref === void 0 ? void 0 : ref.filter(function(x) {
129
+ 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) {
128
130
  return x.constraint === _sdk.AttributeRuleDTOConstraintEnum.CombinationUnique;
129
131
  });
130
132
  var reduceVariantsToAttributeRuleValues = function(map, attribute) {
@@ -148,7 +150,7 @@ var createAttributeRulesMap = function(product) {
148
150
  return map;
149
151
  };
150
152
  var mappedAttributeRules = product === null || product === void 0 ? void 0 : (ref1 = product.variants) === null || ref1 === void 0 ? void 0 : ref1.map(function(v) {
151
- return v.attributes;
153
+ return isLineItem ? remapLineItemAttributes(v.attributes) : v.attributes;
152
154
  }).flat().reduce(reduceVariantsToAttributeRuleValues, {});
153
155
  return mappedAttributeRules;
154
156
  };
@@ -208,12 +210,13 @@ var createSelectedOption = function(options, selectedOption) {
208
210
  };
209
211
  exports.createSelectedOption = createSelectedOption;
210
212
  var createMappedAttributes = function(currentVariant) {
211
- var ref;
212
- var mappedAttributes = ((ref = currentVariant.attributes) === null || ref === void 0 ? void 0 : ref.reduce(function(attributeArray, attribute) {
213
+ var isLineItem = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
214
+ var ref, ref2;
215
+ 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) {
213
216
  attributeArray.push({
214
217
  name: attribute.name,
215
218
  value: attribute.value,
216
- valueData: attribute.valueData
219
+ valueData: isLineItem ? attribute : attribute.valueData
217
220
  });
218
221
  return attributeArray;
219
222
  }, [])) || [];
@@ -254,15 +257,15 @@ var getProductVideos = function(assets) {
254
257
  };
255
258
  exports.getProductVideos = getProductVideos;
256
259
  var formatCategories = function(categories, rootCategoryId) {
257
- var ref5;
260
+ var ref6;
258
261
  var results;
259
262
  if (categories === null || categories === void 0 ? void 0 : categories.some(function(cat) {
260
- var ref, ref4;
261
- return (ref = cat.resource) === null || ref === void 0 ? void 0 : (ref4 = ref.custom) === null || ref4 === void 0 ? void 0 : ref4.some(function(customField) {
263
+ var ref, ref5;
264
+ return (ref = cat.resource) === null || ref === void 0 ? void 0 : (ref5 = ref.custom) === null || ref5 === void 0 ? void 0 : ref5.some(function(customField) {
262
265
  return customField.field === 'isTemporary';
263
266
  });
264
267
  })) {
265
- var ref2;
268
+ var ref3;
266
269
  var cats = categories.reduce(function(result, category) {
267
270
  result[category.resourceId] = _objectSpread({}, category.resource, {
268
271
  hasChildCategories: false
@@ -282,8 +285,8 @@ var formatCategories = function(categories, rootCategoryId) {
282
285
  ]);
283
286
  return result;
284
287
  }, {});
285
- var ref3;
286
- var mainPaths = (ref2 = Object.values(cats).filter(function(category) {
288
+ var ref4;
289
+ var mainPaths = (ref3 = Object.values(cats).filter(function(category) {
287
290
  return category.hasChildCategories === false;
288
291
  }).map(function(category) {
289
292
  return paths1 === null || paths1 === void 0 ? void 0 : paths1[category._id];
@@ -293,22 +296,22 @@ var formatCategories = function(categories, rootCategoryId) {
293
296
  });
294
297
  }).filter(function(paths) {
295
298
  return !paths.some(function(path) {
296
- var ref, ref6;
297
- return (ref3 = (ref6 = path === null || path === void 0 ? void 0 : (ref = path.custom) === null || ref === void 0 ? void 0 : ref.find(function(custom) {
299
+ var ref, ref7;
300
+ return (ref4 = (ref7 = path === null || path === void 0 ? void 0 : (ref = path.custom) === null || ref === void 0 ? void 0 : ref.find(function(custom) {
298
301
  return custom.field === 'isTemporary';
299
- })) === null || ref6 === void 0 ? void 0 : ref6.value) !== null && ref3 !== void 0 ? ref3 : false;
302
+ })) === null || ref7 === void 0 ? void 0 : ref7.value) !== null && ref4 !== void 0 ? ref4 : false;
300
303
  });
301
- })) === null || ref2 === void 0 ? void 0 : ref2[0].flat();
304
+ })) === null || ref3 === void 0 ? void 0 : ref3[0].flat();
302
305
  results = mainPaths;
303
306
  } else {
304
307
  results = categories === null || categories === void 0 ? void 0 : categories.filter(function(cat) {
305
- var ref, ref7;
306
- 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) {
308
+ var ref, ref8;
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 : (ref8 = ref.ancestors) === null || ref8 === void 0 ? void 0 : ref8.some(function(ancestor) {
307
310
  return ancestor.resource === rootCategoryId;
308
311
  }));
309
312
  });
310
313
  }
311
- var formattedResults = (ref5 = results) === null || ref5 === void 0 ? void 0 : ref5.map(function(category) {
314
+ var formattedResults = (ref6 = results) === null || ref6 === void 0 ? void 0 : ref6.map(function(category) {
312
315
  if (category.resource) {
313
316
  var resource = category.resource;
314
317
  return {
@@ -342,3 +345,26 @@ var createLabelsMap = function(data) {
342
345
  });
343
346
  };
344
347
  exports.createLabelsMap = createLabelsMap;
348
+ function remapLineItemAttributes(attributes) {
349
+ var arr = [];
350
+ Object.keys(attributes).forEach(function(key) {
351
+ // handles the remapping for lineItem.variantAttributes or lineItem[index].variantAttributes
352
+ if (Array.isArray(attributes[key])) {
353
+ attributes[key].forEach(function(attr, index) {
354
+ arr.push(_objectSpread({
355
+ attributeName: key,
356
+ name: key,
357
+ data: attributes[key][index],
358
+ valueData: attributes[key][index]
359
+ }, attributes[key][index]));
360
+ });
361
+ } else {
362
+ arr.push({
363
+ name: key,
364
+ data: attributes[key][0],
365
+ value: attributes[key][0]
366
+ });
367
+ }
368
+ });
369
+ return arr;
370
+ }