@lancom/shared 0.0.127 → 0.0.130
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/assets/js/utils/gtm.js +45 -13
- package/components/checkout/cart/cart_price_info/cart-price-info.vue +5 -4
- package/components/editor/editor.vue +1 -1
- package/components/products/products_autocomplete/products-autocomplete.vue +7 -0
- package/middleware/page-info.js +1 -1
- package/mixins/payment.js +24 -13
- package/package.json +1 -1
- package/store/cart.js +13 -1
package/assets/js/utils/gtm.js
CHANGED
|
@@ -1,18 +1,50 @@
|
|
|
1
1
|
const gtm = {
|
|
2
|
-
push({
|
|
3
|
-
id,
|
|
4
|
-
total,
|
|
5
|
-
tax,
|
|
6
|
-
shipping,
|
|
7
|
-
products
|
|
8
|
-
}) {
|
|
2
|
+
push(data, skipReset) {
|
|
9
3
|
window.dataLayer = window.dataLayer || [];
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
if (!skipReset) {
|
|
5
|
+
window.dataLayer.push(function() {
|
|
6
|
+
this.reset();
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
window.dataLayer.push(data);
|
|
10
|
+
},
|
|
11
|
+
addToCart(entities, pricing) {
|
|
12
|
+
this.push({
|
|
13
|
+
event: 'add_to_cart',
|
|
14
|
+
value: pricing.totalPriceWithoutTax,
|
|
15
|
+
currency: 'AUD',
|
|
16
|
+
items: entities.reduce((products, { product, simpleProducts }) => {
|
|
17
|
+
return [
|
|
18
|
+
...products,
|
|
19
|
+
...simpleProducts
|
|
20
|
+
.filter(({ amount }) => amount > 0)
|
|
21
|
+
.map(({ SKU, amount, _id }) => ({
|
|
22
|
+
item_id: SKU,
|
|
23
|
+
item_name: product.name,
|
|
24
|
+
item_brand: product.brand.name,
|
|
25
|
+
currency: 'AUD',
|
|
26
|
+
price: pricing.products[product._id]?.products[_id]?.totalPriceWithoutTax,
|
|
27
|
+
quantity: amount
|
|
28
|
+
}))
|
|
29
|
+
];
|
|
30
|
+
}, [])
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
removeFromCart(simpleProducts, pricing) {
|
|
34
|
+
const removeSimpleProducts = simpleProducts.filter(({ amount }) => amount > 0);
|
|
35
|
+
const spPricing = Object.keys(pricing.products)
|
|
36
|
+
.filter(k => !!pricing.products[k].products)
|
|
37
|
+
.reduce((res, k) => ({ ...res, ...pricing.products[k].products }), {});
|
|
38
|
+
gtm.push({
|
|
39
|
+
event: 'remove_from_cart',
|
|
40
|
+
value: removeSimpleProducts.reduce((sum, { guid }) => sum + (spPricing[guid]?.totalPriceWithoutTax || 0), 0),
|
|
41
|
+
currency: 'AUD',
|
|
42
|
+
items: removeSimpleProducts.map(({ SKU, amount, guid }) => ({
|
|
43
|
+
item_id: SKU,
|
|
44
|
+
currency: 'AUD',
|
|
45
|
+
price: spPricing[guid]?.totalPriceWithoutTax,
|
|
46
|
+
quantity: amount
|
|
47
|
+
}))
|
|
16
48
|
});
|
|
17
49
|
}
|
|
18
50
|
};
|
|
@@ -53,15 +53,16 @@ export default {
|
|
|
53
53
|
this.calculatePriceWithDebounce();
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
|
-
mounted() {
|
|
57
|
-
this.
|
|
56
|
+
async mounted() {
|
|
57
|
+
await this.calculatePrice();
|
|
58
|
+
this.$emit('loaded', this.cartPricing);
|
|
58
59
|
},
|
|
59
60
|
methods: {
|
|
60
61
|
...mapActions([
|
|
61
62
|
'calculateCartPrice'
|
|
62
63
|
]),
|
|
63
|
-
calculatePrice() {
|
|
64
|
-
this.calculateCartPrice({ shop: this.shop });
|
|
64
|
+
async calculatePrice() {
|
|
65
|
+
await this.calculateCartPrice({ shop: this.shop });
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
};
|
|
@@ -177,7 +177,7 @@ export default {
|
|
|
177
177
|
},
|
|
178
178
|
proceedToCard() {
|
|
179
179
|
const entities = generateCartProducts(this.product, this.template.simpleProducts, this.template.layers, this.isPrintPricing, this.layerThumbnails);
|
|
180
|
-
this.addToCart({ entities, shop: this.shop });
|
|
180
|
+
this.addToCart({ entities, shop: this.shop, pricing: this.productPricing });
|
|
181
181
|
this.showCartModal(async () => {
|
|
182
182
|
const message = 'Do you wish to continue with editing the current design or reset the editor?';
|
|
183
183
|
const reset = await this.showConfirmationModal(message, {
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
<script>
|
|
50
50
|
import debounce from 'lodash.debounce';
|
|
51
51
|
import { mapGetters } from 'vuex';
|
|
52
|
+
import gtm from '@lancom/shared/assets/js/utils/gtm';
|
|
52
53
|
import api from '@lancom/shared/assets/js/api';
|
|
53
54
|
import ProductsAutocompleteItem from './products_autocomplete-item/products-autocomplete-item';
|
|
54
55
|
|
|
@@ -97,6 +98,12 @@ export default {
|
|
|
97
98
|
},
|
|
98
99
|
async search() {
|
|
99
100
|
this.searching = true;
|
|
101
|
+
if (this.text) {
|
|
102
|
+
gtm.push({
|
|
103
|
+
event: 'search',
|
|
104
|
+
search_term: this.text
|
|
105
|
+
});
|
|
106
|
+
}
|
|
100
107
|
try {
|
|
101
108
|
this.products = this.text ? await api.searchProducts(this.shop._id, this.text) : [];
|
|
102
109
|
} catch (e) {
|
package/middleware/page-info.js
CHANGED
|
@@ -9,7 +9,7 @@ export default async function ({ store, route, redirect }) {
|
|
|
9
9
|
};
|
|
10
10
|
const routeInfo = await store.dispatch('page/fetchRouteInfo', data);
|
|
11
11
|
if (routeInfo?.type === 'redirect' && routeInfo.redirectTo) {
|
|
12
|
-
redirect(routeInfo.redirectTo);
|
|
12
|
+
redirect(301, routeInfo.redirectTo);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
}
|
package/mixins/payment.js
CHANGED
|
@@ -63,19 +63,30 @@ export default {
|
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
65
|
sendConversionData() {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
66
|
+
gtm.push({
|
|
67
|
+
event: 'purchase',
|
|
68
|
+
transaction_id: this.orderData.code,
|
|
69
|
+
value: this.orderData.total,
|
|
70
|
+
currency: 'AUD',
|
|
71
|
+
coupon: this.orderData.couponCode,
|
|
72
|
+
shipping: this.orderData.shippingTotal,
|
|
73
|
+
tax: this.orderData.totalGST - this.orderData.total,
|
|
74
|
+
items: this.orderData.products.reduce((products, { product, simpleProducts }) => {
|
|
75
|
+
return [
|
|
76
|
+
...products,
|
|
77
|
+
...simpleProducts
|
|
78
|
+
.filter(({ amount }) => amount > 0)
|
|
79
|
+
.map(({ SKU, productCost, amount }) => ({
|
|
80
|
+
item_id: SKU,
|
|
81
|
+
item_name: product.name,
|
|
82
|
+
item_brand: product.brand.name,
|
|
83
|
+
price: productCost,
|
|
84
|
+
currency: 'AUD',
|
|
85
|
+
quantity: amount
|
|
86
|
+
}))
|
|
87
|
+
];
|
|
88
|
+
}, [])
|
|
89
|
+
});
|
|
79
90
|
},
|
|
80
91
|
clearFailedCharge() {
|
|
81
92
|
this.errorMessage = null;
|
package/package.json
CHANGED
package/store/cart.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import groupBy from 'lodash/groupBy';
|
|
2
2
|
import api from '@lancom/shared/assets/js/api';
|
|
3
|
+
import gtm from '@lancom/shared/assets/js/utils/gtm';
|
|
3
4
|
import { getPrintTypeSizePricing } from '@lancom/shared/assets/js/utils/prints';
|
|
4
5
|
|
|
5
6
|
export const state = () => ({
|
|
@@ -63,7 +64,8 @@ export const getters = {
|
|
|
63
64
|
};
|
|
64
65
|
|
|
65
66
|
export const actions = {
|
|
66
|
-
async addToCart({ state, commit }, { entities, shop }) {
|
|
67
|
+
async addToCart({ state, commit }, { entities, shop, pricing }) {
|
|
68
|
+
const addingEntities = [...entities];
|
|
67
69
|
const withoutPrints = e => (e.prints || []).length === 0;
|
|
68
70
|
entities = entities.map(e => {
|
|
69
71
|
const entitiy = withoutPrints(e) && state.entities.find(e2 => withoutPrints(e2) && e2?.product?._id === e?.product?._id);
|
|
@@ -89,6 +91,9 @@ export const actions = {
|
|
|
89
91
|
commit('setId', cart._id);
|
|
90
92
|
commit('setEntities', cart.entities);
|
|
91
93
|
}
|
|
94
|
+
if (pricing) {
|
|
95
|
+
gtm.addToCart(addingEntities, pricing);
|
|
96
|
+
}
|
|
92
97
|
},
|
|
93
98
|
async removeSimpleProductsFromCart({ commit, state }, { simpleProducts, shop }) {
|
|
94
99
|
const removeGuids = (simpleProducts || []).map(e => e.guid);
|
|
@@ -99,10 +104,17 @@ export const actions = {
|
|
|
99
104
|
const payload = { _id: state.id, entities };
|
|
100
105
|
await api.saveCart(payload, shop._id);
|
|
101
106
|
commit('setEntities', entities);
|
|
107
|
+
if (state.cartPricing) {
|
|
108
|
+
gtm.removeFromCart(simpleProducts, state.cartPricing);
|
|
109
|
+
}
|
|
102
110
|
},
|
|
103
111
|
async removeSupplier({ commit, state }, { supplier, shop }) {
|
|
104
112
|
const brands = supplier.brands.map(({ _id }) => _id);
|
|
105
113
|
const entities = state.entities.filter(entity => !brands.includes(entity.product.brand._id));
|
|
114
|
+
if (state.cartPricing) {
|
|
115
|
+
const simpleProducts = entities.reduce((items, entity) => [...items, ...entity.simpleProducts], []);
|
|
116
|
+
gtm.removeFromCart(simpleProducts, state.cartPricing);
|
|
117
|
+
}
|
|
106
118
|
const payload = { _id: state.id, entities };
|
|
107
119
|
await api.saveCart(payload, shop._id);
|
|
108
120
|
commit('setEntities', entities);
|