@lancom/shared 0.0.177 → 0.0.179

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.
@@ -28,23 +28,25 @@ const gtm = {
28
28
  });
29
29
  },
30
30
  viewCart(entities, pricing) {
31
- this.push({
32
- event: 'view_cart',
33
- value: pricing.totalPriceWithoutTax,
34
- currency: 'AUD',
35
- coupon: pricing.coupon?.code,
36
- items: entities.reduce((products, { guid: productGuid, product, simpleProducts }) => {
37
- return [
38
- ...products,
39
- ...simpleProducts
40
- .filter(({ amount }) => amount > 0)
41
- .map((sp) => ({
42
- ...getOrderItem(product, sp),
43
- price: pricing.products[productGuid]?.products[sp.guid]?.priceWithoutTax
44
- }))
45
- ];
46
- }, [])
47
- });
31
+ if (pricing) {
32
+ this.push({
33
+ event: 'view_cart',
34
+ value: pricing.totalPriceWithoutTax,
35
+ currency: 'AUD',
36
+ coupon: pricing.coupon?.code,
37
+ items: entities.reduce((products, { guid: productGuid, product, simpleProducts }) => {
38
+ return [
39
+ ...products,
40
+ ...simpleProducts
41
+ .filter(({ amount }) => amount > 0)
42
+ .map((sp) => ({
43
+ ...getOrderItem(product, sp),
44
+ price: pricing.products[productGuid]?.products[sp.guid]?.priceWithoutTax
45
+ }))
46
+ ];
47
+ }, [])
48
+ });
49
+ }
48
50
  },
