addio-ecomm-sdk 1.3.77 → 1.3.78
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/.vscode/settings.json +34 -34
- package/README.md +79 -79
- package/dist/index.d.ts +203 -203
- package/dist/index.js +1237 -1237
- package/dist/lib/constants/components/CreditCardInput.d.ts +11 -11
- package/dist/lib/constants/components/CreditCardInput.js +65 -65
- package/dist/lib/constants/components/Snackbar.d.ts +11 -11
- package/dist/lib/constants/components/Snackbar.js +29 -29
- package/dist/lib/constants/contexts/CartContext/CartContextProvider.d.ts +7 -7
- package/dist/lib/constants/contexts/CartContext/CartContextProvider.js +640 -640
- package/dist/lib/constants/contexts/CartContext/index.d.ts +79 -79
- package/dist/lib/constants/contexts/CartContext/index.js +47 -47
- package/dist/lib/constants/contexts/DataContext/DataContextProvider.d.ts +15 -15
- package/dist/lib/constants/contexts/DataContext/DataContextProvider.js +173 -173
- package/dist/lib/constants/contexts/DataContext/index.d.ts +47 -47
- package/dist/lib/constants/contexts/DataContext/index.js +27 -27
- package/dist/lib/constants/contexts/LogContext/LogContextProvider.d.ts +6 -6
- package/dist/lib/constants/contexts/LogContext/LogContextProvider.js +40 -40
- package/dist/lib/constants/contexts/LogContext/index.d.ts +7 -7
- package/dist/lib/constants/contexts/LogContext/index.js +7 -7
- package/dist/lib/constants/contexts/ModalContext/ModalContextProvider.d.ts +7 -7
- package/dist/lib/constants/contexts/ModalContext/ModalContextProvider.js +61 -61
- package/dist/lib/constants/contexts/ModalContext/index.d.ts +14 -14
- package/dist/lib/constants/contexts/ModalContext/index.js +16 -16
- package/dist/lib/constants/contexts/SDKContext/SDKProvider.d.ts +8 -8
- package/dist/lib/constants/contexts/SDKContext/SDKProvider.js +23 -23
- package/dist/lib/constants/contexts/SDKContext/index.d.ts +4 -4
- package/dist/lib/constants/contexts/SDKContext/index.js +4 -4
- package/dist/lib/constants/contexts/SnackbarContext/SnackbarContext.d.ts +4 -4
- package/dist/lib/constants/contexts/SnackbarContext/SnackbarContext.js +6 -6
- package/dist/lib/constants/contexts/SnackbarContext/SnackbarContextProvider.d.ts +12 -12
- package/dist/lib/constants/contexts/SnackbarContext/SnackbarContextProvider.js +38 -38
- package/dist/lib/constants/contexts/SnackbarContext/interfaces/ISnackbarContext.d.ts +19 -19
- package/dist/lib/constants/contexts/SnackbarContext/interfaces/ISnackbarContext.js +21 -21
- package/dist/lib/constants/contexts/StockNotifContext/StockNotifContextProvider.d.ts +7 -7
- package/dist/lib/constants/contexts/StockNotifContext/StockNotifContextProvider.js +112 -112
- package/dist/lib/constants/contexts/StockNotifContext/index.d.ts +10 -10
- package/dist/lib/constants/contexts/StockNotifContext/index.js +10 -10
- package/dist/lib/constants/contexts/UserContext/UserContextProvider.d.ts +5 -5
- package/dist/lib/constants/contexts/UserContext/UserContextProvider.js +313 -313
- package/dist/lib/constants/contexts/UserContext/index.d.ts +54 -54
- package/dist/lib/constants/contexts/UserContext/index.js +28 -28
- package/dist/lib/constants/contexts/WishlistContext/WishlistContextProvider.d.ts +6 -6
- package/dist/lib/constants/contexts/WishlistContext/WishlistContextProvider.js +231 -231
- package/dist/lib/constants/contexts/WishlistContext/index.d.ts +12 -12
- package/dist/lib/constants/contexts/WishlistContext/index.js +12 -12
- package/dist/lib/constants/hooks/useCart.d.ts +2 -2
- package/dist/lib/constants/hooks/useCart.js +11 -11
- package/dist/lib/constants/hooks/useData.d.ts +2 -2
- package/dist/lib/constants/hooks/useData.js +11 -11
- package/dist/lib/constants/hooks/useLogs.d.ts +2 -2
- package/dist/lib/constants/hooks/useLogs.js +11 -11
- package/dist/lib/constants/hooks/useModal.d.ts +2 -2
- package/dist/lib/constants/hooks/useModal.js +11 -11
- package/dist/lib/constants/hooks/useSDK.d.ts +2 -2
- package/dist/lib/constants/hooks/useSDK.js +11 -11
- package/dist/lib/constants/hooks/useSnackbar.d.ts +2 -2
- package/dist/lib/constants/hooks/useSnackbar.js +11 -11
- package/dist/lib/constants/hooks/useStockNotif.d.ts +2 -2
- package/dist/lib/constants/hooks/useStockNotif.js +11 -11
- package/dist/lib/constants/hooks/useUser.d.ts +2 -2
- package/dist/lib/constants/hooks/useUser.js +11 -11
- package/dist/lib/constants/hooks/useWishlist.d.ts +2 -2
- package/dist/lib/constants/hooks/useWishlist.js +11 -11
- package/dist/lib/models/image/index.d.ts +6 -6
- package/dist/lib/models/image/index.js +10 -10
- package/dist/lib/models/stockNotification/index.d.ts +13 -13
- package/dist/lib/models/stockNotification/index.js +70 -70
- package/dist/lib/models/wishlist/index.d.ts +14 -14
- package/dist/lib/models/wishlist/index.js +86 -86
- package/dist/utils/StripeErrors.d.ts +24 -24
- package/dist/utils/StripeErrors.js +55 -55
- package/dist/utils/algolia.d.ts +3 -3
- package/dist/utils/algolia.js +35 -35
- package/dist/utils/analytics.d.ts +71 -71
- package/dist/utils/analytics.js +246 -246
- package/dist/utils/cart.d.ts +3 -3
- package/dist/utils/cart.js +65 -65
- package/dist/utils/contentful.d.ts +10 -10
- package/dist/utils/contentful.js +63 -63
- package/dist/utils/functions.d.ts +21 -21
- package/dist/utils/functions.js +183 -183
- package/dist/utils/getSDK.d.ts +4 -4
- package/dist/utils/getSDK.js +19 -19
- package/dist/utils/initStoreData.d.ts +3 -3
- package/dist/utils/initStoreData.js +17 -17
- package/dist/utils/interfaces/IClientCMSData.d.ts +132 -132
- package/dist/utils/interfaces/IClientCMSData.js +2 -2
- package/dist/utils/interfaces/IEndpointResult.d.ts +10 -10
- package/dist/utils/interfaces/IEndpointResult.js +2 -2
- package/dist/utils/interfaces/IFacebookUserProfile.d.ts +10 -10
- package/dist/utils/interfaces/IFacebookUserProfile.js +2 -2
- package/dist/utils/interfaces/IFilter.d.ts +23 -23
- package/dist/utils/interfaces/IFilter.js +2 -2
- package/dist/utils/interfaces/IGoogleUserProfile.d.ts +7 -7
- package/dist/utils/interfaces/IGoogleUserProfile.js +2 -2
- package/dist/utils/interfaces/ISDKConfig.d.ts +7 -7
- package/dist/utils/interfaces/ISDKConfig.js +2 -2
- package/dist/utils/interfaces/ISpaceData.d.ts +18 -18
- package/dist/utils/interfaces/ISpaceData.js +2 -2
- package/dist/utils/larivieremeunier.d.ts +3 -3
- package/dist/utils/larivieremeunier.js +156 -156
- package/dist/utils/technosupply.d.ts +3 -3
- package/dist/utils/technosupply.js +155 -155
- package/package.json +61 -61
- package/publish.sh +132 -132
package/dist/utils/analytics.js
CHANGED
|
@@ -1,247 +1,247 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addToDataLayer_GT4 = exports.addProductPageToAnalytics_GT4 = exports.addAddToBasketToAnalytics_GT4 = exports.addPurchaseToAnalytics_GT4 = exports.getCheckoutData = exports.addCheckoutStepsToAnalytics_GA4 = exports.addLoggedCustomerToAnalytics_GA4 = exports.addPurchaseToAnalytics_GA4 = exports.addCheckoutStepsToAnalytics = exports.addPurchaseToAnalytics = exports.sendFormSubmitEventToAnalytics = void 0;
|
|
4
|
-
const discount_1 = require("addio-admin-sdk/dist/utils/discount");
|
|
5
|
-
const products_1 = require("addio-admin-sdk/dist/utils/products");
|
|
6
|
-
const lodash_1 = require("lodash");
|
|
7
|
-
const functions_1 = require("./functions");
|
|
8
|
-
const getCartItem = (item) => {
|
|
9
|
-
return Object.assign(Object.assign(Object.assign({ id: item.sku, name: !!item.parent_name ? (0, functions_1.translate)('fr', item.parent_name) : '', variant: !!item.name ? (0, functions_1.translate)('fr', item.name) : '' }, (!!item.brand_name ? { brand: (0, functions_1.translate)('fr', item.brand_name) } : {})), (!!item.category_name ? { category: (0, functions_1.translate)('fr', item.category_name) } : {})), { price: (0, products_1.getLowestPrice)(item).price.amount, quantity: item.qte });
|
|
10
|
-
};
|
|
11
|
-
const sendFormSubmitEventToAnalytics = (form_id) => {
|
|
12
|
-
const dataLayer = getDataLayer();
|
|
13
|
-
if (!!!dataLayer)
|
|
14
|
-
return;
|
|
15
|
-
dataLayer.push({ event: 'form_submit', form_id });
|
|
16
|
-
};
|
|
17
|
-
exports.sendFormSubmitEventToAnalytics = sendFormSubmitEventToAnalytics;
|
|
18
|
-
const addPurchaseToAnalytics = (cart, TagManager) => {
|
|
19
|
-
const allPromos = (0, discount_1.getCartPromo)(cart);
|
|
20
|
-
let coupon = null;
|
|
21
|
-
if (!!allPromos) {
|
|
22
|
-
const promo = allPromos.filter((x) => !!x.promo_code);
|
|
23
|
-
if (!!promo)
|
|
24
|
-
coupon = promo.find((x) => x.promo_code);
|
|
25
|
-
}
|
|
26
|
-
TagManager.dataLayer({
|
|
27
|
-
dataLayer: {
|
|
28
|
-
event: 'purchase',
|
|
29
|
-
ecommerce: {
|
|
30
|
-
purchase: {
|
|
31
|
-
actionField: Object.assign({ id: cart.ref, affiliation: (!!cart.customer_info && !!cart.customer_info.customer_default_email) || cart.customer_id
|
|
32
|
-
? !!cart.customer_info && cart.customer_info.pro_title
|
|
33
|
-
? `client ${cart.customer_info.pro_title}`
|
|
34
|
-
: 'client connecté'
|
|
35
|
-
: 'invité', revenue: cart.total, tax: !!cart.total_taxes ? cart.total_taxes : (0, lodash_1.sumBy)(cart.taxes, (tax) => (0, lodash_1.sumBy)(tax.taxes, 'amount')), shipping: cart.shipping }, (!!coupon ? { coupon: coupon.promo_code } : {})),
|
|
36
|
-
products: cart.items.map((item) => getCartItem(item))
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
dataLayerName: 'purchase'
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
exports.addPurchaseToAnalytics = addPurchaseToAnalytics;
|
|
44
|
-
const addCheckoutStepsToAnalytics = (cart, TagManager, step, option) => {
|
|
45
|
-
TagManager.dataLayer({
|
|
46
|
-
dataLayer: {
|
|
47
|
-
event: 'checkout',
|
|
48
|
-
ecommerce: {
|
|
49
|
-
checkout: {
|
|
50
|
-
actionField: { step: step, option: !!option ? option : '' },
|
|
51
|
-
products: cart.items.map((item) => getCartItem(item))
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
dataLayerName: 'checkout'
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
exports.addCheckoutStepsToAnalytics = addCheckoutStepsToAnalytics;
|
|
59
|
-
const getAppliedCartPromo = (cart) => {
|
|
60
|
-
const allPromos = (0, discount_1.getCartPromo)(cart);
|
|
61
|
-
if (!!allPromos) {
|
|
62
|
-
const promo = allPromos.filter((x) => !!x.promo_code);
|
|
63
|
-
if (!!promo)
|
|
64
|
-
return promo.find((x) => x.promo_code);
|
|
65
|
-
if (!!allPromos.length)
|
|
66
|
-
return allPromos[0];
|
|
67
|
-
}
|
|
68
|
-
return;
|
|
69
|
-
};
|
|
70
|
-
const getCartItem_GA4 = (item, itemIndex, currency) => {
|
|
71
|
-
return Object.assign(Object.assign(Object.assign(Object.assign({ item_id: item.sku, item_name: !!item.parent_name ? (0, functions_1.translate)('fr', item.parent_name) : '', currency: currency }, (!!(0, products_1.getLowestPrice)(item).promo
|
|
72
|
-
? { discount: item.regular_price.amount - (0, products_1.getLowestPrice)(item).price.amount }
|
|
73
|
-
: {})), { index: itemIndex, item_brand: !!item.brand_name ? (0, functions_1.translate)('fr', item.brand_name) : '', item_category: !!item.categories && !!item.categories.lvl0
|
|
74
|
-
? item.categories.lvl0
|
|
75
|
-
: !!item.category_name
|
|
76
|
-
? (0, functions_1.translate)('fr', item.category_name)
|
|
77
|
-
: '' }), (!!item.categories
|
|
78
|
-
? Object.assign(Object.assign(Object.assign(Object.assign({}, (!!item.categories.lvl1 ? { item_category2: item.categories.lvl1.split(' > ').slice(-1)[0] } : {})), (!!item.categories.lvl2 ? { item_category2: item.categories.lvl2.split(' > ').slice(-1)[0] } : {})), (!!item.categories.lvl3 ? { item_category2: item.categories.lvl3.split(' > ').slice(-1)[0] } : {})), (!!item.categories.lvl4 ? { item_category2: item.categories.lvl4.split(' > ').slice(-1)[0] } : {})) : {})), { item_variant: (0, functions_1.translate)('fr', item.name), price: item.regular_price.amount, quantity: item.qte });
|
|
79
|
-
};
|
|
80
|
-
const addPurchaseToAnalytics_GA4 = (cart, TagManager) => {
|
|
81
|
-
if (!!!process.env.IS_TEST_ENV) {
|
|
82
|
-
const coupon = getAppliedCartPromo(cart);
|
|
83
|
-
const affiliation = !!cart.customer_info && !!cart.customer_info.pro_proof_doc ? 'pro' : !!cart.customer_id ? 'connected' : 'guest';
|
|
84
|
-
TagManager.dataLayer({ dataLayer: { ecommerce: null } });
|
|
85
|
-
TagManager.dataLayer({
|
|
86
|
-
dataLayer: {
|
|
87
|
-
event: 'purchase',
|
|
88
|
-
ecommerce: Object.assign(Object.assign({ affiliation: affiliation, transaction_id: cart.ref, currency: cart.currency || 'CAD', value: cart.total, revenue: cart.total, tax: !!cart.total_taxes ? cart.total_taxes : (0, lodash_1.sumBy)(cart.taxes, (tax) => (0, lodash_1.sumBy)(tax.taxes, 'amount')), shipping: cart.shipping }, (!!coupon ? { coupon: coupon.promo_code } : {})), { items: cart.items.map((item, index) => getCartItem_GA4(item, index, cart.currency || 'CAD')) })
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
exports.addPurchaseToAnalytics_GA4 = addPurchaseToAnalytics_GA4;
|
|
94
|
-
const addLoggedCustomerToAnalytics_GA4 = (userType, TagManager, userID, clerkID) => {
|
|
95
|
-
if (!!!process.env.IS_TEST_ENV) {
|
|
96
|
-
TagManager.dataLayer({ dataLayer: { user_type: null } });
|
|
97
|
-
TagManager.dataLayer({
|
|
98
|
-
dataLayer: Object.assign({ event: 'login', user_type: userType, user_id: userID }, (!!clerkID ? { clerk_id: clerkID } : {}))
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
exports.addLoggedCustomerToAnalytics_GA4 = addLoggedCustomerToAnalytics_GA4;
|
|
103
|
-
const addCheckoutStepsToAnalytics_GA4 = (cart, TagManager, event) => {
|
|
104
|
-
if (!!!process.env.IS_TEST_ENV) {
|
|
105
|
-
const dataLayer = getDataLayer();
|
|
106
|
-
if (!!!dataLayer)
|
|
107
|
-
return;
|
|
108
|
-
dataLayer.push({ ecommerce: null, user_type: null });
|
|
109
|
-
const user_type = !!cart.customer_info && !!cart.customer_info.pro_proof_doc ? 'pro' : !!cart.customer_id ? 'connected' : '';
|
|
110
|
-
const newEcommData = (0, exports.getCheckoutData)(event, cart);
|
|
111
|
-
dataLayer.push({
|
|
112
|
-
event,
|
|
113
|
-
user_type,
|
|
114
|
-
ecommerce: newEcommData
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
exports.addCheckoutStepsToAnalytics_GA4 = addCheckoutStepsToAnalytics_GA4;
|
|
119
|
-
const getCheckoutData = (event, cart) => {
|
|
120
|
-
const coupon = getAppliedCartPromo(cart);
|
|
121
|
-
switch (true) {
|
|
122
|
-
case event === 'begin_checkout':
|
|
123
|
-
return Object.assign(Object.assign({ currency: cart.currency || 'CAD', value: cart.total }, (!!coupon ? { coupon: coupon } : {})), { items: cart.items.map((i, index) => {
|
|
124
|
-
return getCartItem_GA4(i, index, cart.currency || 'CAD');
|
|
125
|
-
}) });
|
|
126
|
-
case event === 'add_shipping_info':
|
|
127
|
-
return Object.assign(Object.assign({ currency: cart.currency || 'CAD', value: cart.total }, (!!coupon ? { coupon: coupon } : {})), { shipping_tier: !!cart.is_pickup
|
|
128
|
-
? 'Cueillette'
|
|
129
|
-
: !!cart.shipping_selected
|
|
130
|
-
? !!cart.shipping_selected.is_lowest
|
|
131
|
-
? 'Livraison standard'
|
|
132
|
-
: 'Livraison express'
|
|
133
|
-
: 'Livraison', items: cart.items.map((i, index) => {
|
|
134
|
-
return getCartItem_GA4(i, index, cart.currency || 'CAD');
|
|
135
|
-
}) });
|
|
136
|
-
case event === 'add_payment_info':
|
|
137
|
-
return Object.assign(Object.assign({ currency: cart.currency || 'CAD', value: cart.total }, (!!coupon ? { coupon: coupon } : {})), { payment_type: cart.paid_by ? cart.paid_by : '', items: cart.items.map((i, index) => {
|
|
138
|
-
return getCartItem_GA4(i, index, cart.currency || 'CAD');
|
|
139
|
-
}) });
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
exports.getCheckoutData = getCheckoutData;
|
|
143
|
-
const getDataLayer = () => {
|
|
144
|
-
if (typeof window != 'undefined') {
|
|
145
|
-
return window.dataLayer;
|
|
146
|
-
}
|
|
147
|
-
return undefined;
|
|
148
|
-
};
|
|
149
|
-
const addPurchaseToAnalytics_GT4 = (cart) => {
|
|
150
|
-
if (!!!process.env.IS_TEST_ENV) {
|
|
151
|
-
const dataLayer = getDataLayer();
|
|
152
|
-
if (!!!dataLayer)
|
|
153
|
-
return;
|
|
154
|
-
const allPromos = (0, discount_1.getCartPromo)(cart);
|
|
155
|
-
let coupon = null;
|
|
156
|
-
if (!!allPromos) {
|
|
157
|
-
const promo = allPromos.filter((x) => !!x.promo_code);
|
|
158
|
-
if (!!promo)
|
|
159
|
-
coupon = promo.find((x) => x.promo_code);
|
|
160
|
-
}
|
|
161
|
-
dataLayer.push({
|
|
162
|
-
event: 'purchase',
|
|
163
|
-
ecommerce: {
|
|
164
|
-
purchase: {
|
|
165
|
-
actionField: Object.assign({ id: cart.ref, affiliation: (!!cart.customer_info && !!cart.customer_info.customer_default_email) || cart.customer_id
|
|
166
|
-
? !!cart.customer_info && cart.customer_info.pro_title
|
|
167
|
-
? `client ${cart.customer_info.pro_title}`
|
|
168
|
-
: 'client connecté'
|
|
169
|
-
: 'invité', revenue: cart.total, tax: !!cart.total_taxes ? cart.total_taxes : (0, lodash_1.sumBy)(cart.taxes, (tax) => (0, lodash_1.sumBy)(tax.taxes, 'amount')), shipping: cart.shipping }, (!!coupon ? { coupon: coupon.promo_code } : {})),
|
|
170
|
-
products: cart.items.map((item) => getCartItem(item))
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
exports.addPurchaseToAnalytics_GT4 = addPurchaseToAnalytics_GT4;
|
|
177
|
-
const addAddToBasketToAnalytics_GT4 = (item, locale) => {
|
|
178
|
-
if (!!!process.env.IS_TEST_ENV) {
|
|
179
|
-
const dataLayer = getDataLayer();
|
|
180
|
-
if (!!!dataLayer)
|
|
181
|
-
return;
|
|
182
|
-
let items = [];
|
|
183
|
-
if (Array.isArray(item))
|
|
184
|
-
items = item;
|
|
185
|
-
else
|
|
186
|
-
items.push(item);
|
|
187
|
-
dataLayer.push({ ecommerce: null });
|
|
188
|
-
dataLayer.push({
|
|
189
|
-
event: 'addedToCart',
|
|
190
|
-
ecommerce: {
|
|
191
|
-
currency: items[0].regular_price.currency,
|
|
192
|
-
items: items.map((i) => {
|
|
193
|
-
const price = (0, products_1.getLowestPrice)(i).price;
|
|
194
|
-
return {
|
|
195
|
-
item_name: (0, functions_1.translate)(locale, i.name),
|
|
196
|
-
item_id: i.id,
|
|
197
|
-
price: price.amount,
|
|
198
|
-
item_category: !!i.category_name ? (0, functions_1.translate)(locale, i.category_name) : '',
|
|
199
|
-
item_variant: i.sku,
|
|
200
|
-
quantity: i.qte
|
|
201
|
-
};
|
|
202
|
-
})
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
exports.addAddToBasketToAnalytics_GT4 = addAddToBasketToAnalytics_GT4;
|
|
208
|
-
const addProductPageToAnalytics_GT4 = (product, locale) => {
|
|
209
|
-
if (!!!process.env.IS_TEST_ENV) {
|
|
210
|
-
if (!!!product.declinations.length)
|
|
211
|
-
return;
|
|
212
|
-
const dataLayer = getDataLayer();
|
|
213
|
-
if (!!!dataLayer)
|
|
214
|
-
return;
|
|
215
|
-
dataLayer.push({ ecommerce: null });
|
|
216
|
-
dataLayer.push({
|
|
217
|
-
ecommerce: {
|
|
218
|
-
currency: product.declinations[0].regular_price.currency,
|
|
219
|
-
impressions: product.declinations.map((d, idx) => {
|
|
220
|
-
const price = (0, products_1.getLowestPrice)(d).price;
|
|
221
|
-
return {
|
|
222
|
-
name: (0, functions_1.translate)(locale, d.name),
|
|
223
|
-
id: d.id,
|
|
224
|
-
price: price.amount,
|
|
225
|
-
brand: !!d.brand_name ? (0, functions_1.translate)(locale, d.brand_name) : '',
|
|
226
|
-
category: !!d.category_name ? (0, functions_1.translate)(locale, d.category_name) : '',
|
|
227
|
-
variant: d.sku,
|
|
228
|
-
list: 'Product page',
|
|
229
|
-
position: idx
|
|
230
|
-
};
|
|
231
|
-
})
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
exports.addProductPageToAnalytics_GT4 = addProductPageToAnalytics_GT4;
|
|
237
|
-
const addToDataLayer_GT4 = (data) => {
|
|
238
|
-
if (!!!process.env.IS_TEST_ENV) {
|
|
239
|
-
const dataLayer = getDataLayer();
|
|
240
|
-
if (!!!dataLayer)
|
|
241
|
-
return;
|
|
242
|
-
dataLayer.push({ ecommerce: null });
|
|
243
|
-
dataLayer.push(data);
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
exports.addToDataLayer_GT4 = addToDataLayer_GT4;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addToDataLayer_GT4 = exports.addProductPageToAnalytics_GT4 = exports.addAddToBasketToAnalytics_GT4 = exports.addPurchaseToAnalytics_GT4 = exports.getCheckoutData = exports.addCheckoutStepsToAnalytics_GA4 = exports.addLoggedCustomerToAnalytics_GA4 = exports.addPurchaseToAnalytics_GA4 = exports.addCheckoutStepsToAnalytics = exports.addPurchaseToAnalytics = exports.sendFormSubmitEventToAnalytics = void 0;
|
|
4
|
+
const discount_1 = require("addio-admin-sdk/dist/utils/discount");
|
|
5
|
+
const products_1 = require("addio-admin-sdk/dist/utils/products");
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
const functions_1 = require("./functions");
|
|
8
|
+
const getCartItem = (item) => {
|
|
9
|
+
return Object.assign(Object.assign(Object.assign({ id: item.sku, name: !!item.parent_name ? (0, functions_1.translate)('fr', item.parent_name) : '', variant: !!item.name ? (0, functions_1.translate)('fr', item.name) : '' }, (!!item.brand_name ? { brand: (0, functions_1.translate)('fr', item.brand_name) } : {})), (!!item.category_name ? { category: (0, functions_1.translate)('fr', item.category_name) } : {})), { price: (0, products_1.getLowestPrice)(item).price.amount, quantity: item.qte });
|
|
10
|
+
};
|
|
11
|
+
const sendFormSubmitEventToAnalytics = (form_id) => {
|
|
12
|
+
const dataLayer = getDataLayer();
|
|
13
|
+
if (!!!dataLayer)
|
|
14
|
+
return;
|
|
15
|
+
dataLayer.push({ event: 'form_submit', form_id });
|
|
16
|
+
};
|
|
17
|
+
exports.sendFormSubmitEventToAnalytics = sendFormSubmitEventToAnalytics;
|
|
18
|
+
const addPurchaseToAnalytics = (cart, TagManager) => {
|
|
19
|
+
const allPromos = (0, discount_1.getCartPromo)(cart);
|
|
20
|
+
let coupon = null;
|
|
21
|
+
if (!!allPromos) {
|
|
22
|
+
const promo = allPromos.filter((x) => !!x.promo_code);
|
|
23
|
+
if (!!promo)
|
|
24
|
+
coupon = promo.find((x) => x.promo_code);
|
|
25
|
+
}
|
|
26
|
+
TagManager.dataLayer({
|
|
27
|
+
dataLayer: {
|
|
28
|
+
event: 'purchase',
|
|
29
|
+
ecommerce: {
|
|
30
|
+
purchase: {
|
|
31
|
+
actionField: Object.assign({ id: cart.ref, affiliation: (!!cart.customer_info && !!cart.customer_info.customer_default_email) || cart.customer_id
|
|
32
|
+
? !!cart.customer_info && cart.customer_info.pro_title
|
|
33
|
+
? `client ${cart.customer_info.pro_title}`
|
|
34
|
+
: 'client connecté'
|
|
35
|
+
: 'invité', revenue: cart.total, tax: !!cart.total_taxes ? cart.total_taxes : (0, lodash_1.sumBy)(cart.taxes, (tax) => (0, lodash_1.sumBy)(tax.taxes, 'amount')), shipping: cart.shipping }, (!!coupon ? { coupon: coupon.promo_code } : {})),
|
|
36
|
+
products: cart.items.map((item) => getCartItem(item))
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
dataLayerName: 'purchase'
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
exports.addPurchaseToAnalytics = addPurchaseToAnalytics;
|
|
44
|
+
const addCheckoutStepsToAnalytics = (cart, TagManager, step, option) => {
|
|
45
|
+
TagManager.dataLayer({
|
|
46
|
+
dataLayer: {
|
|
47
|
+
event: 'checkout',
|
|
48
|
+
ecommerce: {
|
|
49
|
+
checkout: {
|
|
50
|
+
actionField: { step: step, option: !!option ? option : '' },
|
|
51
|
+
products: cart.items.map((item) => getCartItem(item))
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
dataLayerName: 'checkout'
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
exports.addCheckoutStepsToAnalytics = addCheckoutStepsToAnalytics;
|
|
59
|
+
const getAppliedCartPromo = (cart) => {
|
|
60
|
+
const allPromos = (0, discount_1.getCartPromo)(cart);
|
|
61
|
+
if (!!allPromos) {
|
|
62
|
+
const promo = allPromos.filter((x) => !!x.promo_code);
|
|
63
|
+
if (!!promo)
|
|
64
|
+
return promo.find((x) => x.promo_code);
|
|
65
|
+
if (!!allPromos.length)
|
|
66
|
+
return allPromos[0];
|
|
67
|
+
}
|
|
68
|
+
return;
|
|
69
|
+
};
|
|
70
|
+
const getCartItem_GA4 = (item, itemIndex, currency) => {
|
|
71
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({ item_id: item.sku, item_name: !!item.parent_name ? (0, functions_1.translate)('fr', item.parent_name) : '', currency: currency }, (!!(0, products_1.getLowestPrice)(item).promo
|
|
72
|
+
? { discount: item.regular_price.amount - (0, products_1.getLowestPrice)(item).price.amount }
|
|
73
|
+
: {})), { index: itemIndex, item_brand: !!item.brand_name ? (0, functions_1.translate)('fr', item.brand_name) : '', item_category: !!item.categories && !!item.categories.lvl0
|
|
74
|
+
? item.categories.lvl0
|
|
75
|
+
: !!item.category_name
|
|
76
|
+
? (0, functions_1.translate)('fr', item.category_name)
|
|
77
|
+
: '' }), (!!item.categories
|
|
78
|
+
? Object.assign(Object.assign(Object.assign(Object.assign({}, (!!item.categories.lvl1 ? { item_category2: item.categories.lvl1.split(' > ').slice(-1)[0] } : {})), (!!item.categories.lvl2 ? { item_category2: item.categories.lvl2.split(' > ').slice(-1)[0] } : {})), (!!item.categories.lvl3 ? { item_category2: item.categories.lvl3.split(' > ').slice(-1)[0] } : {})), (!!item.categories.lvl4 ? { item_category2: item.categories.lvl4.split(' > ').slice(-1)[0] } : {})) : {})), { item_variant: (0, functions_1.translate)('fr', item.name), price: item.regular_price.amount, quantity: item.qte });
|
|
79
|
+
};
|
|
80
|
+
const addPurchaseToAnalytics_GA4 = (cart, TagManager) => {
|
|
81
|
+
if (!!!process.env.IS_TEST_ENV) {
|
|
82
|
+
const coupon = getAppliedCartPromo(cart);
|
|
83
|
+
const affiliation = !!cart.customer_info && !!cart.customer_info.pro_proof_doc ? 'pro' : !!cart.customer_id ? 'connected' : 'guest';
|
|
84
|
+
TagManager.dataLayer({ dataLayer: { ecommerce: null } });
|
|
85
|
+
TagManager.dataLayer({
|
|
86
|
+
dataLayer: {
|
|
87
|
+
event: 'purchase',
|
|
88
|
+
ecommerce: Object.assign(Object.assign({ affiliation: affiliation, transaction_id: cart.ref, currency: cart.currency || 'CAD', value: cart.total, revenue: cart.total, tax: !!cart.total_taxes ? cart.total_taxes : (0, lodash_1.sumBy)(cart.taxes, (tax) => (0, lodash_1.sumBy)(tax.taxes, 'amount')), shipping: cart.shipping }, (!!coupon ? { coupon: coupon.promo_code } : {})), { items: cart.items.map((item, index) => getCartItem_GA4(item, index, cart.currency || 'CAD')) })
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
exports.addPurchaseToAnalytics_GA4 = addPurchaseToAnalytics_GA4;
|
|
94
|
+
const addLoggedCustomerToAnalytics_GA4 = (userType, TagManager, userID, clerkID) => {
|
|
95
|
+
if (!!!process.env.IS_TEST_ENV) {
|
|
96
|
+
TagManager.dataLayer({ dataLayer: { user_type: null } });
|
|
97
|
+
TagManager.dataLayer({
|
|
98
|
+
dataLayer: Object.assign({ event: 'login', user_type: userType, user_id: userID }, (!!clerkID ? { clerk_id: clerkID } : {}))
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
exports.addLoggedCustomerToAnalytics_GA4 = addLoggedCustomerToAnalytics_GA4;
|
|
103
|
+
const addCheckoutStepsToAnalytics_GA4 = (cart, TagManager, event) => {
|
|
104
|
+
if (!!!process.env.IS_TEST_ENV) {
|
|
105
|
+
const dataLayer = getDataLayer();
|
|
106
|
+
if (!!!dataLayer)
|
|
107
|
+
return;
|
|
108
|
+
dataLayer.push({ ecommerce: null, user_type: null });
|
|
109
|
+
const user_type = !!cart.customer_info && !!cart.customer_info.pro_proof_doc ? 'pro' : !!cart.customer_id ? 'connected' : '';
|
|
110
|
+
const newEcommData = (0, exports.getCheckoutData)(event, cart);
|
|
111
|
+
dataLayer.push({
|
|
112
|
+
event,
|
|
113
|
+
user_type,
|
|
114
|
+
ecommerce: newEcommData
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
exports.addCheckoutStepsToAnalytics_GA4 = addCheckoutStepsToAnalytics_GA4;
|
|
119
|
+
const getCheckoutData = (event, cart) => {
|
|
120
|
+
const coupon = getAppliedCartPromo(cart);
|
|
121
|
+
switch (true) {
|
|
122
|
+
case event === 'begin_checkout':
|
|
123
|
+
return Object.assign(Object.assign({ currency: cart.currency || 'CAD', value: cart.total }, (!!coupon ? { coupon: coupon } : {})), { items: cart.items.map((i, index) => {
|
|
124
|
+
return getCartItem_GA4(i, index, cart.currency || 'CAD');
|
|
125
|
+
}) });
|
|
126
|
+
case event === 'add_shipping_info':
|
|
127
|
+
return Object.assign(Object.assign({ currency: cart.currency || 'CAD', value: cart.total }, (!!coupon ? { coupon: coupon } : {})), { shipping_tier: !!cart.is_pickup
|
|
128
|
+
? 'Cueillette'
|
|
129
|
+
: !!cart.shipping_selected
|
|
130
|
+
? !!cart.shipping_selected.is_lowest
|
|
131
|
+
? 'Livraison standard'
|
|
132
|
+
: 'Livraison express'
|
|
133
|
+
: 'Livraison', items: cart.items.map((i, index) => {
|
|
134
|
+
return getCartItem_GA4(i, index, cart.currency || 'CAD');
|
|
135
|
+
}) });
|
|
136
|
+
case event === 'add_payment_info':
|
|
137
|
+
return Object.assign(Object.assign({ currency: cart.currency || 'CAD', value: cart.total }, (!!coupon ? { coupon: coupon } : {})), { payment_type: cart.paid_by ? cart.paid_by : '', items: cart.items.map((i, index) => {
|
|
138
|
+
return getCartItem_GA4(i, index, cart.currency || 'CAD');
|
|
139
|
+
}) });
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
exports.getCheckoutData = getCheckoutData;
|
|
143
|
+
const getDataLayer = () => {
|
|
144
|
+
if (typeof window != 'undefined') {
|
|
145
|
+
return window.dataLayer;
|
|
146
|
+
}
|
|
147
|
+
return undefined;
|
|
148
|
+
};
|
|
149
|
+
const addPurchaseToAnalytics_GT4 = (cart) => {
|
|
150
|
+
if (!!!process.env.IS_TEST_ENV) {
|
|
151
|
+
const dataLayer = getDataLayer();
|
|
152
|
+
if (!!!dataLayer)
|
|
153
|
+
return;
|
|
154
|
+
const allPromos = (0, discount_1.getCartPromo)(cart);
|
|
155
|
+
let coupon = null;
|
|
156
|
+
if (!!allPromos) {
|
|
157
|
+
const promo = allPromos.filter((x) => !!x.promo_code);
|
|
158
|
+
if (!!promo)
|
|
159
|
+
coupon = promo.find((x) => x.promo_code);
|
|
160
|
+
}
|
|
161
|
+
dataLayer.push({
|
|
162
|
+
event: 'purchase',
|
|
163
|
+
ecommerce: {
|
|
164
|
+
purchase: {
|
|
165
|
+
actionField: Object.assign({ id: cart.ref, affiliation: (!!cart.customer_info && !!cart.customer_info.customer_default_email) || cart.customer_id
|
|
166
|
+
? !!cart.customer_info && cart.customer_info.pro_title
|
|
167
|
+
? `client ${cart.customer_info.pro_title}`
|
|
168
|
+
: 'client connecté'
|
|
169
|
+
: 'invité', revenue: cart.total, tax: !!cart.total_taxes ? cart.total_taxes : (0, lodash_1.sumBy)(cart.taxes, (tax) => (0, lodash_1.sumBy)(tax.taxes, 'amount')), shipping: cart.shipping }, (!!coupon ? { coupon: coupon.promo_code } : {})),
|
|
170
|
+
products: cart.items.map((item) => getCartItem(item))
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
exports.addPurchaseToAnalytics_GT4 = addPurchaseToAnalytics_GT4;
|
|
177
|
+
const addAddToBasketToAnalytics_GT4 = (item, locale) => {
|
|
178
|
+
if (!!!process.env.IS_TEST_ENV) {
|
|
179
|
+
const dataLayer = getDataLayer();
|
|
180
|
+
if (!!!dataLayer)
|
|
181
|
+
return;
|
|
182
|
+
let items = [];
|
|
183
|
+
if (Array.isArray(item))
|
|
184
|
+
items = item;
|
|
185
|
+
else
|
|
186
|
+
items.push(item);
|
|
187
|
+
dataLayer.push({ ecommerce: null });
|
|
188
|
+
dataLayer.push({
|
|
189
|
+
event: 'addedToCart',
|
|
190
|
+
ecommerce: {
|
|
191
|
+
currency: items[0].regular_price.currency,
|
|
192
|
+
items: items.map((i) => {
|
|
193
|
+
const price = (0, products_1.getLowestPrice)(i).price;
|
|
194
|
+
return {
|
|
195
|
+
item_name: (0, functions_1.translate)(locale, i.name),
|
|
196
|
+
item_id: i.id,
|
|
197
|
+
price: price.amount,
|
|
198
|
+
item_category: !!i.category_name ? (0, functions_1.translate)(locale, i.category_name) : '',
|
|
199
|
+
item_variant: i.sku,
|
|
200
|
+
quantity: i.qte
|
|
201
|
+
};
|
|
202
|
+
})
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
exports.addAddToBasketToAnalytics_GT4 = addAddToBasketToAnalytics_GT4;
|
|
208
|
+
const addProductPageToAnalytics_GT4 = (product, locale) => {
|
|
209
|
+
if (!!!process.env.IS_TEST_ENV) {
|
|
210
|
+
if (!!!product.declinations.length)
|
|
211
|
+
return;
|
|
212
|
+
const dataLayer = getDataLayer();
|
|
213
|
+
if (!!!dataLayer)
|
|
214
|
+
return;
|
|
215
|
+
dataLayer.push({ ecommerce: null });
|
|
216
|
+
dataLayer.push({
|
|
217
|
+
ecommerce: {
|
|
218
|
+
currency: product.declinations[0].regular_price.currency,
|
|
219
|
+
impressions: product.declinations.map((d, idx) => {
|
|
220
|
+
const price = (0, products_1.getLowestPrice)(d).price;
|
|
221
|
+
return {
|
|
222
|
+
name: (0, functions_1.translate)(locale, d.name),
|
|
223
|
+
id: d.id,
|
|
224
|
+
price: price.amount,
|
|
225
|
+
brand: !!d.brand_name ? (0, functions_1.translate)(locale, d.brand_name) : '',
|
|
226
|
+
category: !!d.category_name ? (0, functions_1.translate)(locale, d.category_name) : '',
|
|
227
|
+
variant: d.sku,
|
|
228
|
+
list: 'Product page',
|
|
229
|
+
position: idx
|
|
230
|
+
};
|
|
231
|
+
})
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
exports.addProductPageToAnalytics_GT4 = addProductPageToAnalytics_GT4;
|
|
237
|
+
const addToDataLayer_GT4 = (data) => {
|
|
238
|
+
if (!!!process.env.IS_TEST_ENV) {
|
|
239
|
+
const dataLayer = getDataLayer();
|
|
240
|
+
if (!!!dataLayer)
|
|
241
|
+
return;
|
|
242
|
+
dataLayer.push({ ecommerce: null });
|
|
243
|
+
dataLayer.push(data);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
exports.addToDataLayer_GT4 = addToDataLayer_GT4;
|
|
247
247
|
//# sourceMappingURL=analytics.js.map
|
package/dist/utils/cart.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ICartItemPrices } from 'addio-admin-sdk/dist/Interfaces/Cart';
|
|
2
|
-
export declare const getPriceByCurrency: (prices: ICartItemPrices[], currencyTo: string) => ICartItemPrices;
|
|
3
|
-
export declare const getPromoCodeError: (errCode: string, locale?: string) => string;
|
|
1
|
+
import { ICartItemPrices } from 'addio-admin-sdk/dist/Interfaces/Cart';
|
|
2
|
+
export declare const getPriceByCurrency: (prices: ICartItemPrices[], currencyTo: string) => ICartItemPrices;
|
|
3
|
+
export declare const getPromoCodeError: (errCode: string, locale?: string) => string;
|
package/dist/utils/cart.js
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPromoCodeError = exports.getPriceByCurrency = void 0;
|
|
4
|
-
const Cart_1 = require("addio-admin-sdk/dist/Interfaces/Cart");
|
|
5
|
-
const errors_1 = require("addio-admin-sdk/dist/utils/errors");
|
|
6
|
-
const functions_1 = require("./functions");
|
|
7
|
-
const getPriceByCurrency = (prices, currencyTo) => {
|
|
8
|
-
if (typeof prices === 'number')
|
|
9
|
-
return {
|
|
10
|
-
amount: prices,
|
|
11
|
-
currency: currencyTo || 'CAD',
|
|
12
|
-
exchange_from: 'CAD',
|
|
13
|
-
exchange_rate: 1,
|
|
14
|
-
exchange_rate_date: new Date()
|
|
15
|
-
};
|
|
16
|
-
if (!Array.isArray(prices)) {
|
|
17
|
-
if (!!prices.amount)
|
|
18
|
-
return {
|
|
19
|
-
amount: prices.amount,
|
|
20
|
-
currency: currencyTo || 'CAD',
|
|
21
|
-
exchange_from: 'CAD',
|
|
22
|
-
exchange_rate: 1,
|
|
23
|
-
exchange_rate_date: new Date()
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
const price = prices.find((a) => a.currency === currencyTo);
|
|
27
|
-
if (!!!price)
|
|
28
|
-
throw new Error(`Product has'nt been set in that currency ${currencyTo}. Available currencies: ${prices
|
|
29
|
-
.map((a) => a.currency)
|
|
30
|
-
.join(', ')}`);
|
|
31
|
-
return price;
|
|
32
|
-
};
|
|
33
|
-
exports.getPriceByCurrency = getPriceByCurrency;
|
|
34
|
-
const getPromoCodeError = (errCode, locale = 'fr') => {
|
|
35
|
-
let message = '';
|
|
36
|
-
switch (errCode) {
|
|
37
|
-
case Cart_1.CartErrorEnum.GENERAL_ERROR_USER:
|
|
38
|
-
message = (0, functions_1.getStringByLang)(errors_1.cartErrorMsgs.generalErrors.user, locale);
|
|
39
|
-
break;
|
|
40
|
-
case Cart_1.CartErrorEnum.PROMO_CODE_WRONG_CODE:
|
|
41
|
-
message = (0, functions_1.getStringByLang)(errors_1.cartErrorMsgs.promoCode.wrongCode, locale);
|
|
42
|
-
break;
|
|
43
|
-
case Cart_1.CartErrorEnum.PROMO_CODE_USED:
|
|
44
|
-
message = (0, functions_1.getStringByLang)(errors_1.cartErrorMsgs.promoCode.used, locale);
|
|
45
|
-
break;
|
|
46
|
-
case Cart_1.CartErrorEnum.PROMO_CODE_CART_ALREADY_DISCOUNTED:
|
|
47
|
-
message = (0, functions_1.getStringByLang)(errors_1.cartErrorMsgs.promoCode.alreadyDiscounted, locale);
|
|
48
|
-
break;
|
|
49
|
-
case Cart_1.CartErrorEnum.PROMO_CODE_NO_SHIPPING_SELECTED:
|
|
50
|
-
message = (0, functions_1.getStringByLang)(errors_1.cartErrorMsgs.promoCode.chooseShippingFirst, locale);
|
|
51
|
-
break;
|
|
52
|
-
case Cart_1.CartErrorEnum.PROMO_CODE_FREE_SHIPPING:
|
|
53
|
-
message = (0, functions_1.getStringByLang)(errors_1.cartErrorMsgs.freeShipping.excludedState, locale);
|
|
54
|
-
break;
|
|
55
|
-
case Cart_1.CartErrorEnum.PROMO_CODE_NOT_ELIGIBLE:
|
|
56
|
-
message = (0, functions_1.getStringByLang)(errors_1.cartErrorMsgs.promoCode.notEligible, locale);
|
|
57
|
-
break;
|
|
58
|
-
case Cart_1.CartErrorEnum.GENERAL_ERROR:
|
|
59
|
-
default:
|
|
60
|
-
message = (0, functions_1.getStringByLang)(errors_1.cartErrorMsgs.generalErrors.global, locale);
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
return message;
|
|
64
|
-
};
|
|
65
|
-
exports.getPromoCodeError = getPromoCodeError;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPromoCodeError = exports.getPriceByCurrency = void 0;
|
|
4
|
+
const Cart_1 = require("addio-admin-sdk/dist/Interfaces/Cart");
|
|
5
|
+
const errors_1 = require("addio-admin-sdk/dist/utils/errors");
|
|
6
|
+
const functions_1 = require("./functions");
|
|
7
|
+
const getPriceByCurrency = (prices, currencyTo) => {
|
|
8
|
+
if (typeof prices === 'number')
|
|
9
|
+
return {
|
|
10
|
+
amount: prices,
|
|
11
|
+
currency: currencyTo || 'CAD',
|
|
12
|
+
exchange_from: 'CAD',
|
|
13
|
+
exchange_rate: 1,
|
|
14
|
+
exchange_rate_date: new Date()
|
|
15
|
+
};
|
|
16
|
+
if (!Array.isArray(prices)) {
|
|
17
|
+
if (!!prices.amount)
|
|
18
|
+
return {
|
|
19
|
+
amount: prices.amount,
|
|
20
|
+
currency: currencyTo || 'CAD',
|
|
21
|
+
exchange_from: 'CAD',
|
|
22
|
+
exchange_rate: 1,
|
|
23
|
+
exchange_rate_date: new Date()
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const price = prices.find((a) => a.currency === currencyTo);
|
|
27
|
+
if (!!!price)
|
|
28
|
+
throw new Error(`Product has'nt been set in that currency ${currencyTo}. Available currencies: ${prices
|
|
29
|
+
.map((a) => a.currency)
|
|
30
|
+
.join(', ')}`);
|
|
31
|
+
return price;
|
|
32
|
+
};
|
|
33
|
+
exports.getPriceByCurrency = getPriceByCurrency;
|
|
34
|
+
const getPromoCodeError = (errCode, locale = 'fr') => {
|
|
35
|
+
let message = '';
|
|
36
|
+
switch (errCode) {
|
|
37
|
+
case Cart_1.CartErrorEnum.GENERAL_ERROR_USER:
|
|
38
|
+
message = (0, functions_1.getStringByLang)(errors_1.cartErrorMsgs.generalErrors.user, locale);
|
|
39
|
+
break;
|
|
40
|
+
case Cart_1.CartErrorEnum.PROMO_CODE_WRONG_CODE:
|
|
41
|
+
message = (0, functions_1.getStringByLang)(errors_1.cartErrorMsgs.promoCode.wrongCode, locale);
|
|
42
|
+
break;
|
|
43
|
+
case Cart_1.CartErrorEnum.PROMO_CODE_USED:
|
|
44
|
+
message = (0, functions_1.getStringByLang)(errors_1.cartErrorMsgs.promoCode.used, locale);
|
|
45
|
+
break;
|
|
46
|
+
case Cart_1.CartErrorEnum.PROMO_CODE_CART_ALREADY_DISCOUNTED:
|
|
47
|
+
message = (0, functions_1.getStringByLang)(errors_1.cartErrorMsgs.promoCode.alreadyDiscounted, locale);
|
|
48
|
+
break;
|
|
49
|
+
case Cart_1.CartErrorEnum.PROMO_CODE_NO_SHIPPING_SELECTED:
|
|
50
|
+
message = (0, functions_1.getStringByLang)(errors_1.cartErrorMsgs.promoCode.chooseShippingFirst, locale);
|
|
51
|
+
break;
|
|
52
|
+
case Cart_1.CartErrorEnum.PROMO_CODE_FREE_SHIPPING:
|
|
53
|
+
message = (0, functions_1.getStringByLang)(errors_1.cartErrorMsgs.freeShipping.excludedState, locale);
|
|
54
|
+
break;
|
|
55
|
+
case Cart_1.CartErrorEnum.PROMO_CODE_NOT_ELIGIBLE:
|
|
56
|
+
message = (0, functions_1.getStringByLang)(errors_1.cartErrorMsgs.promoCode.notEligible, locale);
|
|
57
|
+
break;
|
|
58
|
+
case Cart_1.CartErrorEnum.GENERAL_ERROR:
|
|
59
|
+
default:
|
|
60
|
+
message = (0, functions_1.getStringByLang)(errors_1.cartErrorMsgs.generalErrors.global, locale);
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
return message;
|
|
64
|
+
};
|
|
65
|
+
exports.getPromoCodeError = getPromoCodeError;
|
|
66
66
|
//# sourceMappingURL=cart.js.map
|