@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.
package/dist/mod.js CHANGED
@@ -1785,6 +1785,10 @@ var pickupAdapter = {
1785
1785
  };
1786
1786
 
1787
1787
  // src/params/adapters/orderForm/utils.ts
1788
+ var getOrderFormItems = (orderForm) => {
1789
+ const idSelected = orderForm == null ? void 0 : orderForm.selected;
1790
+ return idSelected ? orderForm.items.filter((item) => item.id === idSelected) : orderForm.items;
1791
+ };
1788
1792
  var getItemCategory6 = (item) => {
1789
1793
  var _a;
1790
1794
  const categories = item == null ? void 0 : item.productCategories;
@@ -1809,9 +1813,20 @@ function getItemShippingTier2(orderForm, item) {
1809
1813
  const selectedSla = (_c = info == null ? void 0 : info.slas) == null ? void 0 : _c.find((sla) => sla.id === info.selectedSla);
1810
1814
  return ((_d = selectedSla == null ? void 0 : selectedSla.pickupStoreInfo) == null ? void 0 : _d.friendlyName) ? `retirada em loja: ${selectedSla.pickupStoreInfo.friendlyName}` : (selectedSla == null ? void 0 : selectedSla.name) ? `Receba em casa: ${selectedSla.name}` : null;
1811
1815
  }
1812
- var getOrderFormItems = (orderForm) => {
1813
- const idSelected = orderForm == null ? void 0 : orderForm.selected;
1814
- return idSelected ? orderForm.items.filter((item) => item.id === idSelected) : orderForm.items;
1816
+ var getPaymentType2 = (context) => {
1817
+ var _a, _b, _c;
1818
+ if (context.payment_type) return context.payment_type;
1819
+ if (!context.orderForm) return null;
1820
+ const payments = ((_a = context.orderForm.paymentData) == null ? void 0 : _a.payments) || [];
1821
+ const systems = ((_b = context.orderForm.paymentData) == null ? void 0 : _b.paymentSystems) || [];
1822
+ if (!payments.length || !systems.length) return null;
1823
+ const selectedPayment = payments.find((p) => p == null ? void 0 : p.paymentSystem) || payments[0];
1824
+ const id = String((selectedPayment == null ? void 0 : selectedPayment.paymentSystem) || "").trim();
1825
+ if (!id) return null;
1826
+ const system = systems.find((s) => String(s.id) === id);
1827
+ const name = ((_c = system == null ? void 0 : system.name) == null ? void 0 : _c.toLowerCase()) || "";
1828
+ const match = paymentTypeMap.find(([key]) => name.includes(key));
1829
+ return match ? match[1] : null;
1815
1830
  };
1816
1831
 
1817
1832
  // src/params/adapters/orderForm/index.ts
@@ -1827,7 +1842,7 @@ var orderFormAdapter = {
1827
1842
  index: (_c = (_b = context == null ? void 0 : context.orderForm) == null ? void 0 : _b.index) != null ? _c : index + 1,
1828
1843
  item_brand: (_e = (_d = item.additionalInfo) == null ? void 0 : _d.brandName) != null ? _e : null,
1829
1844
  item_name: (_f = item == null ? void 0 : item.name.replace(item == null ? void 0 : item.skuName, "").trim()) != null ? _f : null,
1830
- price: (item == null ? void 0 : item.price) / 100,
1845
+ price: (item == null ? void 0 : item.sellingPrice) / 100,
1831
1846
  discount: ((item == null ? void 0 : item.listPrice) - (item == null ? void 0 : item.sellingPrice)) / 100,
1832
1847
  item_variant: (_j = (_i = (_h = (_g = item == null ? void 0 : item.skuName) == null ? void 0 : _g.split(" - ")[0]) == null ? void 0 : _h.split("_").pop()) == null ? void 0 : _i.trim()) != null ? _j : null,
1833
1848
  item_variant2: (_m = (_l = (_k = item == null ? void 0 : item.skuName) == null ? void 0 : _k.split(" - ")[1]) == null ? void 0 : _l.trim()) != null ? _m : null,
@@ -1864,20 +1879,16 @@ var orderFormAdapter = {
1864
1879
  var _a;
1865
1880
  if (context == null ? void 0 : context.value) return context.value;
1866
1881
  if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1867
- return getOrderFormItems(context.orderForm).map((item) => (item == null ? void 0 : item.price) / 100 * item.quantity).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
1882
+ return getOrderFormItems(context.orderForm).map((item) => (item == null ? void 0 : item.sellingPrice) / 100 * item.quantity).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
1868
1883
  },
1869
- payment_type: getPaymentType,
1884
+ payment_type: getPaymentType2,
1870
1885
  total_discount: (context) => {
1871
- var _a, _b;
1886
+ var _a, _b, _c;
1872
1887
  if (context == null ? void 0 : context.total_discount) return context.total_discount;
1873
1888
  if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1874
- const totalsList = ((_b = context.orderForm) == null ? void 0 : _b.totalizers) || [];
1875
- const totalDiscount = getOrderFormItems(context.orderForm).reduce((acc, item) => {
1876
- const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
1877
- return acc + unitDiscount * item.quantity;
1878
- }, 0);
1879
- const discounts = totalsList.find((t) => t.id === "Discounts");
1880
- return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
1889
+ const totalizers = (_b = context == null ? void 0 : context.orderForm) == null ? void 0 : _b.totalizers;
1890
+ const productDiscount = ((_c = totalizers.find((t) => t.id === "Discounts")) == null ? void 0 : _c.value) || 0;
1891
+ return Math.abs(productDiscount) / 100 || null;
1881
1892
  },
1882
1893
  subtotal: (context) => {
1883
1894
  var _a, _b;
@@ -1885,17 +1896,6 @@ var orderFormAdapter = {
1885
1896
  const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
1886
1897
  return subtotal;
1887
1898
  },
1888
- coupon_message: (context) => {
1889
- var _a;
1890
- if (context.couponMessage) return context.couponMessage;
1891
- const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
1892
- if (messages.length === 0) return null;
1893
- const couponMessages = messages.filter(
1894
- (msg) => msg.text.toLowerCase().includes("cupom")
1895
- );
1896
- if (couponMessages.length === 0) return null;
1897
- return couponMessages.map((msg) => msg.text).join(" | ");
1898
- },
1899
1899
  zipcode: (context) => {
1900
1900
  var _a;
1901
1901
  return (_a = context.meta.zipcode) != null ? _a : null;
@@ -1978,6 +1978,15 @@ var orderFormAdapter = {
1978
1978
  var _a, _b;
1979
1979
  return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
1980
1980
  },
1981
+ coupon_message: (context) => {
1982
+ var _a;
1983
+ if (context.couponMessage) return context.couponMessage;
1984
+ const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
1985
+ if (messages.length === 0) return "C\xF3digo de desconto aplicado com sucesso";
1986
+ const couponMessages = messages.filter((msg) => msg.text.toLowerCase().includes("cupom"));
1987
+ if (couponMessages.length === 0) return "C\xF3digo de desconto aplicado com sucesso";
1988
+ return couponMessages.map((msg) => msg.text).join(" | ");
1989
+ },
1981
1990
  coupon: (context) => {
1982
1991
  var _a, _b;
1983
1992
  return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;