PageSourceSearch

https://www.iway.ch/wp-content/themes/iwaytwo/assets/js/gfo_checkout.js?ver=6

js iway.ch collected 2026-09-24 09:40:37 UTC 11,597 bytes, 249 lines download raw bytes

1/* ========== Storage > Cookie umschreiben ============================ */
2/*(function(){
3    // Dieser Code kann aber November 2024 entfernt werden
4    // Er dient nur darum offene Bestellungen für GFO-Webcomponent-3 vorzubereiten
5    // Früher wurde localStorage verwendet, neu Cookies
6    let order_reference = localStorage.getItem("order_reference");
7    if (null == order_reference || "" == order_reference){
8        //console.log("es gibt keine alte Bestellreferenz - nichts tun");
9        return;
10    }
11    let cookieArray = document.cookie.split(';');
12    for (var i=0; i<cookieArray.length; i++){
13        if (cookieArray[i].startsWith("gfo_order=")){
14            //console.log("es gibt bereits ein Cookie - nichts tun");
15            return;
16        }
17    }
18    // Setze Cookie und lösche localStorage-Wert
19    const d = new Date();
20    const exdays = 30;
21    d.setTime(d.getTime() + (exdays*24*60*60*1000));
22    let expires = "expires="+ d.toUTCString();
23    document.cookie = "gfo_order=" + order_reference + ";" + expires + ";path=/";
24    localStorage.removeItem("order_reference");
25    //console.log("localStorage in Cookie umgewandelt");
26})();
27*/
28
29/* ========== Anzahl beim Cart-Symbol aktualisieren ========== */
30function GfoOrderHasChangedCallback( new_order){
31    //console.log('order has changed');
32    // Zu hinterlegen:
33    // <gfo-form data-on_order_change="GfoOrderHasChangedCallback" ...> 
34    // <gfo-cart-dropdown data-on_order_change="GfoOrderHasChangedCallback" ...>
35    let number_of_items = 0;
36    if (new_order != null && new_order.hasOwnProperty('positions')){
37        new_order.positions.forEach(function(item){
38            if (item.product_id != 1000
39                && item.product_id != 11
40                && item.product_is_main == true // nur Hauptprodukte, IWEB-2935
41            ){
42                number_of_items+=item.qty;
43            }
44        })
45    }
46    localStorage.setItem("number_of_cart_items", number_of_items);
47    updateNumberOfCartItems();
48}
49function updateNumberOfCartItems(){
50    let number_of_cart_items = localStorage.getItem("number_of_cart_items");
51    let cookies = document.cookie;
52    if (typeof(number_of_cart_items) == 'string'
53        && number_of_cart_items != '0'
54        && typeof(cookies) == "string" 
55        && -1 == cookies.indexOf("gfo_order=")){
56        // Wenn das gfo_order cookie abgelaufen ist, der Wert in LocaleStorage aber immer noch >0
57        // reset auf 0
58        number_of_cart_items = '0';
59        localStorage.removeItem('number_of_cart_items');
60    }
61    let regex = /[0-9]+/;
62    if (!regex.test(number_of_cart_items)){
63        number_of_cart_items = '0';
64    }
65    let el = document.getElementById("cartCounter");
66    if (el){
67        el.innerHTML = number_of_cart_items;
68    }
69}
70window.addEventListener("storage", async function (evt) {
71    if (evt.key == "number_of_cart_items") {
72        updateNumberOfCartItems();
73    }
74})
75document.addEventListener("DOMContentLoaded", updateNumberOfCartItems);
76
77
78
79/* ========== Tracking-Funktion (callback) ==================== */
80/*
81 * @param order object
82 */
83function GfoNgTrack(order) {
84    step = order.step;
85    var ga4_items = [];
86    for (var i = 0; i < order.items.length; i++) {
87        var pos = order.items[i];
88        ga4_items.push({
89            item_id: pos.id,
90            item_name: pos.name,
91            currency: "CHF",
92            index: i+1,
93            item_brand: "iWay",
94            item_category: pos.product_name,
95            price: pos.price,
96            quantity: pos.quantity,
97        });
98    }
99    var coupon_code = '';
100    if (order.hasOwnProperty("coupon") && order.coupon != null){
101        coupon_code = order.coupon;
102
103    }
104    var revenue = 0;
105    if (order.hasOwnProperty("revenue") && order.revenue != null){
106        revenue = order.revenue;
107    }
108    let ecommerce_data = {
109        affiliation: order.affiliation == "" ? "iWay" : order.affiliation,
110        transaction_id: order.tracking_reference,
111        currency: "CHF",
112        value: revenue,
113        coupon: coupon_code,
114        items: ga4_items
115    }
116    if ('checkout' == order.action) {
117        let push_data = {
118            event: "add_to_cart", 
119            ecommerce: ecommerce_data
120        };
121        //console.log(push_data);
122        //GA4 push to datalayer
123        if (typeof dataLayer != 'undefined') { 
124            dataLayer.push(push_data);
125        }
126
127    }
128    
129    if ('create_link' == order.action || 'create_quote' == order.action) {
130        let push_data = {
131            event: order.action, 
132            ecommerce: ecommerce_data
133        };
134        //console.log(push_data);
135        //GA4 push to datalayer
136        if (typeof dataLayer != 'undefined') { 
137            dataLayer.push(push_data);
138        }
139    }
140    if ("purchase" == order.action) {
141        let push_data = {
142            event: 'purchase', 
143            ecommerce: ecommerce_data
144        };
145        //console.log(push_data);
146        //GA4 purchase
147        if (typeof dataLayer != 'undefined') {  
148            dataLayer.push(push_data);
149        }
150
151        // Facebook Tracking
152        // deaktiviert gemäss Cecilia 31.10.2025
153        // if (undefined != window.fbq) {
154        //     fbq('track', 'Purchase', {
155        //         currency: 'CHF',
156        //         value: revenue,
157        //     });
158        // }
159
160        // Adtraction
161        //$(document).ready(function(){
162        if ('undefined' != typeof(window.ADT)){
163            ADT = ADT || {};
164            ADT.Tag = ADT.Tag || {};
165            ADT.Tag.t = 3;
166            ADT.Tag.c = "CHF";
167            ADT.Tag.tp = 1630657768;
168            ADT.Tag.am = revenue;
169            ADT.Tag.ti = order.tracking_reference;
170            ADT.Tag.xd = md5(order.address_invoice.email);
171            ADT.Tag.cpn = coupon_code;
172
173            ADT.Tag.doEvent();
174
175        //});
176        }
177
178
179        // Connects Tracking
180        /* <![CDATA[ */
181        window._lea = window._lea || [];
182
183        window._lea.push({
184            id: 'DBLGFgXnEiRgKRwfhRKG',
185            module: 'OrderTracking',
186            event: 'Sale',
187            site: 'checkout',
188            oid: order.tracking_reference,
189            ovalue: revenue,
190            ocurrency: 'CHF',
191            ocategory: 'Sales',
192            oname: '',
193            ochannel: '',
194            voucher: ''
195        });
196        // End editable part
197
198        (function (d) { var s = d.createElement("script"); s.async = true; s.src = (d.location.protocol == "https:" ? "https:" : "http:") + "//tc.connects.ch/lila.js"; var a = d.getElementsByTagName("script")[0]; a.parentNode.insertBefore(s, a) })(document);
199
200        /* ]]> */
201    } 
202    
203}
204
205/* ===== md5 hashing for user's emails ===== */
206/* Used by Adtraction for cross device tracking */
207function md5(inputString) {
208    var hc = "0123456789abcdef";
209    function rh(n) { var j, s = ""; for (j = 0; j <= 3; j++) s += hc.charAt((n >> (j * 8 + 4)) & 0x0F) + hc.charAt((n >> (j * 8)) & 0x0F); return s; }
210    function ad(x, y) { var l = (x & 0xFFFF) + (y & 0xFFFF); var m = (x >> 16) + (y >> 16) + (l >> 16); return (m << 16) | (l & 0xFFFF); }
211    function rl(n, c) { return (n << c) | (n >>> (32 - c)); }
212    function cm(q, a, b, x, s, t) { return ad(rl(ad(ad(a, q), ad(x, t)), s), b); }
213    function ff(a, b, c, d, x, s, t) { return cm((b & c) | ((~b) & d), a, b, x, s, t); }
214    function gg(a, b, c, d, x, s, t) { return cm((b & d) | (c & (~d)), a, b, x, s, t); }
215    function hh(a, b, c, d, x, s, t) { return cm(b ^ c ^ d, a, b, x, s, t); }
216    function ii(a, b, c, d, x, s, t) { return cm(c ^ (b | (~d)), a, b, x, s, t); }
217    function sb(x) {
218        var i; var nblk = ((x.length + 8) >> 6) + 1; var blks = new Array(nblk * 16); for (i = 0; i < nblk * 16; i++) blks[i] = 0;
219        for (i = 0; i < x.length; i++) blks[i >> 2] |= x.charCodeAt(i) << ((i % 4) * 8);
220        blks[i >> 2] |= 0x80 << ((i % 4) * 8); blks[nblk * 16 - 2] = x.length * 8; return blks;
221    }
222    var i, x = sb(inputString), a = 1732584193, b = -271733879, c = -1732584194, d = 271733878, olda, oldb, oldc, oldd;
223    for (i = 0; i < x.length; i += 16) {
224        olda = a; oldb = b; oldc = c; oldd = d;
225        a = ff(a, b, c, d, x[i + 0], 7, -680876936); d = ff(d, a, b, c, x[i + 1], 12, -389564586); c = ff(c, d, a, b, x[i + 2], 17, 606105819);
226        b = ff(b, c, d, a, x[i + 3], 22, -1044525330); a = ff(a, b, c, d, x[i + 4], 7, -176418897); d = ff(d, a, b, c, x[i + 5], 12, 1200080426);
227        c = ff(c, d, a, b, x[i + 6], 17, -1473231341); b = ff(b, c, d, a, x[i + 7], 22, -45705983); a = ff(a, b, c, d, x[i + 8], 7, 1770035416);
228        d = ff(d, a, b, c, x[i + 9], 12, -1958414417); c = ff(c, d, a, b, x[i + 10], 17, -42063); b = ff(b, c, d, a, x[i + 11], 22, -1990404162);
229        a = ff(a, b, c, d, x[i + 12], 7, 1804603682); d = ff(d, a, b, c, x[i + 13], 12, -40341101); c = ff(c, d, a, b, x[i + 14], 17, -1502002290);
230        b = ff(b, c, d, a, x[i + 15], 22, 1236535329); a = gg(a, b, c, d, x[i + 1], 5, -165796510); d = gg(d, a, b, c, x[i + 6], 9, -1069501632);
231        c = gg(c, d, a, b, x[i + 11], 14, 643717713); b = gg(b, c, d, a, x[i + 0], 20, -373897302); a = gg(a, b, c, d, x[i + 5], 5, -701558691);
232        d = gg(d, a, b, c, x[i + 10], 9, 38016083); c = gg(c, d, a, b, x[i + 15], 14, -660478335); b = gg(b, c, d, a, x[i + 4], 20, -405537848);
233        a = gg(a, b, c, d, x[i + 9], 5, 568446438); d = gg(d, a, b, c, x[i + 14], 9, -1019803690); c = gg(c, d, a, b, x[i + 3], 14, -187363961);
234        b = gg(b, c, d, a, x[i + 8], 20, 1163531501); a = gg(a, b, c, d, x[i + 13], 5, -1444681467); d = gg(d, a, b, c, x[i + 2], 9, -51403784);
235        c = gg(c, d, a, b, x[i + 7], 14, 1735328473); b = gg(b, c, d, a, x[i + 12], 20, -1926607734); a = hh(a, b, c, d, x[i + 5], 4, -378558);
236        d = hh(d, a, b, c, x[i + 8], 11, -2022574463); c = hh(c, d, a, b, x[i + 11], 16, 1839030562); b = hh(b, c, d, a, x[i + 14], 23, -35309556);
237        a = hh(a, b, c, d, x[i + 1], 4, -1530992060); d = hh(d, a, b, c, x[i + 4], 11, 1272893353); c = hh(c, d, a, b, x[i + 7], 16, -155497632);
238        b = hh(b, c, d, a, x[i + 10], 23, -1094730640); a = hh(a, b, c, d, x[i + 13], 4, 681279174); d = hh(d, a, b, c, x[i + 0], 11, -358537222);
239        c = hh(c, d, a, b, x[i + 3], 16, -722521979); b = hh(b, c, d, a, x[i + 6], 23, 76029189); a = hh(a, b, c, d, x[i + 9], 4, -640364487);
240        d = hh(d, a, b, c, x[i + 12], 11, -421815835); c = hh(c, d, a, b, x[i + 15], 16, 530742520); b = hh(b, c, d, a, x[i + 2], 23, -995338651);
241        a = ii(a, b, c, d, x[i + 0], 6, -198630844); d = ii(d, a, b, c, x[i + 7], 10, 1126891415); c = ii(c, d, a, b, x[i + 14], 15, -1416354905);
242        b = ii(b, c, d, a, x[i + 5], 21, -57434055); a = ii(a, b, c, d, x[i + 12], 6, 1700485571); d = ii(d, a, b, c, x[i + 3], 10, -1894986606);
243        c = ii(c, d, a, b, x[i + 10], 15, -1051523); b = ii(b, c, d, a, x[i + 1], 21, -2054922799); a = ii(a, b, c, d, x[i + 8], 6, 1873313359);
244        d = ii(d, a, b, c, x[i + 15], 10, -30611744); c = ii(c, d, a, b, x[i + 6], 15, -1560198380); b = ii(b, c, d, a, x[i + 13], 21, 1309151649);
245        a = ii(a, b, c, d, x[i + 4], 6, -145523070); d = ii(d, a, b, c, x[i + 11], 10, -1120210379); c = ii(c, d, a, b, x[i + 2], 15, 718787259);
246        b = ii(b, c, d, a, x[i + 9], 21, -343485551); a = ad(a, olda); b = ad(b, oldb); c = ad(c, oldc); d = ad(d, oldd);
247    }
248    return rh(a) + rh(b) + rh(c) + rh(d);
249}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.