UNPKG

2.37 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var page_type_1 = require("../../commons/types/page-type");
5var vtex_runner_1 = require("../../event/runners/vtex-runner");
6var confirmation_1 = require("../../event/types/page/confirmation");
7/**
8 * Specific runner used by Martins
9 *
10 * @class MartinsRunner
11 * @implements {Runner}
12 */
13var MartinsRunner = /** @class */ (function (_super) {
14 tslib_1.__extends(MartinsRunner, _super);
15 function MartinsRunner() {
16 return _super !== null && _super.apply(this, arguments) || this;
17 }
18 /**
19 * Get current page info based on DataLayer.
20 *
21 * @protected
22 * @param {any} item Current item.
23 * @return {PageInfo} Current page info.
24 * @memberof MartinsRunner
25 */
26 MartinsRunner.prototype.getPageInfo = function (item) {
27 if (item && item.event) {
28 if (item.event.toUpperCase() === "PURCHASE") {
29 return {
30 item: item,
31 pageType: page_type_1.PageType.Confirmation,
32 };
33 }
34 else if (item.event.toUpperCase() === "CART") {
35 return {
36 item: item,
37 pageType: page_type_1.PageType.Cart,
38 };
39 }
40 }
41 return undefined;
42 };
43 /**
44 * Send order event, based on a order item.
45 *
46 * @protected
47 * @param {*} orderItem Order item from the DataLayer.
48 * @memberof VTEXRunner
49 */
50 MartinsRunner.prototype.sendOrderEvent = function (orderItem) {
51 var orderId = orderItem.transactionId;
52 var products = [];
53 if (orderItem.transactionProducts) {
54 for (var _i = 0, _a = orderItem.transactionProducts; _i < _a.length; _i++) {
55 var transactionProduct = _a[_i];
56 products.push({
57 product: transactionProduct.sku,
58 quantity: transactionProduct.quantity,
59 price: transactionProduct.price,
60 });
61 }
62 }
63 var event = new confirmation_1.PageConfirmationEvent(orderId).withProducts(products);
64 event.push();
65 };
66 return MartinsRunner;
67}(vtex_runner_1.VTEXRunner));
68exports.MartinsRunner = MartinsRunner;
69//# sourceMappingURL=martins-runner.js.map
\No newline at end of file