@sentecacommerce-theme/lib 0.12.103 → 0.13.4
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 +4 -1
- package/dist/cjs/components/AnalyticsScripts/index.js +3 -2
- package/dist/cjs/hooks/useCheckoutSubmit/index.js +4 -1
- package/dist/cjs/hooks/useLineItem/LineItemContext.js +86 -0
- package/dist/cjs/hooks/useLineItem/index.js +34 -12
- package/dist/cjs/hooks/useProduct/index.js +17 -276
- package/dist/cjs/hooks/useProduct/utils/index.js +44 -18
- package/dist/cjs/hooks/useProductVariants/index.js +334 -0
- package/dist/cjs/hooks/useProductVariants/types.js +3 -0
- package/dist/cjs/index.js +16 -4
- package/dist/cjs/listing/api/queries/useListingQuery.js +1 -0
- package/dist/cjs/listing/hooks/useListingBreadcrumbs.js +20 -8
- package/dist/cjs/listing/hooks/useListingCategories.js +2 -2
- package/dist/cjs/listing/hooks/useListingMeta.js +12 -10
- package/dist/cjs/listing/utils/buildCategoryQuery.js +22 -1
- package/dist/cjs/seo/components/TranslationsMeta/index.js +1 -0
- package/dist/cjs/utils/localStorage.js +7 -2
- package/dist/esm/api/myCartApi/index.js +4 -1
- package/dist/esm/components/AnalyticsScripts/index.js +3 -2
- package/dist/esm/hooks/useCheckoutSubmit/index.js +4 -1
- package/dist/esm/hooks/useLineItem/LineItemContext.js +75 -0
- package/dist/esm/hooks/useLineItem/index.js +16 -12
- package/dist/esm/hooks/useProduct/index.js +18 -277
- package/dist/esm/hooks/useProduct/utils/index.js +44 -18
- package/dist/esm/hooks/useProductVariants/index.js +293 -0
- package/dist/esm/hooks/useProductVariants/types.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/listing/api/queries/useListingQuery.js +1 -0
- package/dist/esm/listing/hooks/useListingBreadcrumbs.js +15 -3
- package/dist/esm/listing/hooks/useListingCategories.js +2 -2
- package/dist/esm/listing/hooks/useListingMeta.js +12 -12
- package/dist/esm/listing/utils/buildCategoryQuery.js +22 -1
- package/dist/esm/seo/components/TranslationsMeta/index.js +1 -0
- package/dist/esm/utils/localStorage.js +7 -2
- package/dist/types/hooks/useLineItem/LineItemContext.d.ts +22 -0
- package/dist/types/hooks/useLineItem/index.d.ts +2 -2
- package/dist/types/hooks/useProduct/index.d.ts +2 -76
- package/dist/types/hooks/useProduct/utils/index.d.ts +6 -4
- package/dist/types/hooks/useProductVariants/index.d.ts +34 -0
- package/dist/types/hooks/useProductVariants/types.d.ts +79 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/listing/hooks/useListingMeta.d.ts +4 -0
- package/dist/types/listing/types.d.ts +1 -0
- package/package.json +5 -5
@@ -64,6 +64,7 @@ var LineItemType;
|
|
64
64
|
})(LineItemType || (LineItemType = {}));
|
65
65
|
var MyCartApiFactory = function() {
|
66
66
|
var instance;
|
67
|
+
var hasAnalytics = !process.env.NO_ANALYTICS;
|
67
68
|
function initialise() {
|
68
69
|
var myCartApi1 = new _sdk.MyCartAPI((0, _getSDKConfig).getSDKConfig());
|
69
70
|
var myOrdersApi = new _sdk.MyOrdersAPI((0, _getSDKConfig).getSDKConfig());
|
@@ -262,7 +263,9 @@ var MyCartApiFactory = function() {
|
|
262
263
|
var product = data.lineItems.find(function(p) {
|
263
264
|
return p.productId === params.productId;
|
264
265
|
});
|
265
|
-
|
266
|
+
if (hasAnalytics) {
|
267
|
+
product && (0, _addToCart).addToCart(product.variant.sku, params.quantity, product.offer.price || product.offer.originalPrice);
|
268
|
+
}
|
266
269
|
queryCache.setQueryData([
|
267
270
|
myCartCacheKeys.useIsExisting,
|
268
271
|
params.productId,
|
@@ -80,6 +80,7 @@ function _unsupportedIterableToArray(o, minLen) {
|
|
80
80
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
81
81
|
}
|
82
82
|
var isProduction = process.env.NODE_ENV === 'production';
|
83
|
+
var hasAnalytics = !process.env.NO_ANALYTICS;
|
83
84
|
function AnalyticsScripts() {
|
84
85
|
var ref11, ref1, ref2, ref3, ref4;
|
85
86
|
var timeout = (0, _react).useRef(null);
|
@@ -117,7 +118,7 @@ function AnalyticsScripts() {
|
|
117
118
|
}
|
118
119
|
};
|
119
120
|
(0, _react).useEffect(function() {
|
120
|
-
if (!isProduction) return;
|
121
|
+
if (!isProduction && !hasAnalytics) return;
|
121
122
|
if (document) {
|
122
123
|
timeout.current = setTimeout(initAnalytics, 3500);
|
123
124
|
document.addEventListener('scroll', initAnalyticsOnEvent);
|
@@ -129,7 +130,7 @@ function AnalyticsScripts() {
|
|
129
130
|
]);
|
130
131
|
var pageView = (0, _pageView).getPageView(config);
|
131
132
|
(0, _react).useEffect(function() {
|
132
|
-
if (!isProduction) return;
|
133
|
+
if (!isProduction && !hasAnalytics) return;
|
133
134
|
var handleRouteChange = function(url) {
|
134
135
|
if ('browser' in process) {
|
135
136
|
setTimeout(function() {
|
@@ -91,6 +91,7 @@ var useCheckoutSubmit = function(param) {
|
|
91
91
|
var onSuccess = param.onSuccess, onBeforeBoricaRedirect = param.onBeforeBoricaRedirect, onBeforePaypalRedirect = param.onBeforePaypalRedirect, onBeforeUniCreditRedirect = param.onBeforeUniCreditRedirect, onError = param.onError, withMeta = param.withMeta, disablePaymentRedirects = param.disablePaymentRedirects;
|
92
92
|
var Config = (0, _useConfig).useConfigState();
|
93
93
|
var districtMeta = (0, _).useDistrictMeta();
|
94
|
+
var hasAnalytics = !process.env.NO_ANALYTICS;
|
94
95
|
var ref = _slicedToArray(_.myOrdersApi.useCreate(withMeta ? districtMeta : {}, function() {
|
95
96
|
var _ref = _asyncToGenerator(_regeneratorRuntime.default.mark(function _callee(result) {
|
96
97
|
var paypalPayment, boricaPayment, uniCreditPayment, boricaResult, paypalResponse, uniCreditStartSessionResponse;
|
@@ -98,7 +99,9 @@ var useCheckoutSubmit = function(param) {
|
|
98
99
|
while(1)switch(_ctx.prev = _ctx.next){
|
99
100
|
case 0:
|
100
101
|
// Analytics
|
101
|
-
(
|
102
|
+
if (hasAnalytics) {
|
103
|
+
(0, _purchase).purchase(result, Config);
|
104
|
+
}
|
102
105
|
paypalPayment = result.payments.find(function(payment) {
|
103
106
|
return payment.type === _sdk.PaymentDTOTypeEnum.PaymentServiceProvider && payment.moduleKey === 'Paypal';
|
104
107
|
});
|
@@ -0,0 +1,86 @@
|
|
1
|
+
Object.defineProperty(exports, "__esModule", {
|
2
|
+
value: true
|
3
|
+
});
|
4
|
+
exports.LineItemStateProvider = LineItemStateProvider;
|
5
|
+
exports.useLineItemState = useLineItemState;
|
6
|
+
exports.useLineItemFunctions = useLineItemFunctions;
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
8
|
+
var _useProductVariants = require("../useProductVariants");
|
9
|
+
var _ = require("../..");
|
10
|
+
function _defineProperty(obj, key, value) {
|
11
|
+
if (key in obj) {
|
12
|
+
Object.defineProperty(obj, key, {
|
13
|
+
value: value,
|
14
|
+
enumerable: true,
|
15
|
+
configurable: true,
|
16
|
+
writable: true
|
17
|
+
});
|
18
|
+
} else {
|
19
|
+
obj[key] = value;
|
20
|
+
}
|
21
|
+
return obj;
|
22
|
+
}
|
23
|
+
function _interopRequireDefault(obj) {
|
24
|
+
return obj && obj.__esModule ? obj : {
|
25
|
+
default: obj
|
26
|
+
};
|
27
|
+
}
|
28
|
+
function _objectSpread(target) {
|
29
|
+
for(var i = 1; i < arguments.length; i++){
|
30
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
31
|
+
var ownKeys = Object.keys(source);
|
32
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
33
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
34
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
35
|
+
}));
|
36
|
+
}
|
37
|
+
ownKeys.forEach(function(key) {
|
38
|
+
_defineProperty(target, key, source[key]);
|
39
|
+
});
|
40
|
+
}
|
41
|
+
return target;
|
42
|
+
}
|
43
|
+
var LineItemStateContext = /*#__PURE__*/ _react.default.createContext(undefined);
|
44
|
+
var CountDispatchContext = /*#__PURE__*/ _react.default.createContext(undefined);
|
45
|
+
function LineItemStateProvider(param) {
|
46
|
+
var product = param.product, children = param.children;
|
47
|
+
var ref = (0, _useProductVariants).useProductVariants({
|
48
|
+
product: product,
|
49
|
+
defaultVariantId: product.variantId,
|
50
|
+
isLineItem: true
|
51
|
+
}), variants = ref.variants, selectedVariant = ref.selectedVariant, getVariantById = ref.getVariantById, getVariantByAttribute = ref.getVariantByAttribute, getVariantByCombination = ref.getVariantByCombination, selectVariantById = ref.selectVariantById, selectVariantByAttribute = ref.selectVariantByAttribute, selectVariantByCombination = ref.selectVariantByCombination;
|
52
|
+
var state = {
|
53
|
+
variants: variants,
|
54
|
+
selectedVariant: _objectSpread({}, selectedVariant, {
|
55
|
+
name: (0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.name),
|
56
|
+
slug: (0, _).getTranslatableField(selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.slug)
|
57
|
+
})
|
58
|
+
};
|
59
|
+
var functions = {
|
60
|
+
getVariantById: getVariantById,
|
61
|
+
getVariantByAttribute: getVariantByAttribute,
|
62
|
+
getVariantByCombination: getVariantByCombination,
|
63
|
+
selectVariantById: selectVariantById,
|
64
|
+
selectVariantByAttribute: selectVariantByAttribute,
|
65
|
+
selectVariantByCombination: selectVariantByCombination
|
66
|
+
};
|
67
|
+
return(/*#__PURE__*/ _react.default.createElement(LineItemStateContext.Provider, {
|
68
|
+
value: state
|
69
|
+
}, /*#__PURE__*/ _react.default.createElement(CountDispatchContext.Provider, {
|
70
|
+
value: functions
|
71
|
+
}, children)));
|
72
|
+
}
|
73
|
+
function useLineItemState() {
|
74
|
+
var context = _react.default.useContext(LineItemStateContext);
|
75
|
+
if (context === undefined) {
|
76
|
+
throw new Error('useLineItemState must be used within a LineItemStateProvider');
|
77
|
+
}
|
78
|
+
return context;
|
79
|
+
}
|
80
|
+
function useLineItemFunctions() {
|
81
|
+
var context = _react.default.useContext(CountDispatchContext);
|
82
|
+
if (context === undefined) {
|
83
|
+
throw new Error('useLineItemFunctions must be used within a LineItemStateProvider');
|
84
|
+
}
|
85
|
+
return context;
|
86
|
+
}
|
@@ -1,10 +1,29 @@
|
|
1
1
|
Object.defineProperty(exports, "__esModule", {
|
2
2
|
value: true
|
3
3
|
});
|
4
|
+
Object.defineProperty(exports, "useLineItemFunctions", {
|
5
|
+
enumerable: true,
|
6
|
+
get: function() {
|
7
|
+
return _lineItemContext.useLineItemFunctions;
|
8
|
+
}
|
9
|
+
});
|
10
|
+
Object.defineProperty(exports, "useLineItemState", {
|
11
|
+
enumerable: true,
|
12
|
+
get: function() {
|
13
|
+
return _lineItemContext.useLineItemState;
|
14
|
+
}
|
15
|
+
});
|
16
|
+
Object.defineProperty(exports, "LineItemStateProvider", {
|
17
|
+
enumerable: true,
|
18
|
+
get: function() {
|
19
|
+
return _lineItemContext.LineItemStateProvider;
|
20
|
+
}
|
21
|
+
});
|
4
22
|
exports.useLineItem = void 0;
|
5
23
|
var _react = _interopRequireDefault(require("react"));
|
6
24
|
var _utils = require("../../utils");
|
7
25
|
var _usePrefetchProduct = require("../usePrefetchProduct");
|
26
|
+
var _lineItemContext = require("./LineItemContext");
|
8
27
|
function _defineProperty(obj, key, value) {
|
9
28
|
if (key in obj) {
|
10
29
|
Object.defineProperty(obj, key, {
|
@@ -39,10 +58,10 @@ function _objectSpread(target) {
|
|
39
58
|
return target;
|
40
59
|
}
|
41
60
|
var useLineItem = function(props) {
|
42
|
-
var
|
61
|
+
var ref17 = (0, _usePrefetchProduct).usePrefetchProduct((0, _utils).getTranslatableField(props === null || props === void 0 ? void 0 : props.slug)), onMouseEnter = ref17.onMouseEnter, onMouseLeave = ref17.onMouseLeave, onMouseDown = ref17.onMouseDown;
|
43
62
|
var data = _react.default.useMemo(function() {
|
44
|
-
var
|
45
|
-
var mappedAttributes = (
|
63
|
+
var ref18, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, ref10, ref11, ref12, ref13;
|
64
|
+
var mappedAttributes = (ref18 = Object.keys(props === null || props === void 0 ? void 0 : props.attributes)) === null || ref18 === void 0 ? void 0 : ref18.reduce(function(map, key) {
|
46
65
|
var current = props === null || props === void 0 ? void 0 : props.attributes[key];
|
47
66
|
var ref;
|
48
67
|
map[key] = {
|
@@ -63,7 +82,7 @@ var useLineItem = function(props) {
|
|
63
82
|
}
|
64
83
|
return map;
|
65
84
|
}, {});
|
66
|
-
var
|
85
|
+
var ref14, ref15, ref16;
|
67
86
|
return {
|
68
87
|
_id: props === null || props === void 0 ? void 0 : props._id,
|
69
88
|
name: (0, _utils).getTranslatableField(props === null || props === void 0 ? void 0 : props.name),
|
@@ -71,18 +90,21 @@ var useLineItem = function(props) {
|
|
71
90
|
name: (0, _utils).getTranslatableField(props === null || props === void 0 ? void 0 : (ref2 = props.brands) === null || ref2 === void 0 ? void 0 : (ref3 = ref2[0]) === null || ref3 === void 0 ? void 0 : ref3.name),
|
72
91
|
slug: (0, _utils).getTranslatableField(props === null || props === void 0 ? void 0 : (ref4 = props.brands) === null || ref4 === void 0 ? void 0 : (ref5 = ref4[0]) === null || ref5 === void 0 ? void 0 : ref5.slug)
|
73
92
|
},
|
93
|
+
attributes: props === null || props === void 0 ? void 0 : props.attributes,
|
94
|
+
variantAttributes: (ref6 = props) === null || ref6 === void 0 ? void 0 : ref6.variantAttributes,
|
95
|
+
variants: props === null || props === void 0 ? void 0 : props.variants,
|
74
96
|
slug: (0, _utils).getTranslatableField(props === null || props === void 0 ? void 0 : props.slug),
|
75
97
|
collapseKey: props === null || props === void 0 ? void 0 : props.collapseKey,
|
76
98
|
variantId: props === null || props === void 0 ? void 0 : props.variantId,
|
77
|
-
offerId: props === null || props === void 0 ? void 0 : (
|
99
|
+
offerId: props === null || props === void 0 ? void 0 : (ref7 = props.offer) === null || ref7 === void 0 ? void 0 : ref7._id,
|
78
100
|
offer: props === null || props === void 0 ? void 0 : props.offer,
|
79
101
|
sku: props === null || props === void 0 ? void 0 : props.sku,
|
80
102
|
images: (props === null || props === void 0 ? void 0 : props.images) || {},
|
81
103
|
ratings: props === null || props === void 0 ? void 0 : props.reviewRatingStatistics,
|
82
|
-
price: props === null || props === void 0 ? void 0 : (
|
83
|
-
discountedPrice: props === null || props === void 0 ? void 0 : (
|
84
|
-
variantOptions: (
|
85
|
-
variantsCount: (
|
104
|
+
price: props === null || props === void 0 ? void 0 : (ref8 = props.offer) === null || ref8 === void 0 ? void 0 : ref8.originalPrice,
|
105
|
+
discountedPrice: props === null || props === void 0 ? void 0 : (ref9 = props.offer) === null || ref9 === void 0 ? void 0 : ref9.discountedPrice,
|
106
|
+
variantOptions: (ref14 = props === null || props === void 0 ? void 0 : props.variantOptions) !== null && ref14 !== void 0 ? ref14 : 0,
|
107
|
+
variantsCount: (ref15 = props === null || props === void 0 ? void 0 : props.variantsCount) !== null && ref15 !== void 0 ? ref15 : 0,
|
86
108
|
categories: props === null || props === void 0 ? void 0 : props.categories.map(function(category) {
|
87
109
|
return {
|
88
110
|
name: (0, _utils).getTranslatableField(category.name),
|
@@ -90,9 +112,9 @@ var useLineItem = function(props) {
|
|
90
112
|
};
|
91
113
|
}),
|
92
114
|
inventory: {
|
93
|
-
hasAvailableQuantity: (props === null || props === void 0 ? void 0 : (
|
94
|
-
availableQuantity: (props === null || props === void 0 ? void 0 : (
|
95
|
-
maxQuantity: props === null || props === void 0 ? void 0 : (
|
115
|
+
hasAvailableQuantity: (props === null || props === void 0 ? void 0 : (ref10 = props.inventorySnapshot) === null || ref10 === void 0 ? void 0 : ref10.canOrder) ? true : false,
|
116
|
+
availableQuantity: (props === null || props === void 0 ? void 0 : (ref11 = props.inventorySnapshot) === null || ref11 === void 0 ? void 0 : ref11.canOrder) ? (ref16 = props === null || props === void 0 ? void 0 : (ref12 = props.inventorySnapshot) === null || ref12 === void 0 ? void 0 : ref12.availableQuantity) !== null && ref16 !== void 0 ? ref16 : 0 : 0,
|
117
|
+
maxQuantity: props === null || props === void 0 ? void 0 : (ref13 = props.offer) === null || ref13 === void 0 ? void 0 : ref13.maxQuantity
|
96
118
|
},
|
97
119
|
labels: mapLabelData(props === null || props === void 0 ? void 0 : props.labels),
|
98
120
|
getCustomFieldByKey: function(key) {
|
@@ -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
|
-
|
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
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|
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 : (
|
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 : (
|
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 : (
|
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 : (
|
130
|
-
name: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (
|
131
|
-
slug: (0, _).getTranslatableField(product === null || product === void 0 ? void 0 : (
|
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 : (
|
136
|
-
slug: (0, _).getTranslatableField(rootCategory === null || rootCategory === void 0 ? void 0 : (
|
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 : (
|
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,
|