@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.
@@ -0,0 +1,293 @@
1
+ import React from 'react';
2
+ import { assignCombinationsToAttributeRules, createCombinationsMap, createAttributeRulesMap, createMappedAttributes, processAvailabilityPerStore, createMappedOptions, createSelectedOption2, createLabelsMap, createCustomFieldsMap, remapLineItemAttributes } from '../useProduct/utils';
3
+ function _arrayLikeToArray(arr, len) {
4
+ if (len == null || len > arr.length) len = arr.length;
5
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
6
+ return arr2;
7
+ }
8
+ function _arrayWithHoles(arr) {
9
+ if (Array.isArray(arr)) return arr;
10
+ }
11
+ function _arrayWithoutHoles(arr) {
12
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
13
+ }
14
+ function _defineProperty(obj, key, value) {
15
+ if (key in obj) {
16
+ Object.defineProperty(obj, key, {
17
+ value: value,
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true
21
+ });
22
+ } else {
23
+ obj[key] = value;
24
+ }
25
+ return obj;
26
+ }
27
+ function _iterableToArray(iter) {
28
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
29
+ }
30
+ function _iterableToArrayLimit(arr, i) {
31
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
32
+ if (_i == null) return;
33
+ var _arr = [];
34
+ var _n = true;
35
+ var _d = false;
36
+ var _s, _e;
37
+ try {
38
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
39
+ _arr.push(_s.value);
40
+ if (i && _arr.length === i) break;
41
+ }
42
+ } catch (err) {
43
+ _d = true;
44
+ _e = err;
45
+ } finally{
46
+ try {
47
+ if (!_n && _i["return"] != null) _i["return"]();
48
+ } finally{
49
+ if (_d) throw _e;
50
+ }
51
+ }
52
+ return _arr;
53
+ }
54
+ function _nonIterableRest() {
55
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
56
+ }
57
+ function _nonIterableSpread() {
58
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
59
+ }
60
+ function _objectSpread(target) {
61
+ for(var i = 1; i < arguments.length; i++){
62
+ var source = arguments[i] != null ? arguments[i] : {};
63
+ var ownKeys = Object.keys(source);
64
+ if (typeof Object.getOwnPropertySymbols === "function") {
65
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
66
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
67
+ }));
68
+ }
69
+ ownKeys.forEach(function(key) {
70
+ _defineProperty(target, key, source[key]);
71
+ });
72
+ }
73
+ return target;
74
+ }
75
+ function _slicedToArray(arr, i) {
76
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
77
+ }
78
+ function _toConsumableArray(arr) {
79
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
80
+ }
81
+ function _unsupportedIterableToArray(o, minLen) {
82
+ if (!o) return;
83
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
84
+ var n = Object.prototype.toString.call(o).slice(8, -1);
85
+ if (n === "Object" && o.constructor) n = o.constructor.name;
86
+ if (n === "Map" || n === "Set") return Array.from(n);
87
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
88
+ }
89
+ export * from './types';
90
+ export var useProductVariants = function(param) {
91
+ var product = param.product, defaultVariantId = param.defaultVariantId, _isLineItem = param.isLineItem, isLineItem = _isLineItem === void 0 ? false : _isLineItem;
92
+ var getVariantsWithInventory = function getVariantsWithInventory() {
93
+ var ref9;
94
+ if (isLineItem) {
95
+ var innerProduct = JSON.parse(JSON.stringify(product));
96
+ delete innerProduct.variants;
97
+ product.variants.unshift(innerProduct);
98
+ }
99
+ var variantsWithInventory = product === null || product === void 0 ? void 0 : (ref9 = product.variants) === null || ref9 === void 0 ? void 0 : ref9.reduce(function(map, _, index, arr) {
100
+ var ref10, ref5, ref6, ref7, ref8;
101
+ var currentVariant = arr[index];
102
+ if (isLineItem && !Array.isArray((ref10 = currentVariant) === null || ref10 === void 0 ? void 0 : ref10.variantAttributes)) {
103
+ currentVariant.variantAttributes = remapLineItemAttributes(currentVariant.variantAttributes);
104
+ }
105
+ var mappedAttributes = createMappedAttributes(currentVariant, isLineItem);
106
+ var mappedOptions = createMappedOptions(currentVariant === null || currentVariant === void 0 ? void 0 : currentVariant.availableOptions) || [];
107
+ var isAvailable = currentVariant === null || currentVariant === void 0 ? void 0 : (ref5 = currentVariant.inventorySnapshot) === null || ref5 === void 0 ? void 0 : ref5.canOrder;
108
+ var updatedVariant = _objectSpread({}, currentVariant, {
109
+ inventory: {
110
+ hasAvailableQuantity: (ref6 = currentVariant.inventorySnapshot) === null || ref6 === void 0 ? void 0 : ref6.canOrder,
111
+ availableQuantity: (ref7 = currentVariant.inventorySnapshot) === null || ref7 === void 0 ? void 0 : ref7.availableQuantity
112
+ },
113
+ isAvailable: isAvailable ? true : false,
114
+ quantity: isAvailable ? currentVariant === null || currentVariant === void 0 ? void 0 : (ref8 = currentVariant.inventorySnapshot) === null || ref8 === void 0 ? void 0 : ref8.availableQuantity : 0,
115
+ attributes: mappedAttributes,
116
+ options: mappedOptions,
117
+ selectedOptions: [],
118
+ labels: createLabelsMap(currentVariant.labels),
119
+ getAttribute: function(rule) {
120
+ return getSelectedAttribute(rule, mappedAttributes);
121
+ },
122
+ getAttributeByKey: function(key) {
123
+ var ref;
124
+ return (ref = mappedAttributes.find(function(a) {
125
+ return a.name === key;
126
+ })) === null || ref === void 0 ? void 0 : ref.value;
127
+ },
128
+ getAvailabilityByStore: function() {
129
+ var ref;
130
+ return processAvailabilityPerStore(currentVariant === null || currentVariant === void 0 ? void 0 : (ref = currentVariant.inventorySnapshot) === null || ref === void 0 ? void 0 : ref.availabilities);
131
+ }
132
+ });
133
+ map[isLineItem ? currentVariant.variantId : currentVariant._id] = updatedVariant;
134
+ return map;
135
+ }, {});
136
+ return variantsWithInventory || {};
137
+ };
138
+ var getCombinationsAndAttributeRules = function getCombinationsAndAttributeRules() {
139
+ if (isLineItem && !(product === null || product === void 0 ? void 0 : product.attributeRules)) {
140
+ product.attributeRules = remapLineItemAttributes(product === null || product === void 0 ? void 0 : product.attributes);
141
+ }
142
+ var mappedAttributeRules = createAttributeRulesMap(product, isLineItem);
143
+ var attributesWithId = Object.keys(variants || {}).map(function(key) {
144
+ return {
145
+ variantId: isLineItem ? (variants === null || variants === void 0 ? void 0 : variants[key]).variantId : variants === null || variants === void 0 ? void 0 : variants[key]._id,
146
+ attributes: isLineItem && !Array.isArray(variants === null || variants === void 0 ? void 0 : variants[key].attributes) ? remapLineItemAttributes(variants === null || variants === void 0 ? void 0 : variants[key].attributes) : variants === null || variants === void 0 ? void 0 : variants[key].attributes
147
+ };
148
+ });
149
+ var combinationsMap = createCombinationsMap(Object.keys(mappedAttributeRules), attributesWithId);
150
+ assignCombinationsToAttributeRules(mappedAttributeRules, combinationsMap);
151
+ return {
152
+ combinations: combinationsMap,
153
+ attributeRules: mappedAttributeRules
154
+ };
155
+ };
156
+ var getDefaultVariant = function getDefaultVariant() {
157
+ if (!defaultVariantId) return null;
158
+ return variants[defaultVariantId];
159
+ };
160
+ var selectVariantById = function selectVariantById(id) {
161
+ setSelectedVariant(variants[id]);
162
+ };
163
+ var selectVariantByCombination = function selectVariantByCombination(key, value) {
164
+ // Take collapseKey for SD
165
+ var split = value.split(':');
166
+ if (split[0] === 'collapseKey') {
167
+ var id = Object.keys(variants).find(function(el) {
168
+ var ref;
169
+ return variants[el].collapseKey === split[1] && ((ref = variants[el].attributes.find(function(attr) {
170
+ return attr.name === 'size';
171
+ })) === null || ref === void 0 ? void 0 : ref.value) === key;
172
+ });
173
+ return setSelectedVariant(variants[id]);
174
+ }
175
+ var id1 = combinations[key].params[value];
176
+ setSelectedVariant(variants[id1]);
177
+ };
178
+ var selectVariantByAttribute = function selectVariantByAttribute(key) {
179
+ var ref;
180
+ // Get by collapseKey for SD
181
+ var split = key.split(':');
182
+ if (split[0] === 'collapseKey') {
183
+ var id = Object.keys(variants).find(function(el) {
184
+ return variants[el].collapseKey === split[1];
185
+ });
186
+ return setSelectedVariant(variants[id]);
187
+ }
188
+ var id2 = (ref = combinations[key]) === null || ref === void 0 ? void 0 : ref.value;
189
+ setSelectedVariant(variants[id2]);
190
+ };
191
+ var getVariantByCombination = function getVariantByCombination(key, value) {
192
+ var ref11;
193
+ var split = value === null || value === void 0 ? void 0 : value.split(':');
194
+ if ((split === null || split === void 0 ? void 0 : split[0]) === 'collapseKey') {
195
+ var id = Object.keys(variants).find(function(el) {
196
+ var ref;
197
+ return variants[el].collapseKey === (split === null || split === void 0 ? void 0 : split[1]) && ((ref = variants[el].attributes.find(function(attr) {
198
+ return attr.name === 'size';
199
+ })) === null || ref === void 0 ? void 0 : ref.value) === key;
200
+ });
201
+ return variants[id];
202
+ }
203
+ var id3 = (ref11 = combinations[key]) === null || ref11 === void 0 ? void 0 : ref11.params[value];
204
+ return variants === null || variants === void 0 ? void 0 : variants[id3];
205
+ };
206
+ var getSelectedAttribute = function getSelectedAttribute(rule, attributes) {
207
+ var ref;
208
+ var attributeRule = (ref = attributeRules[rule]) === null || ref === void 0 ? void 0 : ref.values;
209
+ var result;
210
+ attributes.forEach(function(currentKey) {
211
+ var found = attributeRule === null || attributeRule === void 0 ? void 0 : attributeRule[currentKey.value];
212
+ if (found) result = _objectSpread({
213
+ id: currentKey.value,
214
+ name: rule
215
+ }, found);
216
+ });
217
+ return result;
218
+ };
219
+ var getVariantById = function getVariantById(id) {
220
+ return variants === null || variants === void 0 ? void 0 : variants[id];
221
+ };
222
+ var getVariantByAttribute = function getVariantByAttribute(key) {
223
+ var ref;
224
+ var id = (ref = combinations[key]) === null || ref === void 0 ? void 0 : ref.value;
225
+ return variants === null || variants === void 0 ? void 0 : variants[id];
226
+ };
227
+ var getCombinationsForAttributeRule = function getCombinationsForAttributeRule(key, id) {
228
+ var ref, ref12;
229
+ 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];
230
+ return result;
231
+ };
232
+ var selectVariantOptions = function selectVariantOptions(definitionKey, optionKey) {
233
+ if (selectedVariant) {
234
+ var newSelectedVariant = _objectSpread({}, selectedVariant);
235
+ newSelectedVariant.selectedOptions = newSelectedVariant.selectedOptions.filter(function(opt) {
236
+ return opt.definitionKey !== definitionKey;
237
+ });
238
+ newSelectedVariant.selectedOptions = _toConsumableArray(newSelectedVariant.selectedOptions).concat([
239
+ {
240
+ definitionKey: definitionKey,
241
+ optionKey: optionKey
242
+ },
243
+ ]);
244
+ newSelectedVariant.mappedSelectedOptions = newSelectedVariant.selectedOptions.map(function(option) {
245
+ return createSelectedOption2(newSelectedVariant.options, option);
246
+ });
247
+ setSelectedVariant(newSelectedVariant);
248
+ }
249
+ };
250
+ var getCustomFieldValue = function getCustomFieldValue(field) {
251
+ return customFields === null || customFields === void 0 ? void 0 : customFields[field];
252
+ };
253
+ var ref4 = _slicedToArray(React.useState(getCombinationsAndAttributeRules), 2), ref1 = ref4[0], combinations = ref1.combinations, attributeRules = ref1.attributeRules, setCombinationsAndAttributeRules = ref4[1];
254
+ var ref2 = _slicedToArray(React.useState(getVariantsWithInventory), 2), variants = ref2[0], setVariants = ref2[1];
255
+ var ref3 = _slicedToArray(React.useState(getDefaultVariant), 2), selectedVariant = ref3[0], setSelectedVariant = ref3[1];
256
+ React.useEffect(function() {
257
+ setVariants(getVariantsWithInventory());
258
+ }, [
259
+ product
260
+ ]);
261
+ React.useMemo(function() {
262
+ if (Object.keys(variants).length) {
263
+ var data = getCombinationsAndAttributeRules();
264
+ setCombinationsAndAttributeRules(data);
265
+ }
266
+ }, [
267
+ variants
268
+ ]);
269
+ var customFields = React.useMemo(function() {
270
+ var mappedFields = createCustomFieldsMap(product === null || product === void 0 ? void 0 : product.custom);
271
+ return mappedFields;
272
+ }, [
273
+ product === null || product === void 0 ? void 0 : product.custom
274
+ ]);
275
+ return {
276
+ combinations: combinations,
277
+ attributeRules: attributeRules,
278
+ variants: variants,
279
+ selectedVariant: selectedVariant,
280
+ setSelectedVariant: setSelectedVariant,
281
+ customFields: customFields,
282
+ getVariantByAttribute: getVariantByAttribute,
283
+ getVariantById: getVariantById,
284
+ getCombinationsAndAttributeRules: getCombinationsAndAttributeRules,
285
+ getCombinationsForAttributeRule: getCombinationsForAttributeRule,
286
+ getVariantByCombination: getVariantByCombination,
287
+ getCustomFieldValue: getCustomFieldValue,
288
+ selectVariantByAttribute: selectVariantByAttribute,
289
+ selectVariantByCombination: selectVariantByCombination,
290
+ selectVariantOptions: selectVariantOptions,
291
+ selectVariantById: selectVariantById
292
+ };
293
+ };
@@ -0,0 +1 @@
1
+ export { };
package/dist/esm/index.js CHANGED
@@ -92,6 +92,7 @@ export * from './hooks/useRouterRedirect';
92
92
  export * from './hooks/useProgressBar';
