@azzas/azzas-tracker-web 2.0.0-preview.16 → 2.0.0-preview.18

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.
@@ -2909,6 +2909,12 @@ var AzzasTracker = function() {
2909
2909
  }
2910
2910
  });
2911
2911
  // src/params/adapters/orderForm/utils.ts
2912
+ var getOrderFormItems = function(orderForm) {
2913
+ var idSelected = orderForm === null || orderForm === void 0 ? void 0 : orderForm.selected;
2914
+ return idSelected ? orderForm.items.filter(function(item) {
2915
+ return item.id === idSelected;
2916
+ }) : orderForm.items;
2917
+ };
2912
2918
  var getItemCategory6 = function(item) {
2913
2919
  var _text_match;
2914
2920
  var categories = item === null || item === void 0 ? void 0 : item.productCategories;
@@ -2929,11 +2935,27 @@ var AzzasTracker = function() {
2929
2935
  var deepest = (_validHierarchy_ = validHierarchy[validHierarchy.length - 1]) !== null && _validHierarchy_ !== void 0 ? _validHierarchy_ : "";
2930
2936
  return capitalize(deepest);
2931
2937
  };
2932
- var getOrderFormItems = function(orderForm) {
2933
- var idSelected = orderForm === null || orderForm === void 0 ? void 0 : orderForm.selected;
2934
- return idSelected ? orderForm.items.filter(function(item) {
2935
- return item.id === idSelected;
2936
- }) : orderForm.items;
2938
+ var getPaymentType2 = function(context) {
2939
+ var _context_orderForm_paymentData, _context_orderForm_paymentData1, _system_name;
2940
+ if (context.payment_type) return context.payment_type;
2941
+ if (!context.orderForm) return null;
2942
+ var payments = ((_context_orderForm_paymentData = context.orderForm.paymentData) === null || _context_orderForm_paymentData === void 0 ? void 0 : _context_orderForm_paymentData.payments) || [];
2943
+ var systems = ((_context_orderForm_paymentData1 = context.orderForm.paymentData) === null || _context_orderForm_paymentData1 === void 0 ? void 0 : _context_orderForm_paymentData1.paymentSystems) || [];
2944
+ if (!payments.length || !systems.length) return null;
2945
+ var selectedPayment = payments.find(function(p) {
2946
+ return p === null || p === void 0 ? void 0 : p.paymentSystem;
2947
+ }) || payments[0];
2948
+ var id = String((selectedPayment === null || selectedPayment === void 0 ? void 0 : selectedPayment.paymentSystem) || "").trim();
2949
+ if (!id) return null;
2950
+ var system = systems.find(function(s) {
2951
+ return String(s.id) === id;
2952
+ });
2953
+ var name = (system === null || system === void 0 ? void 0 : (_system_name = system.name) === null || _system_name === void 0 ? void 0 : _system_name.toLowerCase()) || "";
2954
+ var match = paymentTypeMap.find(function(param) {
2955
+ var _param = _sliced_to_array(param, 1), key = _param[0];
2956
+ return name.includes(key);
2957
+ });
2958
+ return match ? match[1] : null;
2937
2959
  };
2938
2960
  // src/params/adapters/orderForm/index.ts
2939
2961
  var orderFormAdapter = _object_spread_props(_object_spread({}, metaAdapter), {
@@ -2948,7 +2970,7 @@ var AzzasTracker = function() {
2948
2970
  index: (_ref1 = context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.index) !== null && _ref1 !== void 0 ? _ref1 : index + 1,
2949
2971
  item_brand: (_ref2 = (_item_additionalInfo = item.additionalInfo) === null || _item_additionalInfo === void 0 ? void 0 : _item_additionalInfo.brandName) !== null && _ref2 !== void 0 ? _ref2 : null,
2950
2972
  item_name: (_ref3 = item === null || item === void 0 ? void 0 : item.name.replace(item === null || item === void 0 ? void 0 : item.skuName, "").trim()) !== null && _ref3 !== void 0 ? _ref3 : null,
2951
- price: (item === null || item === void 0 ? void 0 : item.price) / 100,
2973
+ price: (item === null || item === void 0 ? void 0 : item.sellingPrice) / 100,
2952
2974
  discount: ((item === null || item === void 0 ? void 0 : item.listPrice) - (item === null || item === void 0 ? void 0 : item.sellingPrice)) / 100,
2953
2975
  item_variant: (_ref4 = item === null || item === void 0 ? void 0 : (_item_skuName = item.skuName) === null || _item_skuName === void 0 ? void 0 : (_item_skuName_split_ = _item_skuName.split(" - ")[0]) === null || _item_skuName_split_ === void 0 ? void 0 : (_item_skuName_split__split_pop = _item_skuName_split_.split("_").pop()) === null || _item_skuName_split__split_pop === void 0 ? void 0 : _item_skuName_split__split_pop.trim()) !== null && _ref4 !== void 0 ? _ref4 : null,
2954
2976
  item_variant2: (_ref5 = item === null || item === void 0 ? void 0 : (_item_skuName1 = item.skuName) === null || _item_skuName1 === void 0 ? void 0 : (_item_skuName_split_1 = _item_skuName1.split(" - ")[1]) === null || _item_skuName_split_1 === void 0 ? void 0 : _item_skuName_split_1.trim()) !== null && _ref5 !== void 0 ? _ref5 : null,
@@ -2992,27 +3014,23 @@ var AzzasTracker = function() {
2992
3014
  if (context === null || context === void 0 ? void 0 : context.value) return context.value;
2993
3015
  if (!(context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.items)) return null;
2994
3016
  return getOrderFormItems(context.orderForm).map(function(item) {
2995
- return (item === null || item === void 0 ? void 0 : item.price) / 100 * item.quantity;
3017
+ return (item === null || item === void 0 ? void 0 : item.sellingPrice) / 100 * item.quantity;
2996
3018
  }).filter(function(price) {
2997
3019
  return price !== void 0;
2998
3020
  }).reduce(function(sum, price) {
2999
3021
  return sum + price;
3000
3022
  }, 0);
3001
3023
  },
3002
- payment_type: getPaymentType,
3024
+ payment_type: getPaymentType2,
3003
3025
  total_discount: function(context) {
3004
- var _context_orderForm, _context_orderForm1;
3026
+ var _context_orderForm, _context_orderForm1, _totalizers_find;
3005
3027
  if (context === null || context === void 0 ? void 0 : context.total_discount) return context.total_discount;
3006
3028
  if (!(context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.items)) return null;
3007
- var totalsList = ((_context_orderForm1 = context.orderForm) === null || _context_orderForm1 === void 0 ? void 0 : _context_orderForm1.totalizers) || [];
3008
- var totalDiscount = getOrderFormItems(context.orderForm).reduce(function(acc, item) {
3009
- var unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
3010
- return acc + unitDiscount * item.quantity;
3011
- }, 0);
3012
- var discounts = totalsList.find(function(t) {
3029
+ var totalizers = context === null || context === void 0 ? void 0 : (_context_orderForm1 = context.orderForm) === null || _context_orderForm1 === void 0 ? void 0 : _context_orderForm1.totalizers;
3030
+ var productDiscount = ((_totalizers_find = totalizers.find(function(t) {
3013
3031
  return t.id === "Discounts";
3014
- });
3015
- return Math.abs(((discounts === null || discounts === void 0 ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
3032
+ })) === null || _totalizers_find === void 0 ? void 0 : _totalizers_find.value) || 0;
3033
+ return Math.abs(productDiscount) / 100 || null;
3016
3034
  },
3017
3035
  subtotal: function(context) {
3018
3036
  var _context_orderForm, _context_orderForm1;
@@ -3024,19 +3042,6 @@ var AzzasTracker = function() {
3024
3042
  }, 0) / 100 || 0;
3025
3043
  return subtotal;
3026
3044
  },
3027
- coupon_message: function(context) {
3028
- var _context_orderForm;
3029
- if (context.couponMessage) return context.couponMessage;
3030
- var messages = ((_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.messages) || [];
3031
- if (messages.length === 0) return null;
3032
- var couponMessages = messages.filter(function(msg) {
3033
- return msg.text.toLowerCase().includes("cupom");
3034
- });
3035
- if (couponMessages.length === 0) return null;
3036
- return couponMessages.map(function(msg) {
3037
- return msg.text;
3038
- }).join(" | ");
3039
- },
3040
3045
  zipcode: function(context) {
3041
3046
  var _context_meta_zipcode;
3042
3047
  return (_context_meta_zipcode = context.meta.zipcode) !== null && _context_meta_zipcode !== void 0 ? _context_meta_zipcode : null;
@@ -3130,6 +3135,19 @@ var AzzasTracker = function() {
3130
3135
  var _context_orderForm_orderGroup, _context_orderForm;
3131
3136
  return ((_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : (_context_orderForm_orderGroup = _context_orderForm.orderGroup) === null || _context_orderForm_orderGroup === void 0 ? void 0 : _context_orderForm_orderGroup.toString()) || null;
3132
3137
  },
3138
+ coupon_message: function(context) {
3139
+ var _context_orderForm;
3140
+ if (context.couponMessage) return context.couponMessage;
3141
+ var messages = ((_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.messages) || [];
3142
+ if (messages.length === 0) return "C\xF3digo de desconto aplicado com sucesso";
3143
+ var couponMessages = messages.filter(function(msg) {
3144
+ return msg.text.toLowerCase().includes("cupom");
3145
+ });
3146
+ if (couponMessages.length === 0) return "C\xF3digo de desconto aplicado com sucesso";
3147
+ return couponMessages.map(function(msg) {
3148
+ return msg.text;
3149
+ }).join(" | ");
3150
+ },
3133
3151
  coupon: function(context) {
3134
3152
  var _context_orderForm_marketingData, _context_orderForm;
3135
3153
  return context.appliedCoupon || (context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : (_context_orderForm_marketingData = _context_orderForm.marketingData) === null || _context_orderForm_marketingData === void 0 ? void 0 : _context_orderForm_marketingData.coupon) || null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azzas/azzas-tracker-web",
3
- "version": "2.0.0-preview.16",
3
+ "version": "2.0.0-preview.18",
4
4
  "type": "module",
5
5
  "main": "./dist/mod.cjs",
6
6
  "module": "./dist/mod.js",