49
51
  removeFromCart(simpleProducts, pricing) {
50
52
  const removeSimpleProducts = simpleProducts.filter(({ amount }) => amount > 0);
@@ -64,12 +64,12 @@ export function getPrintsFromLayers(layers, product) {
64
64
 
65
65
  export function getPrintTypeSizePricing(printType, sizeId, coupon) {
66
66
  let couponPrintArea = null;
67
- (coupon?.prints || [])
68
- .forEach(({ printAreas, printTypes }) => {
69
- if (printTypes.includes(printType._id)) {
70
- couponPrintArea = couponPrintArea || printAreas.find(({ printSizes }) => printSizes.includes(sizeId))
71
- }
72
- });
67
+ // (coupon?.prints || [])
68
+ // .forEach(({ printAreas, printTypes }) => {
69
+ // if (printTypes.includes(printType._id)) {
70
+ // couponPrintArea = couponPrintArea || printAreas.find(({ printSizes }) => printSizes.includes(sizeId))
71
+ // }
72
+ // });
73
73
  return couponPrintArea || (printType?.printAreas || [])
74
74
  .find(({ printSizes }) => {
75
75
  return printSizes.map(size => size?._id || size).includes(sizeId);
@@ -24,6 +24,10 @@
24
24
  filled: code
25
25
  }"
26
26
  @keydown.enter="validateCoupon" />
27
+ <span
28
+ v-if="value"
29
+ class="CouponSelect__clear"
30
+ @click="clearCoupon()">remove coupon</span>
27
31
  </div>
28
32
  <div class="col-5">
29
33
  <btn
@@ -44,19 +48,24 @@
44
48
  Not valid coupon
45
49
  </span>
46
50
  </validation-provider>
47
- <div v-if="value">
51
+ <div v-if="value && pricing">
48
52
  <div
49
53
  v-if="isValidPricing"
50
54
  class="lc_h4">
51
55
  <span v-if="value.showCouponIsApplied">
52
56
  COUPON APPLIED
57
+ <span v-if="pricing.totalsWithoutCoupon">
58
+ : {{ pricing.totalsWithoutCoupon.totalPrice - pricing.totalPrice | price }} OFF
59
+ </span>
53
60
  </span>
54
61
  <span v-else>
55
62
  {{ value.value | price }} OFF
56
63
  </span>
57
- <span
58
- class="CouponSelect__clear"
59
- @click="clearCoupon()">remove</span>
64
+ </div>
65
+ <div
66
+ v-else-if="pricing.couponError"
67
+ class="lc_caption form-help is-danger">
68
+ {{ pricing.couponError }}
60
69
  </div>
61
70
  <div
62
71
  v-else
@@ -99,7 +108,7 @@ export default {
99
108
  computed: {
100
109
  ...mapGetters(['shop']),
101
110
  isValidPricing() {
102
- return !this.value.minOrderValue || this.pricing.coupon;
111
+ return !this.value?.minOrderValue || this.pricing.coupon;
103
112
  },
104
113
  model: {
105
114
  get() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lancom/shared",
3
- "version": "0.0.177",
3
+ "version": "0.0.179",
4
4
  "description": "lancom common scripts",
5
5
  "author": "e.tokovenko <e.tokovenko@gmail.com>",
6
6
  "repository": {
package/store/cart.js CHANGED
@@ -9,6 +9,7 @@ export const state = () => ({
9
9
  entities: [],
10
10
  suburb: null,
11
11
  coupon: null,
12
+ cartPricingCalculating: false,
12
13
  cartPricing: null,
13
14
  cartPricingError: null
14
15
  });
@@ -44,6 +45,7 @@ const getPrintsQuantities = entities => {
44
45
  export const getters = {
45
46
  entities: ({ entities }) => entities,
46
47
  coupon: ({ coupon }) => coupon,
48
+ cartPricingCalculating: ({ cartPricingCalculating }) => cartPricingCalculating,
47
49
  simpleProducts: ({ entities }) => entities.reduce((simpleProducts, entity) => [...simpleProducts, ...(entity.simpleProducts || [])], []),
48
50
  notEmptySimpleProducts: (state, { simpleProducts }) => simpleProducts.filter(e => e.amount > 0),
49
51
  simpleProductsQuantity: (state, { notEmptySimpleProducts }) => notEmptySimpleProducts.reduce((quantity, sp) => quantity + sp.amount, 0),
@@ -128,6 +130,7 @@ export const actions = {
128
130
  const selectedSuppliersWithRates = cartPricing?.shipping?.suppliersWithRates;
129
131
  const payload = generateCalculatePriceData(entities, suburb, null, coupon, selectedSuppliersWithRates);
130
132
  try {
133
+ commit('setCartPricingCalculating', true);
131
134
  const response = await api.calculateProductPrice(payload, shop._id);
132
135
  commit('setCartPricing', response);
133
136
  commit('setCartPricingError', null);
@@ -135,6 +138,8 @@ export const actions = {
135
138
  const { error = 'Error calculate pricing' } = e.response?.data || {};
136
139
  commit('setCartPricingError', error);
137
140
  commit('setCartPricing', null);
141
+ } finally {
142
+ commit('setCartPricingCalculating', false);
138
143
  }
139
144
  },
140
145
  async setSimpleProductAmount({ state, commit }, { guid, amount, shop }) {
@@ -165,6 +170,7 @@ export const actions = {
165
170
  }));
166
171
  const payload = generateCalculatePriceData(entities, suburb, suppliersWithRates, coupon);
167
172
  try {
173
+ commit('setCartPricingCalculating', true);
168
174
  const response = await api.calculateProductPrice(payload, shop._id);
169
175
  commit('setCartPricing', response);
170
176
  commit('setCartPricingError', null);
@@ -172,6 +178,8 @@ export const actions = {
172
178
  const { error = 'Error calculate pricing' } = e.response?.data || {};
173
179
  commit('setCartPricingError', error);
174
180
  commit('setCartPricing', null);
181
+ } finally {
182
+ commit('setCartPricingCalculating', false);
175
183
  }
176
184
  }
177
185
  };
@@ -196,6 +204,9 @@ export const mutations = {
196
204
  setCartPricing(state, price) {
197
205
  state.cartPricing = price;
198
206
  },
207
+ setCartPricingCalculating(state, calculating) {
208
+ state.cartPricingCalculating = calculating;
209
+ },
199
210
  setCartPricingError(state, error) {
200
211
  state.cartPricingError = error;
201
212
  },
@@ -218,13 +229,14 @@ function generateCalculatePriceData(entities, suburb, suppliersWithRates, coupon
218
229
  entities: entities.map(({ _id, guid, prints, simpleProducts, product }) => ({
219
230
  _id,
220
231
  guid,
232
+ productId: product._id,
221
233
  name: product.name,
222
234
  brand: getSimpleObj(product.brand),
223
235
  simpleProducts: simpleProducts.map(({ _id, guid, amount, pricing, unprintedPricing, weight = 0 }) => {
224
- const couponProduct = (coupon?.products || []).find(({ products }) => products.includes(product._id));
236
+ // const couponProduct = (coupon?.products || []).find(({ products, onlyPrinted }) => products.includes(product._id) && (!onlyPrinted || (prints || []).length > 0));
225
237
  return {
226
238
  amount,
227
- pricing: couponProduct?.pricing || ((prints || []).length > 0 ? pricing : unprintedPricing),
239
+ pricing: ((prints || []).length > 0 ? pricing : unprintedPricing),
228
240
  weight: product.weight,
229
241
  volume: product.volume,
230
242
  guid,