93
93
  export * from './hooks/useCatalogDiscounts';
94
94
  export * from './hooks/useLocalRating';
95
+ export * from './hooks/useProductVariants/types';
95
96
  // Utils
96
97
  export * from './utils';
97
98
  export * from './types';
@@ -143,6 +143,7 @@ export var useListingQuery = function() {
143
143
  postFilter: postFilter,
144
144
  offset: offset,
145
145
  config: config.meta,
146
+ includeVariants: config.includeVariants,
146
147
  slug: aliasedSlug
147
148
  });
148
149
  case 2:
@@ -22,6 +22,7 @@ export var TranslationsMeta = function() {
22
22
  var defaultTranslation = translationsMap[defaultLocale];
23
23
  var isError = router.route === '/404' || router.route === '/_error';
24
24
  if (isError) return null;
25
+ if ((allLocales === null || allLocales === void 0 ? void 0 : allLocales.length) < 2) return null;
25
26
  var domain = defaultTranslation === null || defaultTranslation === void 0 ? void 0 : defaultTranslation.domain;
26
27
  return(/*#__PURE__*/ React.createElement(Head, null, allLocales === null || allLocales === void 0 ? void 0 : allLocales.map(function(locale) {
27
28
  var translation = translationsMap === null || translationsMap === void 0 ? void 0 : translationsMap[locale];
@@ -0,0 +1,22 @@
1
+ import { VariantMap, VariantType } from '../useProductVariants';
2
+ import { SearchResultDTO } from '@sentecacommerce/sdk';
3
+ import { LineItemType } from '../../';
4
+ declare type LineItemStateContextType = {
5
+ variants?: VariantMap;
6
+ selectedVariant: (LineItemType & VariantType) | null;
7
+ };
8
+ declare type CountFunctionsContextType = {
9
+ selectVariantById: (id: string) => void;
10
+ selectVariantByAttribute: (key: string) => void;
11
+ selectVariantByCombination: (key: string, value: string) => void;
12
+ getVariantById: (id: string) => VariantType;
13
+ getVariantByAttribute: (key: string) => VariantType;
14
+ getVariantByCombination: (key: string, value: string) => VariantType;
15
+ };
16
+ export declare function LineItemStateProvider({ product, children, }: {
17
+ product: SearchResultDTO;
18
+ children: any;
19
+ }): JSX.Element;
20
+ export declare function useLineItemState(): LineItemStateContextType;
21
+ export declare function useLineItemFunctions(): CountFunctionsContextType;
22
+ export {};
@@ -1,4 +1,5 @@
1
1
  import type { SearchResultDTO, ImageDTO, MoneyDTO, ReviewRatingStatisticsDTO, OfferDTO } from '@sentecacommerce/sdk';
2
+ export { useLineItemFunctions, useLineItemState, LineItemStateProvider, } from './LineItemContext';
2
3
  export interface BaseProductType {
3
4
  name: string;
4
5
  slug: string;
@@ -26,7 +27,7 @@ export interface AttributesType {
26
27
  count: number;
27
28
  elements: AttributeType[];
28
29
  }
29
- interface LineItemType extends BaseProductType {
30
+ export interface LineItemType extends BaseProductType {
30
31
  name: string;
31
32
  brand?: {
32
33
  name: string;
@@ -47,4 +48,3 @@ interface LineItemType extends BaseProductType {
47
48
  getCustomFieldByKey: (key: string) => any;
48
49
  }
49
50
  export declare const useLineItem: (props: SearchResultDTO) => LineItemType;
50
- export {};
@@ -1,23 +1,8 @@
1
1
  import React from 'react';
2
- import type { ProductDTO, ProductVariantDTO, AttributeRuleDTO, ProductAttributeDraftDTO, SelectedOptionDTO, ReviewRatingStatisticsDTO } from '@sentecacommerce/sdk';
3
- import { SelectedOptionType } from './utils';
2
+ import type { ProductDTO, ReviewRatingStatisticsDTO } from '@sentecacommerce/sdk';
4
3
  import { getProductBySlugConfig } from '../../api/productsApi';
5
4
  import { AssetsMap } from '../../utils/assetsToMap';
6
- export interface OptionsType {
7
- definitionKey: string;
8
- label: string;
9
- elements?: SubOptionType[];
10
- }
11
- export interface SubOptionType {
12
- optionKey: string;
13
- label: string;
14
- imageIndex?: number;
15
- }
16
- export interface ContentType {
17
- key: string;
18
- name?: string;
19
- content?: string;
20
- }
5
+ import { VariantMap, VariantType, ContentType, AttributeRulesMap } from '../useProductVariants';
21
6
  export interface MetaInfoCategoryType {
22
7
  name: string;
23
8
  id: string;
@@ -55,65 +40,6 @@ interface SeoInformationType {
55
40
  description?: string;
56
41
  keywords?: string;
57
42
  }
58
- interface AttributeRulesType extends AttributeRuleDTO {
59
- label: string;
60
- values: {
61
- [id: string]: {
62
- label: string;
63
- extra: any;
64
- combinations: {
65
- [id: string]: string;
66
- };
67
- };
68
- };
69
- }
70
- export interface VariantType extends Omit<ProductVariantDTO, 'attributes' | 'availableOptions' | 'selectedOptions' | 'labels'> {
71
- attributes: ProductAttributeDraftDTO[];
72
- options?: OptionsType[];
73
- selectedOptions: SelectedOptionDTO[];
74
- mappedSelectedOptions?: SelectedOptionType[];
75
- isAvailable: boolean;
76
- quantity?: number;
77
- inventory: {
78
- hasAvailableQuantity?: boolean;
79
- availableQuantity?: number;
80
- };
81
- labels?: string[];
82
- getAttribute: (rule: string) => {
83
- id: string;
84
- label: string;
85
- name: string;
86
- extra: any;
87
- combinations: {
88
- [id: string]: string;
89
- };
90
- };
91
- getAttributeByKey: (key: string) => undefined | any;
92
- getAvailabilityByStore: () => InventoryAvailabilityType[] | undefined;
93
- }
94
- interface VariantMap {
95
- [productId: string]: VariantType;
96
- }
97
- export interface BooleanKVP {
98
- [sku: string]: boolean | undefined;
99
- }
100
- export interface AttributeRulesMap {
101
- [name: string]: AttributeRulesType;
102
- }
103
- export interface CombinationsMap {
104
- [id: string]: {
105
- value: string;
106
- params: {
107
- [id: string]: string;
108
- };
109
- };
110
- }
111
- export interface InventoryAvailabilityType {
112
- storeName: string;
113
- availableQuantity: number;
114
- acceptsBackorders: boolean;
115
- restockableInDays: number;
116
- }
117
43
  declare type ProductProviderProps = {
118
44
  children: React.ReactNode;
119
45
  product?: ProductDTO;
@@ -1,5 +1,6 @@
1
- import { ProductAttributeDTO, CustomField, ProductDTO, ProductVariantDTO, InventoryAvailability, OptionDefinitionDTO, SelectedOptionDTO, IdReferenceDTO, ProductVariantLabelDTO } from '@sentecacommerce/sdk';
2
- import { AttributeRulesMap, CombinationsMap, BooleanKVP, InventoryAvailabilityType, MetaInformationType, OptionsType } from '../index';
1
+ import { ProductAttributeDTO, CustomField, ProductDTO, ProductVariantDTO, InventoryAvailability, OptionDefinitionDTO, SelectedOptionDTO, IdReferenceDTO, ProductVariantLabelDTO, AttributeRuleDTO } from '@sentecacommerce/sdk';
2
+ import { InventoryAvailabilityType, OptionsType, AttributeRulesMap, BooleanKVP, CombinationsMap } from '../../useProductVariants';
3
+ import { MetaInformationType } from '../index';
3
4
  export declare const createCustomFieldsMap: (customFields?: CustomField[] | undefined) => BooleanKVP | undefined;
4
5
  export declare const createCombinationsMap: (mappedAttributeRulesKeys: string[], attributesArray: {
5
6
  variantId: string;
@@ -12,7 +13,7 @@ export declare const createProductContent: (data: any) => {
12
13
  content: string;
13
14
  };
14
15
  export declare const createCollapseKeyImagesMap: (product?: ProductDTO | undefined) => {} | undefined;
15
- export declare const createAttributeRulesMap: (product?: ProductDTO | undefined) => any;
16
+ export declare const createAttributeRulesMap: (product?: ProductDTO | undefined, isLineItem?: boolean) => any;
16
17
  export declare const createMappedOptions: (options?: OptionDefinitionDTO[] | undefined) => OptionsType[];
17
18
  export declare type SelectedOptionType = {
18
19
  label?: string;
@@ -24,7 +25,7 @@ export declare type SelectedOptionType = {
24
25
  };
25
26
  export declare const createSelectedOption2: (options?: OptionsType[] | undefined, selectedOption?: SelectedOptionDTO | undefined) => SelectedOptionType;
26
27
  export declare const createSelectedOption: (options?: OptionDefinitionDTO[] | undefined, selectedOption?: SelectedOptionDTO | undefined) => SelectedOptionType;
27
- export declare const createMappedAttributes: (currentVariant: ProductVariantDTO) => ProductAttributeDTO[];
28
+ export declare const createMappedAttributes: (currentVariant: ProductVariantDTO, isLineItem?: boolean) => any;
28
29
  export declare const processAvailabilityPerStore: (availabilities?: InventoryAvailability[] | undefined) => InventoryAvailabilityType[] | undefined;
29
30
  export declare const getProductVideos: (assets: MetaInformationType['assets']) => {
30
31
  type: string;
@@ -40,3 +41,4 @@ export declare const formatCategories: (categories?: IdReferenceDTO[] | undefine
40
41
  link: string;
41
42
  }[];
42
43
  export declare const createLabelsMap: (data?: ProductVariantLabelDTO[] | undefined) => string[] | undefined;
44
+ export declare function remapLineItemAttributes(attributes: ProductAttributeDTO[]): ProductAttributeDTO[] | AttributeRuleDTO[];
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ import { VariantType, BooleanKVP, VariantMap, AttributeRulesMap, CombinationsMap } from './types';
3
+ export * from './types';
4
+ export declare const useProductVariants: ({ product, defaultVariantId, isLineItem, }: {
5
+ product: any;
6
+ defaultVariantId: any;
7
+ isLineItem?: boolean | undefined;
8
+ }) => {
9
+ combinations: CombinationsMap;
10
+ attributeRules: AttributeRulesMap;
11
+ variants: VariantMap;
12
+ selectedVariant: VariantType | null;
13
+ setSelectedVariant: React.Dispatch<React.SetStateAction<VariantType | null>>;
14
+ customFields: BooleanKVP;
15
+ getVariantByAttribute: (key: string) => VariantType;
16
+ getVariantById: (id: string) => VariantType;
17
+ getCombinationsAndAttributeRules: () => {
18
+ combinations: CombinationsMap;
19
+ attributeRules: AttributeRulesMap;
20
+ };
21
+ getCombinationsForAttributeRule: (key: string, id: string) => {
22
+ label: string;
23
+ extra: any;
24
+ combinations: {
25
+ [id: string]: string;
26
+ };
27
+ };
28
+ getVariantByCombination: (key: string, value: string) => VariantType;
29
+ getCustomFieldValue: (field: string) => boolean | undefined;
30
+ selectVariantByAttribute: (key: string) => void;
31
+ selectVariantByCombination: (key: string, value: string) => void;
32
+ selectVariantOptions: (definitionKey: string, optionKey: string) => void;
33
+ selectVariantById: (id: string) => void;
34
+ };
@@ -0,0 +1,79 @@
1
+ import type { ProductVariantDTO, ProductAttributeDraftDTO, SelectedOptionDTO, AttributeRuleDTO, LangValue } from '@sentecacommerce/sdk';
2
+ import { SelectedOptionType } from '../useProduct/utils';
3
+ export interface VariantType extends Omit<ProductVariantDTO, 'attributes' | 'availableOptions' | 'selectedOptions' | 'labels'> {
4
+ name?: LangValue[];
5
+ slug?: LangValue[];
6
+ attributes: ProductAttributeDraftDTO[];
7
+ options?: OptionsType[];
8
+ selectedOptions: SelectedOptionDTO[];
9
+ mappedSelectedOptions?: SelectedOptionType[];
10
+ isAvailable: boolean;
11
+ quantity?: number;
12
+ inventory: {
13
+ hasAvailableQuantity?: boolean;
14
+ availableQuantity?: number;
15
+ };
16
+ labels?: string[];
17
+ getAttribute: (rule: string) => {
18
+ id: string;
19
+ label: string;
20
+ name: string;
21
+ extra: any;
22
+ combinations: {
23
+ [id: string]: string;
24
+ };
25
+ };
26
+ getAttributeByKey: (key: string) => undefined | any;
27
+ getAvailabilityByStore: () => InventoryAvailabilityType[] | undefined;
28
+ variantAttributes?: any[];
29
+ }
30
+ export interface OptionsType {
31
+ definitionKey: string;
32
+ label: string;
33
+ elements?: SubOptionType[];
34
+ }
35
+ export interface SubOptionType {
36
+ optionKey: string;
37
+ label: string;
38
+ imageIndex?: number;
39
+ }
40
+ export interface ContentType {
41
+ key: string;
42
+ name?: string;
43
+ content?: string;
44
+ }
45
+ export interface AttributeRulesType extends AttributeRuleDTO {
46
+ label: string;
47
+ values: {
48
+ [id: string]: {
49
+ label: string;
50
+ extra: any;
51
+ combinations: {
52
+ [id: string]: string;
53
+ };
54
+ };
55
+ };
56
+ }
57
+ export interface VariantMap {
58
+ [productId: string]: VariantType;
59
+ }
60
+ export interface BooleanKVP {
61
+ [sku: string]: boolean | undefined;
62
+ }
63
+ export interface AttributeRulesMap {
64
+ [name: string]: AttributeRulesType;
65
+ }
66
+ export interface CombinationsMap {
67
+ [id: string]: {
68
+ value: string;
69
+ params: {
70
+ [id: string]: string;
71
+ };
72
+ };
73
+ }
74
+ export interface InventoryAvailabilityType {
75
+ storeName: string;
76
+ availableQuantity: number;
77
+ acceptsBackorders: boolean;
78
+ restockableInDays: number;
79
+ }
@@ -85,6 +85,7 @@ export * from './hooks/useRouterRedirect';
85
85
  export * from './hooks/useProgressBar';
86
86
  export * from './hooks/useCatalogDiscounts';
87
87
  export * from './hooks/useLocalRating';
88
+ export * from './hooks/useProductVariants/types';
88
89
  export * from './utils';
89
90
  export * from './types';
90
91
  export * from './seo';
@@ -71,6 +71,7 @@ export interface DefaultListingPageProps {
71
71
  categoryTreeConfig?: Aggregate;
72
72
  sortOptions?: ListField<ListingPageSortOption>;
73
73
  attributeSortType?: AggregateSortEnum;
74
+ includeVariants?: boolean;
74
75
  meta: ListingPageMeta;
75
76
  }
76
77
  export interface ListingPageMeta {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sentecacommerce-theme/lib",
3
3
  "sideEffects": false,
4
- "version": "0.13.2",
4
+ "version": "0.13.3",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/types/index.d.ts",
@@ -31,14 +31,14 @@
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": "a02a163a7ab04039fc81e5e8ce3c38e93131968c",
34
+ "gitHead": "3f7ef1f62b26764823980283fd8c545c0e9aae0e",
35
35
  "peerDependencies": {
36
36
  "react-query": "^2.26.2"
37
37
  },
38
38
  "dependencies": {
39
- "@sentecacommerce-theme/base": "^0.13.1",
40
- "@sentecacommerce-theme/cms": "^0.13.1",
41
- "@sentecacommerce/sdk": "2.0.161",
39
+ "@sentecacommerce-theme/base": "^0.13.3",
40
+ "@sentecacommerce-theme/cms": "^0.13.3",
41
+ "@sentecacommerce/sdk": "2.0.175",
42
42
  "body-scroll-lock": "^3.1.5",
43
43
  "copy-to-clipboard": "^3.3.1",
44
44
  "embla-carousel": "^4.5.1",