@lancom/shared 0.0.174 → 0.0.175

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.
@@ -62,8 +62,15 @@ export function getPrintsFromLayers(layers, product) {
62
62
  return [...prints.values()];
63
63
  }
64
64
 
65
- export function getPrintTypeSizePricing(printType, sizeId) {
66
- return (printType?.printAreas || [])
65
+ export function getPrintTypeSizePricing(printType, sizeId, coupon) {
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
+ });
73
+ return couponPrintArea || (printType?.printAreas || [])
67
74
  .find(({ printSizes }) => {
68
75
  return printSizes.map(size => size?._id || size).includes(sizeId);
69
76
  }) || (printType?.printAreas || [])[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lancom/shared",
3
- "version": "0.0.174",
3
+ "version": "0.0.175",
4
4
  "description": "lancom common scripts",
5
5
  "author": "e.tokovenko <e.tokovenko@gmail.com>",
6
6
  "repository": {
package/store/cart.js CHANGED
@@ -218,17 +218,21 @@ function generateCalculatePriceData(entities, suburb, suppliersWithRates, coupon
218
218
  entities: entities.map(({ _id, guid, prints, simpleProducts, product }) => ({
219
219
  _id,
220
220
  guid,
221
+ name: product.name,
221
222
  brand: getSimpleObj(product.brand),
222
- simpleProducts: simpleProducts.map(({ _id, guid, amount, pricing, unprintedPricing, weight = 0 }) => ({
223
- amount,
224
- pricing: (prints || []).length > 0 ? pricing : unprintedPricing,
225
- weight: product.weight,
226
- volume: product.volume,
227
- guid,
228
- _id
229
- })).filter(({ amount }) => +amount > 0),
223
+ simpleProducts: simpleProducts.map(({ _id, guid, amount, pricing, unprintedPricing, weight = 0 }) => {
224
+ const couponProduct = (coupon?.products || []).find(({ products }) => products.includes(product._id));
225
+ return {
226
+ amount,
227
+ pricing: couponProduct?.pricing || ((prints || []).length > 0 ? pricing : unprintedPricing),
228
+ weight: product.weight,
229
+ volume: product.volume,
230
+ guid,
231
+ _id
232
+ };
233
+ }).filter(({ amount }) => +amount > 0),
230
234
  prints: (prints || []).map(print => {
231
- const { setupCost, freeSetupOver, printCost } = getPrintTypeSizePricing(print.printType, print.printSize?._id) || {};
235
+ const { setupCost, freeSetupOver, printCost } = getPrintTypeSizePricing(print.printType, print.printSize?._id, coupon) || {};
232
236
  return {
233
237
  costType: print.printType.costType,
234
238
  setupCost,
package/store/index.js CHANGED
@@ -56,6 +56,13 @@ export const actions = {
56
56
  if (state.cart?.id) {
57
57
  const cart = await api.fetchCartById(shop._id, state.cart?.id);
58
58
  commit('cart/setCart', cart);
59
+ if (state.cart?.coupon) {
60
+ try {
61
+ const code = state.cart?.coupon.code || state.cart?.coupon;
62
+ const coupon = await api.fetchCouponByCode(shop._id, code);
63
+ commit('cart/setCoupon', coupon);
64
+ } catch (e) {}
65
+ }
59
66
  dispatch('cart/calculateCartPrice', { shop });
60
67
  }
61
68
  }