@azzas/azzas-tracker-web 2.0.0-preview.4 → 2.0.0-preview.6
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.cjs +272 -234
- package/dist/mod.cjs.map +1 -1
- package/dist/mod.d.cts +6 -2
- package/dist/mod.d.ts +6 -2
- package/dist/mod.global.js +271 -234
- package/dist/mod.global.js.map +1 -1
- package/dist/mod.js +271 -234
- package/dist/mod.js.map +1 -1
- package/dist/mod.vtex.global.js +315 -263
- package/package.json +1 -1
package/dist/mod.vtex.global.js
CHANGED
|
@@ -1308,6 +1308,38 @@ var AzzasTracker = function() {
|
|
|
1308
1308
|
});
|
|
1309
1309
|
})();
|
|
1310
1310
|
};
|
|
1311
|
+
var getBrandCode2 = function getBrandCode2(brand) {
|
|
1312
|
+
if (!brand) return null;
|
|
1313
|
+
var standardized = brand.toLowerCase().trim();
|
|
1314
|
+
return BRAND_CODES2[standardized] || null;
|
|
1315
|
+
};
|
|
1316
|
+
var normalizeBrand2 = function normalizeBrand2(input) {
|
|
1317
|
+
var brandStrings = [];
|
|
1318
|
+
if (Array.isArray(input) && input.every(function(item) {
|
|
1319
|
+
return typeof item === "string";
|
|
1320
|
+
})) {
|
|
1321
|
+
brandStrings = input;
|
|
1322
|
+
} else if (Array.isArray(input)) {
|
|
1323
|
+
brandStrings = input.map(function(item) {
|
|
1324
|
+
var _item_additionalInfo;
|
|
1325
|
+
return ((_item_additionalInfo = item.additionalInfo) === null || _item_additionalInfo === void 0 ? void 0 : _item_additionalInfo.brandName) || item.brand;
|
|
1326
|
+
});
|
|
1327
|
+
} else if ((typeof input === "undefined" ? "undefined" : _type_of(input)) === "object" && input !== null && "brand" in input) {
|
|
1328
|
+
var _input_additionalInfo;
|
|
1329
|
+
brandStrings = [
|
|
1330
|
+
((_input_additionalInfo = input.additionalInfo) === null || _input_additionalInfo === void 0 ? void 0 : _input_additionalInfo.brandName) || input.brand
|
|
1331
|
+
];
|
|
1332
|
+
} else if (typeof input === "string") {
|
|
1333
|
+
return getBrandCode2(input);
|
|
1334
|
+
} else {
|
|
1335
|
+
return null;
|
|
1336
|
+
}
|
|
1337
|
+
var brandCodes = brandStrings.map(getBrandCode2).filter(function(code) {
|
|
1338
|
+
return code !== null;
|
|
1339
|
+
});
|
|
1340
|
+
var uniqueSortedCodes = _to_consumable_array(new Set(brandCodes)).sort();
|
|
1341
|
+
return uniqueSortedCodes.length > 0 ? uniqueSortedCodes.join("_") : null;
|
|
1342
|
+
};
|
|
1311
1343
|
var getItemShippingTier2 = function getItemShippingTier2(orderForm, item) {
|
|
1312
1344
|
var _orderForm_shippingData_logisticsInfo, _orderForm_shippingData, _info_slas, _selectedSla_pickupStoreInfo;
|
|
1313
1345
|
var info = orderForm === null || orderForm === void 0 ? void 0 : (_orderForm_shippingData = orderForm.shippingData) === null || _orderForm_shippingData === void 0 ? void 0 : (_orderForm_shippingData_logisticsInfo = _orderForm_shippingData.logisticsInfo) === null || _orderForm_shippingData_logisticsInfo === void 0 ? void 0 : _orderForm_shippingData_logisticsInfo.find(function(li) {
|
|
@@ -1318,7 +1350,7 @@ var AzzasTracker = function() {
|
|
|
1318
1350
|
});
|
|
1319
1351
|
return (selectedSla === null || selectedSla === void 0 ? void 0 : (_selectedSla_pickupStoreInfo = selectedSla.pickupStoreInfo) === null || _selectedSla_pickupStoreInfo === void 0 ? void 0 : _selectedSla_pickupStoreInfo.friendlyName) ? "retirada em loja: ".concat(selectedSla.pickupStoreInfo.friendlyName) : (selectedSla === null || selectedSla === void 0 ? void 0 : selectedSla.name) ? "Receba em casa: ".concat(selectedSla.name) : null;
|
|
1320
1352
|
};
|
|
1321
|
-
var getParameters = function getParameters(context, eventName) {
|
|
1353
|
+
var getParameters = function getParameters(context, eventName, config2) {
|
|
1322
1354
|
return _async_to_generator(function() {
|
|
1323
1355
|
var _adapters_currentAdapter, eventConfig, currentAdapter, getters, entries;
|
|
1324
1356
|
return _ts_generator(this, function(_state) {
|
|
@@ -1354,7 +1386,7 @@ var AzzasTracker = function() {
|
|
|
1354
1386
|
];
|
|
1355
1387
|
return [
|
|
1356
1388
|
4,
|
|
1357
|
-
getter(context,
|
|
1389
|
+
getter(context, config2)
|
|
1358
1390
|
];
|
|
1359
1391
|
case 1:
|
|
1360
1392
|
return [
|
|
@@ -1378,8 +1410,10 @@ var AzzasTracker = function() {
|
|
|
1378
1410
|
});
|
|
1379
1411
|
})();
|
|
1380
1412
|
};
|
|
1381
|
-
var
|
|
1382
|
-
|
|
1413
|
+
var initTracker = function initTracker(c) {
|
|
1414
|
+
config = c;
|
|
1415
|
+
};
|
|
1416
|
+
var trackWebEvent = function trackWebEvent(event, context) {
|
|
1383
1417
|
return _async_to_generator(function() {
|
|
1384
1418
|
var parameters, err;
|
|
1385
1419
|
return _ts_generator(this, function(_state) {
|
|
@@ -1393,7 +1427,7 @@ var AzzasTracker = function() {
|
|
|
1393
1427
|
]);
|
|
1394
1428
|
return [
|
|
1395
1429
|
4,
|
|
1396
|
-
getParameters(context, event)
|
|
1430
|
+
getParameters(context, event, config)
|
|
1397
1431
|
];
|
|
1398
1432
|
case 1:
|
|
1399
1433
|
parameters = _state.sent();
|
|
@@ -1483,6 +1517,9 @@ var AzzasTracker = function() {
|
|
|
1483
1517
|
default: function() {
|
|
1484
1518
|
return src_default;
|
|
1485
1519
|
},
|
|
1520
|
+
initTracker: function() {
|
|
1521
|
+
return initTracker;
|
|
1522
|
+
},
|
|
1486
1523
|
trackWebEvent: function() {
|
|
1487
1524
|
return trackWebEvent;
|
|
1488
1525
|
}
|
|
@@ -2402,9 +2439,9 @@ var AzzasTracker = function() {
|
|
|
2402
2439
|
// src/params/adapters/meta/index.ts
|
|
2403
2440
|
var metaAdapters = {
|
|
2404
2441
|
user_info: getUserInfo,
|
|
2405
|
-
brand:
|
|
2406
|
-
|
|
2407
|
-
},
|
|
2442
|
+
// brand: (context: MetaBrandContext) => {
|
|
2443
|
+
// return context.meta.brand || null;
|
|
2444
|
+
// },
|
|
2408
2445
|
content_type: function(context) {
|
|
2409
2446
|
return context.meta.content_type || null;
|
|
2410
2447
|
},
|
|
@@ -2414,8 +2451,8 @@ var AzzasTracker = function() {
|
|
|
2414
2451
|
pre_filled: function(context) {
|
|
2415
2452
|
return !!context.preFilled;
|
|
2416
2453
|
},
|
|
2417
|
-
currency: function(
|
|
2418
|
-
if (
|
|
2454
|
+
currency: function(_, config2) {
|
|
2455
|
+
if (config2 === null || config2 === void 0 ? void 0 : config2.currency) return config2.currency;
|
|
2419
2456
|
return "BRL";
|
|
2420
2457
|
},
|
|
2421
2458
|
slot_per_line: function(context) {
|
|
@@ -2486,6 +2523,11 @@ var AzzasTracker = function() {
|
|
|
2486
2523
|
var deepest = (_validHierarchy_ = validHierarchy[validHierarchy.length - 1]) !== null && _validHierarchy_ !== void 0 ? _validHierarchy_ : "";
|
|
2487
2524
|
return capitalize(deepest);
|
|
2488
2525
|
};
|
|
2526
|
+
var BRAND_CODES2 = {
|
|
2527
|
+
farm: "farmrio",
|
|
2528
|
+
"farm etc": "farmetc",
|
|
2529
|
+
"farm rio": "farmrio"
|
|
2530
|
+
};
|
|
2489
2531
|
// src/params/adapters/deco/index.ts
|
|
2490
2532
|
var IN_STOCK_SCHEMA = "https://schema.org/InStock";
|
|
2491
2533
|
var LIST_PRICE_SCHEMA = "https://schema.org/ListPrice";
|
|
@@ -2529,13 +2571,16 @@ var AzzasTracker = function() {
|
|
|
2529
2571
|
}
|
|
2530
2572
|
return null;
|
|
2531
2573
|
},
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2574
|
+
brand: function(context, config2) {
|
|
2575
|
+
if (config2 === null || config2 === void 0 ? void 0 : config2.brand) return config2.brand;
|
|
2576
|
+
if (context === null || context === void 0 ? void 0 : context.products) {
|
|
2577
|
+
return normalizeBrand2(context.products.map(function(p) {
|
|
2578
|
+
var _p_brand;
|
|
2579
|
+
return p === null || p === void 0 ? void 0 : (_p_brand = p.brand) === null || _p_brand === void 0 ? void 0 : _p_brand.name;
|
|
2580
|
+
}));
|
|
2581
|
+
}
|
|
2582
|
+
return null;
|
|
2583
|
+
},
|
|
2539
2584
|
line_items: function(context) {
|
|
2540
2585
|
if (context === null || context === void 0 ? void 0 : context.line_items) return context.line_items;
|
|
2541
2586
|
if (context === null || context === void 0 ? void 0 : context.products) {
|
|
@@ -2585,235 +2630,8 @@ var AzzasTracker = function() {
|
|
|
2585
2630
|
return null;
|
|
2586
2631
|
}
|
|
2587
2632
|
});
|
|
2588
|
-
// src/params/adapters/orderForm/utils.ts
|
|
2589
|
-
var getItemCategory5 = function(item) {
|
|
2590
|
-
var _text_match;
|
|
2591
|
-
var categories = item === null || item === void 0 ? void 0 : item.productCategories;
|
|
2592
|
-
if (!categories) return "Cole\xE7\xE3o";
|
|
2593
|
-
var text = Object.values(categories).join(" ");
|
|
2594
|
-
var match = (_text_match = text.match(/outlet|bazar|sale/i)) === null || _text_match === void 0 ? void 0 : _text_match[0].toLowerCase();
|
|
2595
|
-
return match !== null && match !== void 0 ? match : "Cole\xE7\xE3o";
|
|
2596
|
-
};
|
|
2597
|
-
var getItemCategory23 = function(item) {
|
|
2598
|
-
var _ref, _validHierarchy_;
|
|
2599
|
-
var AVOID_CATEGORIES = /outlet|bazar|sale/i;
|
|
2600
|
-
var categories = Object.values((_ref = item === null || item === void 0 ? void 0 : item.productCategories) !== null && _ref !== void 0 ? _ref : {});
|
|
2601
|
-
var validHierarchy = categories.map(function(c) {
|
|
2602
|
-
return c.trim();
|
|
2603
|
-
}).filter(function(c) {
|
|
2604
|
-
return c && !AVOID_CATEGORIES.test(c);
|
|
2605
|
-
});
|
|
2606
|
-
var deepest = (_validHierarchy_ = validHierarchy[validHierarchy.length - 1]) !== null && _validHierarchy_ !== void 0 ? _validHierarchy_ : "";
|
|
2607
|
-
return capitalize(deepest);
|
|
2608
|
-
};
|
|
2609
|
-
var getOrderFormItems = function(orderForm) {
|
|
2610
|
-
var idSelected = orderForm === null || orderForm === void 0 ? void 0 : orderForm.selected;
|
|
2611
|
-
return idSelected ? orderForm.items.filter(function(item) {
|
|
2612
|
-
return item.id === idSelected;
|
|
2613
|
-
}) : orderForm.items;
|
|
2614
|
-
};
|
|
2615
|
-
// src/params/adapters/orderForm/index.ts
|
|
2616
|
-
var orderFormAdapter = _object_spread_props(_object_spread({}, metaAdapters), {
|
|
2617
|
-
items: function(context) {
|
|
2618
|
-
if (context === null || context === void 0 ? void 0 : context.items) return context.items;
|
|
2619
|
-
if ((context === null || context === void 0 ? void 0 : context.orderForm) && (context === null || context === void 0 ? void 0 : context.orderForm.items)) {
|
|
2620
|
-
return getOrderFormItems(context.orderForm).map(function(item, index) {
|
|
2621
|
-
var _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _getItemCategory5, _getItemCategory23, _ref7, _ref8, _item_detailUrl, _resizeVtexImage2, _ref9, _ref10;
|
|
2622
|
-
var _context_orderForm, _item_additionalInfo, _item_skuName_split__split_pop, _item_skuName_split_, _item_skuName, _item_skuName_split_1, _item_skuName1, _context_orderForm1;
|
|
2623
|
-
return {
|
|
2624
|
-
quantity: (_ref = item === null || item === void 0 ? void 0 : item.quantity) !== null && _ref !== void 0 ? _ref : 1,
|
|
2625
|
-
index: (_ref1 = (_ref2 = context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.index) !== null && _ref2 !== void 0 ? _ref2 : index) !== null && _ref1 !== void 0 ? _ref1 : null,
|
|
2626
|
-
item_brand: (_ref3 = (_item_additionalInfo = item.additionalInfo) === null || _item_additionalInfo === void 0 ? void 0 : _item_additionalInfo.brandName) !== null && _ref3 !== void 0 ? _ref3 : null,
|
|
2627
|
-
item_name: (_ref4 = item === null || item === void 0 ? void 0 : item.name.replace(item === null || item === void 0 ? void 0 : item.skuName, "").trim()) !== null && _ref4 !== void 0 ? _ref4 : null,
|
|
2628
|
-
price: (item === null || item === void 0 ? void 0 : item.price) / 100,
|
|
2629
|
-
discount: ((item === null || item === void 0 ? void 0 : item.listPrice) - (item === null || item === void 0 ? void 0 : item.sellingPrice)) / 100,
|
|
2630
|
-
item_variant: (_ref5 = 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 && _ref5 !== void 0 ? _ref5 : null,
|
|
2631
|
-
item_variant2: (_ref6 = 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 && _ref6 !== void 0 ? _ref6 : null,
|
|
2632
|
-
item_shipping_tier: getItemShippingTier2(context.orderForm, item),
|
|
2633
|
-
item_ref: (item === null || item === void 0 ? void 0 : item.productRefId) || (item === null || item === void 0 ? void 0 : item.refId.replace(/_\d+$/, "")) || null,
|
|
2634
|
-
item_category: (_getItemCategory5 = getItemCategory5(item)) !== null && _getItemCategory5 !== void 0 ? _getItemCategory5 : null,
|
|
2635
|
-
item_category2: (_getItemCategory23 = getItemCategory23(item)) !== null && _getItemCategory23 !== void 0 ? _getItemCategory23 : null,
|
|
2636
|
-
item_id: (_ref7 = item === null || item === void 0 ? void 0 : item.productId) !== null && _ref7 !== void 0 ? _ref7 : null,
|
|
2637
|
-
item_sku: (_ref8 = item === null || item === void 0 ? void 0 : item.id) !== null && _ref8 !== void 0 ? _ref8 : null,
|
|
2638
|
-
item_url: (_item_detailUrl = item.detailUrl) !== null && _item_detailUrl !== void 0 ? _item_detailUrl : null,
|
|
2639
|
-
image_url: (_resizeVtexImage2 = resizeVtexImage2(item.imageUrl)) !== null && _resizeVtexImage2 !== void 0 ? _resizeVtexImage2 : null,
|
|
2640
|
-
seller_id: (_ref9 = item === null || item === void 0 ? void 0 : item.seller) !== null && _ref9 !== void 0 ? _ref9 : null,
|
|
2641
|
-
item_list_name: (_ref10 = context === null || context === void 0 ? void 0 : (_context_orderForm1 = context.orderForm) === null || _context_orderForm1 === void 0 ? void 0 : _context_orderForm1.item_list_name) !== null && _ref10 !== void 0 ? _ref10 : null
|
|
2642
|
-
};
|
|
2643
|
-
});
|
|
2644
|
-
}
|
|
2645
|
-
return null;
|
|
2646
|
-
},
|
|
2647
|
-
// brand: (context: any) => {
|
|
2648
|
-
// if (context?.brand) return context.brand
|
|
2649
|
-
// if (context?.products) {
|
|
2650
|
-
// return context.products[0].brand?.name // tem que ajustar FARM por conta de FARM_ETC
|
|
2651
|
-
// }
|
|
2652
|
-
// return null
|
|
2653
|
-
// },
|
|
2654
|
-
line_items: function(context) {
|
|
2655
|
-
var _context_orderForm;
|
|
2656
|
-
if (context === null || context === void 0 ? void 0 : context.line_items) return context.line_items;
|
|
2657
|
-
if (!(context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.items)) return null;
|
|
2658
|
-
return getOrderFormItems(context.orderForm).map(function(item) {
|
|
2659
|
-
return item === null || item === void 0 ? void 0 : item.productId;
|
|
2660
|
-
}).filter(function(id) {
|
|
2661
|
-
return Boolean(id);
|
|
2662
|
-
});
|
|
2663
|
-
},
|
|
2664
|
-
value: function(context) {
|
|
2665
|
-
var _context_orderForm;
|
|
2666
|
-
if (context === null || context === void 0 ? void 0 : context.value) return context.value;
|
|
2667
|
-
if (!(context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.items)) return null;
|
|
2668
|
-
return getOrderFormItems(context.orderForm).map(function(item) {
|
|
2669
|
-
return (item === null || item === void 0 ? void 0 : item.price) / 100 * item.quantity;
|
|
2670
|
-
}).filter(function(price) {
|
|
2671
|
-
return price !== void 0;
|
|
2672
|
-
}).reduce(function(sum, price) {
|
|
2673
|
-
return sum + price;
|
|
2674
|
-
}, 0);
|
|
2675
|
-
},
|
|
2676
|
-
payment_type: getPaymentType,
|
|
2677
|
-
total_discount: function(context) {
|
|
2678
|
-
var _context_orderForm, _context_orderForm1;
|
|
2679
|
-
if (context === null || context === void 0 ? void 0 : context.total_discount) return context.total_discount;
|
|
2680
|
-
if (!(context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.items)) return null;
|
|
2681
|
-
var totalsList = ((_context_orderForm1 = context.orderForm) === null || _context_orderForm1 === void 0 ? void 0 : _context_orderForm1.totalizers) || [];
|
|
2682
|
-
var totalDiscount = getOrderFormItems(context.orderForm).reduce(function(acc, item) {
|
|
2683
|
-
var unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
|
|
2684
|
-
return acc + unitDiscount * item.quantity;
|
|
2685
|
-
}, 0);
|
|
2686
|
-
var discounts = totalsList.find(function(t) {
|
|
2687
|
-
return t.id === "Discounts";
|
|
2688
|
-
});
|
|
2689
|
-
return Math.abs(((discounts === null || discounts === void 0 ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
|
|
2690
|
-
},
|
|
2691
|
-
subtotal: function(context) {
|
|
2692
|
-
var _context_orderForm, _context_orderForm1;
|
|
2693
|
-
var totalsList = ((_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.totalizers) || ((_context_orderForm1 = context.orderForm) === null || _context_orderForm1 === void 0 ? void 0 : _context_orderForm1.totals) || [];
|
|
2694
|
-
var subtotal = totalsList.filter(function(t) {
|
|
2695
|
-
return t.id === "Items";
|
|
2696
|
-
}).reduce(function(acc, t) {
|
|
2697
|
-
return acc + (t.value || 0);
|
|
2698
|
-
}, 0) / 100 || 0;
|
|
2699
|
-
return subtotal;
|
|
2700
|
-
},
|
|
2701
|
-
coupon_message: function(context) {
|
|
2702
|
-
var _context_orderForm;
|
|
2703
|
-
if (context.couponMessage) return context.couponMessage;
|
|
2704
|
-
var messages = ((_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.messages) || [];
|
|
2705
|
-
if (messages.length === 0) return null;
|
|
2706
|
-
var couponMessages = messages.filter(function(msg) {
|
|
2707
|
-
return msg.text.toLowerCase().includes("cupom");
|
|
2708
|
-
});
|
|
2709
|
-
if (couponMessages.length === 0) return null;
|
|
2710
|
-
return couponMessages.map(function(msg) {
|
|
2711
|
-
return msg.text;
|
|
2712
|
-
}).join(" | ");
|
|
2713
|
-
},
|
|
2714
|
-
zipcode: function(context) {
|
|
2715
|
-
var _context_zipcode;
|
|
2716
|
-
return (_context_zipcode = context.zipcode) !== null && _context_zipcode !== void 0 ? _context_zipcode : null;
|
|
2717
|
-
},
|
|
2718
|
-
flag_pickup: function(context) {
|
|
2719
|
-
var _orderForm_shippingData;
|
|
2720
|
-
var orderForm = context.orderForm;
|
|
2721
|
-
if (!orderForm) return null;
|
|
2722
|
-
var logisticsInfo = ((_orderForm_shippingData = orderForm.shippingData) === null || _orderForm_shippingData === void 0 ? void 0 : _orderForm_shippingData.logisticsInfo) || [];
|
|
2723
|
-
var hasPickup = logisticsInfo.some(function(info) {
|
|
2724
|
-
var _info_slas;
|
|
2725
|
-
return (_info_slas = info.slas) === null || _info_slas === void 0 ? void 0 : _info_slas.some(function(sla) {
|
|
2726
|
-
return sla.deliveryChannel === "pickup-in-point";
|
|
2727
|
-
});
|
|
2728
|
-
});
|
|
2729
|
-
return hasPickup;
|
|
2730
|
-
},
|
|
2731
|
-
shippings: function(context) {
|
|
2732
|
-
if (!context.orderForm) return null;
|
|
2733
|
-
var _context_orderForm = context.orderForm, items = _context_orderForm.items, shippingData = _context_orderForm.shippingData;
|
|
2734
|
-
var acc = {};
|
|
2735
|
-
shippingData.logisticsInfo.forEach(function(param) {
|
|
2736
|
-
var itemIndex = param.itemIndex, slas = param.slas;
|
|
2737
|
-
var item = items[itemIndex];
|
|
2738
|
-
if (!item) return;
|
|
2739
|
-
slas.forEach(function(sla) {
|
|
2740
|
-
if (!acc[sla.name]) acc[sla.name] = {
|
|
2741
|
-
shipping_tier: sla.name,
|
|
2742
|
-
delivery_time: parseInt(sla.shippingEstimate),
|
|
2743
|
-
shipping: parseFloat((sla.price / 100).toFixed(1)),
|
|
2744
|
-
line_items: []
|
|
2745
|
-
};
|
|
2746
|
-
acc[sla.name].line_items.push(item.id);
|
|
2747
|
-
});
|
|
2748
|
-
});
|
|
2749
|
-
return Object.values(acc).map(function(s) {
|
|
2750
|
-
return _object_spread_props(_object_spread({}, s), {
|
|
2751
|
-
line_items: s.line_items.join(",")
|
|
2752
|
-
});
|
|
2753
|
-
});
|
|
2754
|
-
},
|
|
2755
|
-
shipping: function(context) {
|
|
2756
|
-
var _ref;
|
|
2757
|
-
var _context_orderForm_shippingData, _context_orderForm;
|
|
2758
|
-
var logistics = (_ref = context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : (_context_orderForm_shippingData = _context_orderForm.shippingData) === null || _context_orderForm_shippingData === void 0 ? void 0 : _context_orderForm_shippingData.logisticsInfo) !== null && _ref !== void 0 ? _ref : [];
|
|
2759
|
-
return logistics.reduce(function(total, item) {
|
|
2760
|
-
var _ref;
|
|
2761
|
-
var _item_slas;
|
|
2762
|
-
var selected = (_item_slas = item.slas) === null || _item_slas === void 0 ? void 0 : _item_slas.find(function(sla) {
|
|
2763
|
-
return sla.id === item.selectedSla;
|
|
2764
|
-
});
|
|
2765
|
-
return total + ((_ref = selected === null || selected === void 0 ? void 0 : selected.price) !== null && _ref !== void 0 ? _ref : 0);
|
|
2766
|
-
}, 0);
|
|
2767
|
-
},
|
|
2768
|
-
shipping_tier: function(context) {
|
|
2769
|
-
var _ref;
|
|
2770
|
-
var _context_orderForm_shippingData, _context_orderForm;
|
|
2771
|
-
var logistics = (_ref = context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : (_context_orderForm_shippingData = _context_orderForm.shippingData) === null || _context_orderForm_shippingData === void 0 ? void 0 : _context_orderForm_shippingData.logisticsInfo) !== null && _ref !== void 0 ? _ref : [];
|
|
2772
|
-
var selectedSlas = logistics.map(function(item) {
|
|
2773
|
-
var _item_slas;
|
|
2774
|
-
if (!item.selectedSla) return null;
|
|
2775
|
-
return ((_item_slas = item.slas) === null || _item_slas === void 0 ? void 0 : _item_slas.find(function(sla) {
|
|
2776
|
-
return sla.id === item.selectedSla;
|
|
2777
|
-
})) || null;
|
|
2778
|
-
}).filter(Boolean);
|
|
2779
|
-
if (selectedSlas.length === 0) return null;
|
|
2780
|
-
var uniqueTiers = Array.from(new Map(selectedSlas.map(function(sla) {
|
|
2781
|
-
var _sla_pickupStoreInfo;
|
|
2782
|
-
var key = sla.deliveryChannel === "pickup-in-point" ? "pickup:".concat(((_sla_pickupStoreInfo = sla.pickupStoreInfo) === null || _sla_pickupStoreInfo === void 0 ? void 0 : _sla_pickupStoreInfo.friendlyName) || sla.name || "") : "delivery:".concat(sla.name || "");
|
|
2783
|
-
return [
|
|
2784
|
-
key,
|
|
2785
|
-
sla
|
|
2786
|
-
];
|
|
2787
|
-
})).values());
|
|
2788
|
-
var sortedTiers = uniqueTiers.sort(function(a, b) {
|
|
2789
|
-
var _a_pickupStoreInfo, _b_pickupStoreInfo;
|
|
2790
|
-
var aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
|
|
2791
|
-
var bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
|
|
2792
|
-
if (aOrder !== bOrder) return aOrder - bOrder;
|
|
2793
|
-
var aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a_pickupStoreInfo = a.pickupStoreInfo) === null || _a_pickupStoreInfo === void 0 ? void 0 : _a_pickupStoreInfo.friendlyName) || a.name || "" : a.name || "";
|
|
2794
|
-
var bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b_pickupStoreInfo = b.pickupStoreInfo) === null || _b_pickupStoreInfo === void 0 ? void 0 : _b_pickupStoreInfo.friendlyName) || b.name || "" : b.name || "";
|
|
2795
|
-
return aLabel.localeCompare(bLabel, "pt-BR");
|
|
2796
|
-
});
|
|
2797
|
-
var shippingTier = sortedTiers.map(function(sla) {
|
|
2798
|
-
var _sla_pickupStoreInfo;
|
|
2799
|
-
return sla.deliveryChannel === "pickup-in-point" ? "retirada em loja".concat(((_sla_pickupStoreInfo = sla.pickupStoreInfo) === null || _sla_pickupStoreInfo === void 0 ? void 0 : _sla_pickupStoreInfo.friendlyName) ? ": ".concat(sla.pickupStoreInfo.friendlyName) : "") : sla.deliveryChannel === "delivery" ? "receba em casa".concat(sla.name ? ": ".concat(sla.name) : "") : null;
|
|
2800
|
-
}).filter(Boolean).join(", ");
|
|
2801
|
-
return shippingTier || null;
|
|
2802
|
-
},
|
|
2803
|
-
transaction_id: function(context) {
|
|
2804
|
-
var _context_orderForm_orderGroup, _context_orderForm;
|
|
2805
|
-
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;
|
|
2806
|
-
},
|
|
2807
|
-
coupon: function(context) {
|
|
2808
|
-
var _context_orderForm_marketingData, _context_orderForm;
|
|
2809
|
-
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;
|
|
2810
|
-
},
|
|
2811
|
-
seller_cod_name: function(context) {
|
|
2812
|
-
return context.appliedSellerCodName || (context === null || context === void 0 ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
|
|
2813
|
-
}
|
|
2814
|
-
});
|
|
2815
2633
|
// src/params/adapters/headless/utils.ts
|
|
2816
|
-
var
|
|
2634
|
+
var getItemCategory5 = function(item) {
|
|
2817
2635
|
var keywords = [
|
|
2818
2636
|
"outlet",
|
|
2819
2637
|
"bazar",
|
|
@@ -2830,7 +2648,7 @@ var AzzasTracker = function() {
|
|
|
2830
2648
|
}
|
|
2831
2649
|
return "Cole\xE7\xE3o";
|
|
2832
2650
|
};
|
|
2833
|
-
var
|
|
2651
|
+
var getItemCategory23 = function(item) {
|
|
2834
2652
|
var _ref, _reverse_find;
|
|
2835
2653
|
var _item_categories;
|
|
2836
2654
|
var avoidList = /outlet|bazar|sale/i;
|
|
@@ -2847,7 +2665,7 @@ var AzzasTracker = function() {
|
|
|
2847
2665
|
if (context === null || context === void 0 ? void 0 : context.items) return context.items;
|
|
2848
2666
|
if (context === null || context === void 0 ? void 0 : context.products) {
|
|
2849
2667
|
return context.products.map(function(item) {
|
|
2850
|
-
var _ref, _item_brand, _item_productName, _ref1, _ref2, _item_productReference,
|
|
2668
|
+
var _ref, _item_brand, _item_productName, _ref1, _ref2, _item_productReference, _getItemCategory23, _ref3, _ref4, _item_link, _resizeVtexImage2, _ref5, _item_item_list_name;
|
|
2851
2669
|
var _item_items__sellers, _item_items__sellers1, _item_items__name, _item_items_, _item_items__name1, _item_items_1, _item_items, _item_items__images, _item_items1, _item_items__sellers2, _item_items_2, _item_items2;
|
|
2852
2670
|
var listPrice = item === null || item === void 0 ? void 0 : (_item_items__sellers = item.items[0].sellers) === null || _item_items__sellers === void 0 ? void 0 : _item_items__sellers[0].commertialOffer.ListPrice;
|
|
2853
2671
|
var price = item === null || item === void 0 ? void 0 : (_item_items__sellers1 = item.items[0].sellers) === null || _item_items__sellers1 === void 0 ? void 0 : _item_items__sellers1[0].commertialOffer.Price;
|
|
@@ -2863,8 +2681,8 @@ var AzzasTracker = function() {
|
|
|
2863
2681
|
item_variant2: (_ref2 = (_item_items_1 = item.items[0]) === null || _item_items_1 === void 0 ? void 0 : (_item_items__name1 = _item_items_1.name) === null || _item_items__name1 === void 0 ? void 0 : _item_items__name1.split(" - ")[1]) !== null && _ref2 !== void 0 ? _ref2 : null,
|
|
2864
2682
|
item_ref: (_item_productReference = item.productReference) !== null && _item_productReference !== void 0 ? _item_productReference : null,
|
|
2865
2683
|
// sem ref no retorno do IS na multi-lib produtos PDC
|
|
2866
|
-
item_category:
|
|
2867
|
-
item_category2: (
|
|
2684
|
+
item_category: getItemCategory5(item),
|
|
2685
|
+
item_category2: (_getItemCategory23 = getItemCategory23(item)) !== null && _getItemCategory23 !== void 0 ? _getItemCategory23 : null,
|
|
2868
2686
|
item_id: (_ref3 = item === null || item === void 0 ? void 0 : item.productId) !== null && _ref3 !== void 0 ? _ref3 : null,
|
|
2869
2687
|
item_sku: (_ref4 = (_item_items = item.items) === null || _item_items === void 0 ? void 0 : _item_items[0].itemId) !== null && _ref4 !== void 0 ? _ref4 : null,
|
|
2870
2688
|
item_url: (_item_link = item.link) !== null && _item_link !== void 0 ? _item_link : null,
|
|
@@ -2902,8 +2720,8 @@ var AzzasTracker = function() {
|
|
|
2902
2720
|
}
|
|
2903
2721
|
return null;
|
|
2904
2722
|
},
|
|
2905
|
-
brand: function(context) {
|
|
2906
|
-
if (
|
|
2723
|
+
brand: function(context, config2) {
|
|
2724
|
+
if (config2 === null || config2 === void 0 ? void 0 : config2.brand) return config2.brand;
|
|
2907
2725
|
if (context === null || context === void 0 ? void 0 : context.products) {
|
|
2908
2726
|
return context.products.map(function(p) {
|
|
2909
2727
|
return p.brand;
|
|
@@ -2918,7 +2736,7 @@ var AzzasTracker = function() {
|
|
|
2918
2736
|
if (context === null || context === void 0 ? void 0 : context.items) return context.items;
|
|
2919
2737
|
if (context === null || context === void 0 ? void 0 : context.products) {
|
|
2920
2738
|
return context.products.map(function(item) {
|
|
2921
|
-
var _ref, _item_brand_name, _item_name, _ref1, _ref2, _item_additionalProperty,
|
|
2739
|
+
var _ref, _item_brand_name, _item_name, _ref1, _ref2, _item_additionalProperty, _getItemCategory23, _item_isVariantOf_productGroupID, _item_sku, _resizeVtexImage2, _ref3, _item_item_list_name;
|
|
2922
2740
|
var _item_isVariantOf_hasVariant, _item_isVariantOf, _find, _item_image, _item_offers_offers_find_seller, _item_offers_offers_find, _item_offers_offers, _item_offers;
|
|
2923
2741
|
var listPrice = item.offers.highPrice;
|
|
2924
2742
|
var price = item.offers.lowPrice;
|
|
@@ -2936,8 +2754,8 @@ var AzzasTracker = function() {
|
|
|
2936
2754
|
})) === null || _find === void 0 ? void 0 : _find.value) !== null && _ref2 !== void 0 ? _ref2 : null,
|
|
2937
2755
|
item_ref: null,
|
|
2938
2756
|
// sem ref no retorno do IS na multi-lib produtos PDC
|
|
2939
|
-
item_category:
|
|
2940
|
-
item_category2: (
|
|
2757
|
+
item_category: getItemCategory5(item),
|
|
2758
|
+
item_category2: (_getItemCategory23 = getItemCategory23(item)) !== null && _getItemCategory23 !== void 0 ? _getItemCategory23 : null,
|
|
2941
2759
|
item_id: (_item_isVariantOf_productGroupID = item.isVariantOf.productGroupID) !== null && _item_isVariantOf_productGroupID !== void 0 ? _item_isVariantOf_productGroupID : null,
|
|
2942
2760
|
item_sku: (_item_sku = item.sku) !== null && _item_sku !== void 0 ? _item_sku : null,
|
|
2943
2761
|
item_url: null,
|
|
@@ -2976,8 +2794,8 @@ var AzzasTracker = function() {
|
|
|
2976
2794
|
}
|
|
2977
2795
|
return null;
|
|
2978
2796
|
},
|
|
2979
|
-
brand: function(context) {
|
|
2980
|
-
if (
|
|
2797
|
+
brand: function(context, config2) {
|
|
2798
|
+
if (config2 === null || config2 === void 0 ? void 0 : config2.brand) return config2.brand;
|
|
2981
2799
|
if (context === null || context === void 0 ? void 0 : context.products) {
|
|
2982
2800
|
return context.products.map(function(p) {
|
|
2983
2801
|
return p.brand.name;
|
|
@@ -2987,14 +2805,14 @@ var AzzasTracker = function() {
|
|
|
2987
2805
|
}
|
|
2988
2806
|
};
|
|
2989
2807
|
// src/params/adapters/headless/index.ts
|
|
2990
|
-
var headlessAdapter = _object_spread_props(_object_spread({}, metaAdapters
|
|
2991
|
-
//
|
|
2992
|
-
brand: function(context) {
|
|
2808
|
+
var headlessAdapter = _object_spread_props(_object_spread({}, metaAdapters), {
|
|
2809
|
+
// global adapters
|
|
2810
|
+
brand: function(context, config2) {
|
|
2993
2811
|
if (context.zone === "PDP") {
|
|
2994
|
-
return HeadlessPdpZone.brand(context);
|
|
2812
|
+
return HeadlessPdpZone.brand(context, config2);
|
|
2995
2813
|
}
|
|
2996
2814
|
if (context.zone === "PDC") {
|
|
2997
|
-
return HeadlessPdcZone.brand(context);
|
|
2815
|
+
return HeadlessPdcZone.brand(context, config2);
|
|
2998
2816
|
}
|
|
2999
2817
|
return null;
|
|
3000
2818
|
},
|
|
@@ -3064,10 +2882,10 @@ var AzzasTracker = function() {
|
|
|
3064
2882
|
shippings: function(context) {
|
|
3065
2883
|
if (context.shippings) {
|
|
3066
2884
|
return context.shippings.map(function(s) {
|
|
3067
|
-
var _s_line_items
|
|
2885
|
+
var _s_line_items;
|
|
3068
2886
|
return {
|
|
3069
2887
|
line_items: (_s_line_items = s.line_items) !== null && _s_line_items !== void 0 ? _s_line_items : "",
|
|
3070
|
-
shipping:
|
|
2888
|
+
shipping: s.price / 100,
|
|
3071
2889
|
shipping_tier: getShippingTier(s),
|
|
3072
2890
|
delivery_time: getDeliveryTime(s)
|
|
3073
2891
|
};
|
|
@@ -3080,6 +2898,235 @@ var AzzasTracker = function() {
|
|
|
3080
2898
|
return (_context_zipcode = context.zipcode) !== null && _context_zipcode !== void 0 ? _context_zipcode : null;
|
|
3081
2899
|
}
|
|
3082
2900
|
});
|
|
2901
|
+
// src/params/adapters/orderForm/utils.ts
|
|
2902
|
+
var getItemCategory6 = function(item) {
|
|
2903
|
+
var _text_match;
|
|
2904
|
+
var categories = item === null || item === void 0 ? void 0 : item.productCategories;
|
|
2905
|
+
if (!categories) return "Cole\xE7\xE3o";
|
|
2906
|
+
var text = Object.values(categories).join(" ");
|
|
2907
|
+
var match = (_text_match = text.match(/outlet|bazar|sale/i)) === null || _text_match === void 0 ? void 0 : _text_match[0].toLowerCase();
|
|
2908
|
+
return match !== null && match !== void 0 ? match : "Cole\xE7\xE3o";
|
|
2909
|
+
};
|
|
2910
|
+
var getItemCategory24 = function(item) {
|
|
2911
|
+
var _ref, _validHierarchy_;
|
|
2912
|
+
var AVOID_CATEGORIES = /outlet|bazar|sale/i;
|
|
2913
|
+
var categories = Object.values((_ref = item === null || item === void 0 ? void 0 : item.productCategories) !== null && _ref !== void 0 ? _ref : {});
|
|
2914
|
+
var validHierarchy = categories.map(function(c) {
|
|
2915
|
+
return c.trim();
|
|
2916
|
+
}).filter(function(c) {
|
|
2917
|
+
return c && !AVOID_CATEGORIES.test(c);
|
|
2918
|
+
});
|
|
2919
|
+
var deepest = (_validHierarchy_ = validHierarchy[validHierarchy.length - 1]) !== null && _validHierarchy_ !== void 0 ? _validHierarchy_ : "";
|
|
2920
|
+
return capitalize(deepest);
|
|
2921
|
+
};
|
|
2922
|
+
var getOrderFormItems = function(orderForm) {
|
|
2923
|
+
var idSelected = orderForm === null || orderForm === void 0 ? void 0 : orderForm.selected;
|
|
2924
|
+
return idSelected ? orderForm.items.filter(function(item) {
|
|
2925
|
+
return item.id === idSelected;
|
|
2926
|
+
}) : orderForm.items;
|
|
2927
|
+
};
|
|
2928
|
+
// src/params/adapters/orderForm/index.ts
|
|
2929
|
+
var orderFormAdapter = _object_spread_props(_object_spread({}, metaAdapters), {
|
|
2930
|
+
items: function(context) {
|
|
2931
|
+
if (context === null || context === void 0 ? void 0 : context.items) return context.items;
|
|
2932
|
+
if ((context === null || context === void 0 ? void 0 : context.orderForm) && (context === null || context === void 0 ? void 0 : context.orderForm.items)) {
|
|
2933
|
+
return getOrderFormItems(context.orderForm).map(function(item, index) {
|
|
2934
|
+
var _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _getItemCategory6, _getItemCategory24, _ref7, _ref8, _item_detailUrl, _resizeVtexImage2, _ref9, _ref10;
|
|
2935
|
+
var _context_orderForm, _item_additionalInfo, _item_skuName_split__split_pop, _item_skuName_split_, _item_skuName, _item_skuName_split_1, _item_skuName1, _context_orderForm1;
|
|
2936
|
+
return {
|
|
2937
|
+
quantity: (_ref = item === null || item === void 0 ? void 0 : item.quantity) !== null && _ref !== void 0 ? _ref : 1,
|
|
2938
|
+
index: (_ref1 = (_ref2 = context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.index) !== null && _ref2 !== void 0 ? _ref2 : index) !== null && _ref1 !== void 0 ? _ref1 : null,
|
|
2939
|
+
item_brand: (_ref3 = (_item_additionalInfo = item.additionalInfo) === null || _item_additionalInfo === void 0 ? void 0 : _item_additionalInfo.brandName) !== null && _ref3 !== void 0 ? _ref3 : null,
|
|
2940
|
+
item_name: (_ref4 = item === null || item === void 0 ? void 0 : item.name.replace(item === null || item === void 0 ? void 0 : item.skuName, "").trim()) !== null && _ref4 !== void 0 ? _ref4 : null,
|
|
2941
|
+
price: (item === null || item === void 0 ? void 0 : item.price) / 100,
|
|
2942
|
+
discount: ((item === null || item === void 0 ? void 0 : item.listPrice) - (item === null || item === void 0 ? void 0 : item.sellingPrice)) / 100,
|
|
2943
|
+
item_variant: (_ref5 = 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 && _ref5 !== void 0 ? _ref5 : null,
|
|
2944
|
+
item_variant2: (_ref6 = 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 && _ref6 !== void 0 ? _ref6 : null,
|
|
2945
|
+
item_shipping_tier: getItemShippingTier2(context.orderForm, item),
|
|
2946
|
+
item_ref: (item === null || item === void 0 ? void 0 : item.productRefId) || (item === null || item === void 0 ? void 0 : item.refId.replace(/_\d+$/, "")) || null,
|
|
2947
|
+
item_category: (_getItemCategory6 = getItemCategory6(item)) !== null && _getItemCategory6 !== void 0 ? _getItemCategory6 : null,
|
|
2948
|
+
item_category2: (_getItemCategory24 = getItemCategory24(item)) !== null && _getItemCategory24 !== void 0 ? _getItemCategory24 : null,
|
|
2949
|
+
item_id: (_ref7 = item === null || item === void 0 ? void 0 : item.productId) !== null && _ref7 !== void 0 ? _ref7 : null,
|
|
2950
|
+
item_sku: (_ref8 = item === null || item === void 0 ? void 0 : item.id) !== null && _ref8 !== void 0 ? _ref8 : null,
|
|
2951
|
+
item_url: (_item_detailUrl = item.detailUrl) !== null && _item_detailUrl !== void 0 ? _item_detailUrl : null,
|
|
2952
|
+
image_url: (_resizeVtexImage2 = resizeVtexImage2(item.imageUrl)) !== null && _resizeVtexImage2 !== void 0 ? _resizeVtexImage2 : null,
|
|
2953
|
+
seller_id: (_ref9 = item === null || item === void 0 ? void 0 : item.seller) !== null && _ref9 !== void 0 ? _ref9 : null,
|
|
2954
|
+
item_list_name: (_ref10 = context === null || context === void 0 ? void 0 : (_context_orderForm1 = context.orderForm) === null || _context_orderForm1 === void 0 ? void 0 : _context_orderForm1.item_list_name) !== null && _ref10 !== void 0 ? _ref10 : null
|
|
2955
|
+
};
|
|
2956
|
+
});
|
|
2957
|
+
}
|
|
2958
|
+
return null;
|
|
2959
|
+
},
|
|
2960
|
+
brand: function(context, config2) {
|
|
2961
|
+
var _context_orderForm;
|
|
2962
|
+
if (config2 === null || config2 === void 0 ? void 0 : config2.brand) return config2.brand;
|
|
2963
|
+
if (!(context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.items)) return null;
|
|
2964
|
+
var brands = getOrderFormItems(context.orderForm).map(function(item) {
|
|
2965
|
+
return item.additionalInfo.brandName;
|
|
2966
|
+
});
|
|
2967
|
+
return normalizeBrand2(brands);
|
|
2968
|
+
},
|
|
2969
|
+
line_items: function(context) {
|
|
2970
|
+
var _context_orderForm;
|
|
2971
|
+
if (context === null || context === void 0 ? void 0 : context.line_items) return context.line_items;
|
|
2972
|
+
if (!(context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.items)) return null;
|
|
2973
|
+
return getOrderFormItems(context.orderForm).map(function(item) {
|
|
2974
|
+
return item === null || item === void 0 ? void 0 : item.productId;
|
|
2975
|
+
}).filter(function(id) {
|
|
2976
|
+
return Boolean(id);
|
|
2977
|
+
});
|
|
2978
|
+
},
|
|
2979
|
+
value: function(context) {
|
|
2980
|
+
var _context_orderForm;
|
|
2981
|
+
if (context === null || context === void 0 ? void 0 : context.value) return context.value;
|
|
2982
|
+
if (!(context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.items)) return null;
|
|
2983
|
+
return getOrderFormItems(context.orderForm).map(function(item) {
|
|
2984
|
+
return (item === null || item === void 0 ? void 0 : item.price) / 100 * item.quantity;
|
|
2985
|
+
}).filter(function(price) {
|
|
2986
|
+
return price !== void 0;
|
|
2987
|
+
}).reduce(function(sum, price) {
|
|
2988
|
+
return sum + price;
|
|
2989
|
+
}, 0);
|
|
2990
|
+
},
|
|
2991
|
+
payment_type: getPaymentType,
|
|
2992
|
+
total_discount: function(context) {
|
|
2993
|
+
var _context_orderForm, _context_orderForm1;
|
|
2994
|
+
if (context === null || context === void 0 ? void 0 : context.total_discount) return context.total_discount;
|
|
2995
|
+
if (!(context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.items)) return null;
|
|
2996
|
+
var totalsList = ((_context_orderForm1 = context.orderForm) === null || _context_orderForm1 === void 0 ? void 0 : _context_orderForm1.totalizers) || [];
|
|
2997
|
+
var totalDiscount = getOrderFormItems(context.orderForm).reduce(function(acc, item) {
|
|
2998
|
+
var unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
|
|
2999
|
+
return acc + unitDiscount * item.quantity;
|
|
3000
|
+
}, 0);
|
|
3001
|
+
var discounts = totalsList.find(function(t) {
|
|
3002
|
+
return t.id === "Discounts";
|
|
3003
|
+
});
|
|
3004
|
+
return Math.abs(((discounts === null || discounts === void 0 ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
|
|
3005
|
+
},
|
|
3006
|
+
subtotal: function(context) {
|
|
3007
|
+
var _context_orderForm, _context_orderForm1;
|
|
3008
|
+
var totalsList = ((_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.totalizers) || ((_context_orderForm1 = context.orderForm) === null || _context_orderForm1 === void 0 ? void 0 : _context_orderForm1.totals) || [];
|
|
3009
|
+
var subtotal = totalsList.filter(function(t) {
|
|
3010
|
+
return t.id === "Items";
|
|
3011
|
+
}).reduce(function(acc, t) {
|
|
3012
|
+
return acc + (t.value || 0);
|
|
3013
|
+
}, 0) / 100 || 0;
|
|
3014
|
+
return subtotal;
|
|
3015
|
+
},
|
|
3016
|
+
coupon_message: function(context) {
|
|
3017
|
+
var _context_orderForm;
|
|
3018
|
+
if (context.couponMessage) return context.couponMessage;
|
|
3019
|
+
var messages = ((_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.messages) || [];
|
|
3020
|
+
if (messages.length === 0) return null;
|
|
3021
|
+
var couponMessages = messages.filter(function(msg) {
|
|
3022
|
+
return msg.text.toLowerCase().includes("cupom");
|
|
3023
|
+
});
|
|
3024
|
+
if (couponMessages.length === 0) return null;
|
|
3025
|
+
return couponMessages.map(function(msg) {
|
|
3026
|
+
return msg.text;
|
|
3027
|
+
}).join(" | ");
|
|
3028
|
+
},
|
|
3029
|
+
zipcode: function(context) {
|
|
3030
|
+
var _context_zipcode;
|
|
3031
|
+
return (_context_zipcode = context.zipcode) !== null && _context_zipcode !== void 0 ? _context_zipcode : null;
|
|
3032
|
+
},
|
|
3033
|
+
flag_pickup: function(context) {
|
|
3034
|
+
var _orderForm_shippingData;
|
|
3035
|
+
var orderForm = context.orderForm;
|
|
3036
|
+
if (!orderForm) return null;
|
|
3037
|
+
var logisticsInfo = ((_orderForm_shippingData = orderForm.shippingData) === null || _orderForm_shippingData === void 0 ? void 0 : _orderForm_shippingData.logisticsInfo) || [];
|
|
3038
|
+
var hasPickup = logisticsInfo.some(function(info) {
|
|
3039
|
+
var _info_slas;
|
|
3040
|
+
return (_info_slas = info.slas) === null || _info_slas === void 0 ? void 0 : _info_slas.some(function(sla) {
|
|
3041
|
+
return sla.deliveryChannel === "pickup-in-point";
|
|
3042
|
+
});
|
|
3043
|
+
});
|
|
3044
|
+
return hasPickup;
|
|
3045
|
+
},
|
|
3046
|
+
shippings: function(context) {
|
|
3047
|
+
if (!context.orderForm) return null;
|
|
3048
|
+
var _context_orderForm = context.orderForm, items = _context_orderForm.items, shippingData = _context_orderForm.shippingData;
|
|
3049
|
+
var acc = {};
|
|
3050
|
+
shippingData.logisticsInfo.forEach(function(param) {
|
|
3051
|
+
var itemIndex = param.itemIndex, slas = param.slas;
|
|
3052
|
+
var item = items[itemIndex];
|
|
3053
|
+
if (!item) return;
|
|
3054
|
+
slas.forEach(function(sla) {
|
|
3055
|
+
if (!acc[sla.name]) acc[sla.name] = {
|
|
3056
|
+
shipping_tier: sla.name,
|
|
3057
|
+
delivery_time: parseInt(sla.shippingEstimate),
|
|
3058
|
+
shipping: parseFloat((sla.price / 100).toFixed(1)),
|
|
3059
|
+
line_items: []
|
|
3060
|
+
};
|
|
3061
|
+
acc[sla.name].line_items.push(item.id);
|
|
3062
|
+
});
|
|
3063
|
+
});
|
|
3064
|
+
return Object.values(acc).map(function(s) {
|
|
3065
|
+
return _object_spread_props(_object_spread({}, s), {
|
|
3066
|
+
line_items: s.line_items.join(",")
|
|
3067
|
+
});
|
|
3068
|
+
});
|
|
3069
|
+
},
|
|
3070
|
+
shipping: function(context) {
|
|
3071
|
+
var _ref;
|
|
3072
|
+
var _context_orderForm_shippingData, _context_orderForm;
|
|
3073
|
+
var logistics = (_ref = context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : (_context_orderForm_shippingData = _context_orderForm.shippingData) === null || _context_orderForm_shippingData === void 0 ? void 0 : _context_orderForm_shippingData.logisticsInfo) !== null && _ref !== void 0 ? _ref : [];
|
|
3074
|
+
return logistics.reduce(function(total, item) {
|
|
3075
|
+
var _ref;
|
|
3076
|
+
var _item_slas;
|
|
3077
|
+
var selected = (_item_slas = item.slas) === null || _item_slas === void 0 ? void 0 : _item_slas.find(function(sla) {
|
|
3078
|
+
return sla.id === item.selectedSla;
|
|
3079
|
+
});
|
|
3080
|
+
return total + ((_ref = selected === null || selected === void 0 ? void 0 : selected.price) !== null && _ref !== void 0 ? _ref : 0);
|
|
3081
|
+
}, 0);
|
|
3082
|
+
},
|
|
3083
|
+
shipping_tier: function(context) {
|
|
3084
|
+
var _ref;
|
|
3085
|
+
var _context_orderForm_shippingData, _context_orderForm;
|
|
3086
|
+
var logistics = (_ref = context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : (_context_orderForm_shippingData = _context_orderForm.shippingData) === null || _context_orderForm_shippingData === void 0 ? void 0 : _context_orderForm_shippingData.logisticsInfo) !== null && _ref !== void 0 ? _ref : [];
|
|
3087
|
+
var selectedSlas = logistics.map(function(item) {
|
|
3088
|
+
var _item_slas;
|
|
3089
|
+
if (!item.selectedSla) return null;
|
|
3090
|
+
return ((_item_slas = item.slas) === null || _item_slas === void 0 ? void 0 : _item_slas.find(function(sla) {
|
|
3091
|
+
return sla.id === item.selectedSla;
|
|
3092
|
+
})) || null;
|
|
3093
|
+
}).filter(Boolean);
|
|
3094
|
+
if (selectedSlas.length === 0) return null;
|
|
3095
|
+
var uniqueTiers = Array.from(new Map(selectedSlas.map(function(sla) {
|
|
3096
|
+
var _sla_pickupStoreInfo;
|
|
3097
|
+
var key = sla.deliveryChannel === "pickup-in-point" ? "pickup:".concat(((_sla_pickupStoreInfo = sla.pickupStoreInfo) === null || _sla_pickupStoreInfo === void 0 ? void 0 : _sla_pickupStoreInfo.friendlyName) || sla.name || "") : "delivery:".concat(sla.name || "");
|
|
3098
|
+
return [
|
|
3099
|
+
key,
|
|
3100
|
+
sla
|
|
3101
|
+
];
|
|
3102
|
+
})).values());
|
|
3103
|
+
var sortedTiers = uniqueTiers.sort(function(a, b) {
|
|
3104
|
+
var _a_pickupStoreInfo, _b_pickupStoreInfo;
|
|
3105
|
+
var aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
|
|
3106
|
+
var bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
|
|
3107
|
+
if (aOrder !== bOrder) return aOrder - bOrder;
|
|
3108
|
+
var aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a_pickupStoreInfo = a.pickupStoreInfo) === null || _a_pickupStoreInfo === void 0 ? void 0 : _a_pickupStoreInfo.friendlyName) || a.name || "" : a.name || "";
|
|
3109
|
+
var bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b_pickupStoreInfo = b.pickupStoreInfo) === null || _b_pickupStoreInfo === void 0 ? void 0 : _b_pickupStoreInfo.friendlyName) || b.name || "" : b.name || "";
|
|
3110
|
+
return aLabel.localeCompare(bLabel, "pt-BR");
|
|
3111
|
+
});
|
|
3112
|
+
var shippingTier = sortedTiers.map(function(sla) {
|
|
3113
|
+
var _sla_pickupStoreInfo;
|
|
3114
|
+
return sla.deliveryChannel === "pickup-in-point" ? "retirada em loja".concat(((_sla_pickupStoreInfo = sla.pickupStoreInfo) === null || _sla_pickupStoreInfo === void 0 ? void 0 : _sla_pickupStoreInfo.friendlyName) ? ": ".concat(sla.pickupStoreInfo.friendlyName) : "") : sla.deliveryChannel === "delivery" ? "receba em casa".concat(sla.name ? ": ".concat(sla.name) : "") : null;
|
|
3115
|
+
}).filter(Boolean).join(", ");
|
|
3116
|
+
return shippingTier || null;
|
|
3117
|
+
},
|
|
3118
|
+
transaction_id: function(context) {
|
|
3119
|
+
var _context_orderForm_orderGroup, _context_orderForm;
|
|
3120
|
+
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;
|
|
3121
|
+
},
|
|
3122
|
+
coupon: function(context) {
|
|
3123
|
+
var _context_orderForm_marketingData, _context_orderForm;
|
|
3124
|
+
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;
|
|
3125
|
+
},
|
|
3126
|
+
seller_cod_name: function(context) {
|
|
3127
|
+
return context.appliedSellerCodName || (context === null || context === void 0 ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
|
|
3128
|
+
}
|
|
3129
|
+
});
|
|
3083
3130
|
// src/formatter.ts
|
|
3084
3131
|
var adapters = {
|
|
3085
3132
|
DECO: decoAdapter,
|
|
@@ -3087,6 +3134,11 @@ var AzzasTracker = function() {
|
|
|
3087
3134
|
PICKUP: pickupAdapter,
|
|
3088
3135
|
ORDERFORM: orderFormAdapter
|
|
3089
3136
|
};
|
|
3137
|
+
// src/index.ts
|
|
3138
|
+
var config = {
|
|
3139
|
+
brand: "",
|
|
3140
|
+
currency: "BRL"
|
|
3141
|
+
};
|
|
3090
3142
|
var src_default = {
|
|
3091
3143
|
trackWebEvent: trackWebEvent,
|
|
3092
3144
|
EVENTS: EVENTS
|