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