console.log('success'); var done = false function patchNewsletter(selektor) { var mtc_id = localStorage.getItem('mtc_id') var patchData = { 'saglasnost_promotivne_por' : 'da', 'tags' : 'newsletter' } var email = selektor.value patchData['email'] = email MauticJS.makePatchRequest(mtc_id, patchData, function(response, status, error) { console.log(status) if(status != 200) console.log(response) }) } function konvertujTekstUBroj(tekst) { let numberString = tekst // Replace periods with nothing and commas with periods let formattedString = numberString.replace(/\./g, '').replace(/,/, '.'); // Convert the string to a number let number = parseFloat(formattedString); return number } function clearAndUpdateAbandonedCartFromMiniCart() { var mtc_id = localStorage.getItem('mtc_id') var patchData = { 'broj_artikala_abandoned' : 0, 'abandoned_cart' : 'ne', "iznos_korpe_abandoned" : 0 } for(var x = 1; x <= 5; x++) { patchData["abandoned_cart_item_" + x + "_nam"] = ' ' patchData["abandoned_cart_item_" + x + "_pri"] = ' ' patchData["abandoned_cart_item_" + x + "_ima"] = ' ' patchData["abandoned_cart_item_" + x + "_siz"] = ' ' patchData["abandoned_cart_item_" + x + "_old"] = ' ' patchData["abandoned_cart_item_" + x + "_vis"] = 'display:none' } // Clear Abandoned Cart MauticJS.makePatchRequest(mtc_id, patchData, function(response, status, error) { console.log(status) if(status != 200) console.log(response) else { var mtc_id = localStorage.getItem('mtc_id') var patchData = { 'abandoned_cart' : 'da' } var cartItems = document.querySelectorAll('.header-cart-toggle .item').length var itemNames = [''] var itemPrices = [''] var itemOldPrices = [''] var itemImages = [''] var itemSize = [''] for(var x = 1; x <= cartItems; x++) { itemNames[x] = document.querySelectorAll('.header-cart-toggle .item .title')[x - 1].textContent itemPrices[x] = document.querySelectorAll('.header-cart-toggle .item .price')[x - 1].textContent.split('RSD')[0].trim() if(document.querySelectorAll('.header-cart-toggle .item .prev-price')[x - 1] == undefined) itemOldPrices[x] = '' else itemOldPrices[x] = document.querySelectorAll('.header-cart-toggle .item .prev-price')[x - 1].textContent.split('RSD')[0].trim() + ' RSD' itemImages[x] = 'https://www.unitedfashion.rs' + document.querySelectorAll('.header-cart-toggle .item .img-responsive')[x - 1].getAttribute('src') itemSize[x] = document.querySelectorAll('.header-cart-toggle .item .size')[x - 1].textContent } // console.log(cartItems) for(var x = 1; x <= cartItems; x++) { patchData["abandoned_cart_item_" + x + "_nam"] = itemNames[x] patchData["abandoned_cart_item_" + x + "_pri"] = itemPrices[x] patchData["abandoned_cart_item_" + x + "_old"] = itemOldPrices[x] patchData["abandoned_cart_item_" + x + "_ima"] = itemImages[x] patchData["abandoned_cart_item_" + x + "_siz"] = itemSize[x] patchData["abandoned_cart_item_" + x + "_vis"] = "padding: 0px;background-color: #ffffff" } patchData["iznos_korpe_abandoned"] = konvertujTekstUBroj(document.querySelectorAll('.header-cart-toggle .total-price .value-text')[0].textContent.split('RSD')[0].trim()) patchData["broj_artikala_abandoned"] = cartItems console.log(patchData) // Update Abandoned Cart MauticJS.makePatchRequest(mtc_id, patchData, function(response, status, error) { console.log(status) if(status != 200) console.log(response) }) } }) } function clearAbandonedCart() { var mtc_id = localStorage.getItem('mtc_id') var patchData = { 'broj_artikala_abandoned' : 0, 'abandoned_cart' : 'ne', "iznos_korpe_abandoned" : 0 } for(var x = 1; x <= 5; x++) { patchData["abandoned_cart_item_" + x + "_nam"] = ' ' patchData["abandoned_cart_item_" + x + "_pri"] = ' ' patchData["abandoned_cart_item_" + x + "_ima"] = ' ' patchData["abandoned_cart_item_" + x + "_siz"] = ' ' patchData["abandoned_cart_item_" + x + "_old"] = ' ' patchData["abandoned_cart_item_" + x + "_vis"] = 'display:none' } MauticJS.makePatchRequest(mtc_id, patchData, function(response, status, error) { console.log(status) if(status != 200) console.log(response) }) } function clearAndUpdateAbandonedCartFromCheckout() { var mtc_id = localStorage.getItem('mtc_id') var patchData = { 'broj_artikala_abandoned' : 0, 'abandoned_cart' : 'ne', "iznos_korpe_abandoned" : 0 } for(var x = 1; x <= 5; x++) { patchData["abandoned_cart_item_" + x + "_nam"] = ' ' patchData["abandoned_cart_item_" + x + "_pri"] = ' ' patchData["abandoned_cart_item_" + x + "_ima"] = ' ' patchData["abandoned_cart_item_" + x + "_siz"] = ' ' patchData["abandoned_cart_item_" + x + "_old"] = ' ' patchData["abandoned_cart_item_" + x + "_vis"] = 'display:none' } // Clear Abandoned Cart MauticJS.makePatchRequest(mtc_id, patchData, function(response, status, error) { console.log(status) if(status != 200) console.log(response) else { var mtc_id = localStorage.getItem('mtc_id') var patchData = { 'abandoned_cart' : 'da' } var cartItems = document.querySelectorAll('.cart-table .item').length var itemNames = [''] var itemPrices = [''] var itemOldPrices = [''] var itemImages = [''] var itemSize = [''] for(var x = 1; x <= cartItems; x++) { itemNames[x] = document.querySelectorAll('.cart-table .item .product-item-title > a')[x - 1].textContent itemPrices[x] = document.querySelectorAll('.cart-table .item .product-item-prices')[x - 1].textContent.split('RSD')[0].trim() if(document.querySelectorAll('.cart-discount')[x - 1].textContent.split('\n').join('').trim().split(' ').join('') == 'Popust0,00%') itemOldPrices[x] = '' else itemOldPrices[x] = document.querySelectorAll('.cart-table .item .cart-price')[x - 1].childNodes[1].textContent.split('RSD')[0].trim() + ' RSD' itemImages[x] = 'https://www.unitedfashion.rs' + document.querySelectorAll('.cart-table .item .product-item-image img')[x - 1].getAttribute('src') itemSize[x] = document.querySelectorAll('.cart-table .item .product-item-size')[x - 1].textContent.split('Veličina:')[1].trim() } // console.log(cartItems) for(var x = 1; x <= cartItems; x++) { patchData["abandoned_cart_item_" + x + "_nam"] = itemNames[x] patchData["abandoned_cart_item_" + x + "_pri"] = itemPrices[x] patchData["abandoned_cart_item_" + x + "_old"] = itemOldPrices[x] patchData["abandoned_cart_item_" + x + "_ima"] = itemImages[x] patchData["abandoned_cart_item_" + x + "_siz"] = itemSize[x] patchData["abandoned_cart_item_" + x + "_vis"] = "padding: 0px;background-color: #ffffff" } patchData["iznos_korpe_abandoned"] = konvertujTekstUBroj(document.querySelectorAll('#onepage-product-price-value')[0].textContent.split('RSD')[0].trim()) patchData["broj_artikala_abandoned"] = cartItems if(document.querySelector('#cart_onepage_firstname').value.length > 0) patchData['firstname'] = document.querySelector('#cart_onepage_firstname').value if(document.querySelector('#cart_onepage_email').value.length > 0) patchData['email'] = document.querySelector('#cart_onepage_email').value if(document.querySelector('#cart_onepage_phone').value.length > 0) patchData['mobile'] = document.querySelector('#cart_onepage_phone').value console.log(patchData) // Update Abandoned Cart MauticJS.makePatchRequest(mtc_id, patchData, function(response, status, error) { console.log(status) if(status != 200) console.log(response) done = true }) } }) } function getDataPostUserBuyer() { var mtc_id = localStorage.getItem('mtc_id') var patchData = { 'broj_artikala_abandoned' : 0, 'abandoned_cart' : 'ne', "abandoned_cart_value" : 0, 'kupac' : 'da' } for(var x = 1; x <= 5; x++) { patchData["abandoned_cart_item_" + x + "_nam"] = ' ' patchData["abandoned_cart_item_" + x + "_pri"] = ' ' patchData["abandoned_cart_item_" + x + "_ima"] = ' ' patchData["abandoned_cart_item_" + x + "_siz"] = ' ' patchData["abandoned_cart_item_" + x + "_old"] = ' ' patchData["abandoned_cart_item_" + x + "_vis"] = 'display:none' } var today = new Date(); var dd = parseInt(String(today.getDate()).padStart(2, '0')); var mm = parseInt(String(today.getMonth() + 1).padStart(2, '0')); var yyyy = parseInt(today.getFullYear()); var datum_kupovine = '' + yyyy + '-' + mm + '-' + dd // Kupljeni proizvodi var kupljeni_proizvodi = '' document.querySelectorAll('.product-item-title').forEach(element => { kupljeni_proizvodi += element.textContent + ';' }) patchData['last_purchase_item'] = kupljeni_proizvodi patchData['last_purchase'] = datum_kupovine patchData['last_purchase_item_value'] = konvertujTekstUBroj(document.querySelectorAll('#onepage-product-price-value')[0].textContent.split('RSD')[0].trim()) MauticJS.makePatchRequest(mtc_id, patchData, function(response, status, error) { console.log(status) if(status != 200) console.log(response) }) } try { // NEWSLETTER POPUP setTimeout(function() { document.querySelector('#subscribe_form button[type="submit"]').addEventListener('click', function() { console.log('klik 1') patchNewsletter(document.querySelector('#subscribe_email')) }) document.querySelector('#newsletter_form button.confirm-loader').addEventListener('click', function() { console.log('klik 2') patchNewsletter(document.querySelector('input[name="newsletter_email"]')) }) }, 1000) } catch(err) { } // PDP page if(document.querySelectorAll('.product-details').length > 0) { console.log('PDP') setTimeout(function() { document.querySelector('button.fa-shopping-cart').addEventListener('click', function() { setTimeout(function() { try { if(document.querySelectorAll('.header-cart-toggle .item').length > 0) { clearAndUpdateAbandonedCartFromMiniCart() document.querySelectorAll('[title="Izbrišite"]').forEach(element => { element.addEventListener('click', function() { setTimeout(function() { document.querySelector('[data-bb-handler="confirm"]').addEventListener('click', function() { setTimeout(function() { if(document.querySelectorAll('.header-cart-toggle .item').length > 0) clearAndUpdateAbandonedCartFromMiniCart() else if(document.querySelectorAll('.header-cart-toggle .item').length == 0) clearAbandonedCart() }, 2000) }) }, 1500) }) }) } else if(document.querySelectorAll('.header-cart-toggle .item').length == 0) clearAbandonedCart() } catch(err) { } }, 2000) }) }, 1000) } // Success page else if(document.URL.indexOf('kupovina/confirm') > 0) { getDataPostUserBuyer() } // Kupovina else if(document.URL.indexOf('/kupovina') > 0) { document.addEventListener("mouseout", function(event){ if( (event.clientY <= 0 || event.clientX <= 0 || (event.clientX >= window.innerWidth || event.clientY >= window.innerHeight)) && done == false) { console.log('mouseout') if(document.querySelectorAll('.cart-table .item').length > 0) clearAndUpdateAbandonedCartFromCheckout() else if(document.querySelectorAll('.cart-table .item').length == 0) clearAbandonedCart() } }); }