function BraindwAddEvent(e, ev, callback) { var elements = document.querySelectorAll(e); for (var i = 0; i < elements.length; i++) { elements[i].addEventListener(ev, callback); } } function Braindw_Category(){ var cc = ""; if(document.querySelectorAll('.breadcrumbs li').length != 0){ if(document.querySelector('#product_addtocart_form') != null){ cc = document.querySelectorAll('.breadcrumbs li')[document.querySelectorAll('.breadcrumbs li').length-2].className.split('category')[1]; }else{ cc = document.querySelectorAll('.breadcrumbs li')[document.querySelectorAll('.breadcrumbs li').length-1].className.split('category')[1]; } } var categoryCode = cc; console.log("category", cc); var i = 0; if(categoryCode != undefined && categoryCode != null && categoryCode != ""){ var currentCategory = { "id": cc } braindwObject.current.category = currentCategory; for(item of braindwObject.history.categoryViewed){ if(item.id == categoryCode){ braindwObject.history.categoryViewed.splice(i, 1); } i++; } if(braindwObject.history.categoryViewed.length < 15){ braindwObject.history.categoryViewed.unshift ({ "id": categoryCode }) } else{ braindwObject.history.categoryViewed.splice(14, 1); braindwObject.history.categoryViewed.unshift ({ "id": categoryCode }) } } localStorage.setItem('braindw_object', JSON.stringify(braindwObject)); if(categoryCode != undefined, categoryCode != '', categoryCode != null){ BraindwCaptureCategory(categoryCode); bdw_getCategory(categoryCode); } } function Braindw_Collection(){ if(document.querySelector('#product_addtocart_form') != null){ var cc = document.querySelectorAll('.breadcrumbs li')[document.querySelectorAll('.breadcrumbs li').length - 2 ].className.split('category')[1]; }else{ var cc = document.querySelectorAll('.breadcrumbs li')[document.querySelectorAll('.breadcrumbs li').length - 1 ].className.split('category')[1]; } var collectionCode = cc; console.log("collection", cc); var i = 0; if(collectionCode != undefined && collectionCode != null && collectionCode != ""){ var currentCollection = { "id": cc } braindwObject.current.collection = currentCollection; for(item of braindwObject.history.collectionViewed){ if(item.id == collectionCode){ braindwObject.history.collectionViewed.splice(i, 1); } i++; } if(braindwObject.history.collectionViewed.length < 15){ braindwObject.history.collectionViewed.unshift ({ "id": collectionCode }) } else{ braindwObject.history.collectionViewed.splice(14, 1); braindwObject.history.collectionViewed.unshift ({ "id": collectionCode }) } } localStorage.setItem('braindw_object', JSON.stringify(braindwObject)); } function Braindw_Product() { //var codeProduct = document.querySelector('.product-info-stock-sku .value').textContent; var codeProduct = document.querySelector('#product_addtocart_form').firstElementChild.value; var skuProduct = document.querySelector('#product_addtocart_form').dataset.productSku; console.log("product", codeProduct); console.log("sku", skuProduct); var i = 0; if(codeProduct != undefined && codeProduct != null && codeProduct != ""){ var currentProduct = { "id": codeProduct, "sku": skuProduct } braindwObject.current.product = currentProduct; for(item of braindwObject.history.productViewed){ if(item.id == codeProduct){ braindwObject.history.productViewed.splice(i, 1); } i++; } if(braindwObject.history.productViewed.length < 15){ braindwObject.history.productViewed.unshift ({ "id": codeProduct, "sku": skuProduct, "sellerId": "" }) } else{ braindwObject.history.productViewed.splice(14, 1); braindwObject.history.productViewed.unshift ({ "id": codeProduct, "sku": skuProduct, "sellerId": "" }) } } localStorage.setItem('braindw_object', JSON.stringify(braindwObject)); capturesFichaProduct(skuProduct); } function Braindw_addedProduct() { BraindwAddEvent('#product-addtocart-button', 'click', function(e){ if(document.getElementById('product_addtocart_form')){ var element = document.getElementById('product_addtocart_form'); var codeProduct = element.firstElementChild.value; var skuProduct = element.dataset.productSku; var i = 0; for(item of braindwObject.history.productAdded){ if(item.id == codeProduct){ braindwObject.history.productAdded.splice(i, 1); } i++; } if(braindwObject.history.productAdded.length < 15){ braindwObject.history.productAdded.unshift({ "id": codeProduct, "sku": skuProduct, "sellerId": "" }) } else{ braindwObject.history.productAdded.splice(14, 1); braindwObject.history.productAdded.unshift({ "id": codeProduct, "sku": skuProduct, "sellerId": "" }) } } localStorage.setItem('braindw_object', JSON.stringify(braindwObject)); }); /*Pendiente revisión addToCart de productCard en caso de ser necesario BraindwAddEvent('button.action.tocart.primary', 'click', function(e){ if(braindwObject.history.productAdded.length < 15){ if(document.getElementById('product_addtocart_form')){ var element = document.getElementById('product_addtocart_form'); var productSku = element.getAttribute('data-product-sku'); braindwObject.history.productAdded.unshift({ "id": productSku, "sku": "", "sellerId": "" }) } } localStorage.setItem('braindw_object', JSON.stringify(braindwObject)); });*/ } function Braindw_SearchTerm(searchTerm) { var i = 0; var supr = -1; if(searchTerm != undefined && searchTerm != null && searchTerm != ""){ braindwObject.current.searchTerm = searchTerm; for(item of braindwObject.history.searchedTerm){ if(item == searchTerm){ supr = i; } i++; if(supr != -1){ braindwObject.history.searchedTerm.splice(supr, 1); } } if(braindwObject.history.searchedTerm.length < 15){ braindwObject.history.searchedTerm.unshift(searchTerm); } else{ braindwObject.history.searchedTerm.splice(14, 1); braindwObject.history.searchedTerm.unshift(searchTerm); } } localStorage.setItem('braindw_object', JSON.stringify(braindwObject)); } function Braindw_CartOpened() { var items = []; var cartOpen = braindwObject.current.cartOpen; if(braindwObject.current.cartOpen.length != 0){ braindwObject.current.cartOpen.splice(0); } for(var i=0; i< document.querySelectorAll('tbody.cart.item .item-info').length; i++){ var item = document.querySelectorAll("tbody.cart.item .item-info")[i]; var productCode = item.querySelectorAll(".col.price div")[0].dataset.productId; var productSku = item.querySelectorAll(".control.qty input")[0].dataset.cartItemId; var positionPriceTotal = item.getElementsByClassName("price").length-1; items.push({ ProductTitle: item.getElementsByTagName('a')[0].title, ProductCode: productSku, ProductSku: productSku, ProductUrlImage: item.getElementsByTagName('img')[0].currentSrc, ProductQuantity: item.getElementsByClassName('input-text qty')[0].value, ProductQuantityDetails: '', ProductPrice: item.getElementsByClassName("price")[1].innerHTML.replace(' ',''), PriceTotal: item.getElementsByClassName("price")[positionPriceTotal].innerHTML.replace(' ',''), Event: "Load" }) cartOpen.push({ "id": items[i].ProductCode, "sku": items[i].ProductSku, "qt": items[i].ProductQuantity, "price": items[i].ProductPrice, "total": items[i].PriceTotal, "sellerId": "" }) localStorage.setItem('braindw_object', JSON.stringify(braindwObject)); } } /*function Braindw_CartClosed() { let orderNumber = ""; if(jQuery('.checkout-success h5').text().indexOf('es:') > 0){ orderNumber = jQuery('.checkout-success h5').text().split('es:')[1].trim() } var cartClose = braindwObject.current.cartClose; cartClose.id = orderNumber; let r = orderNumber, i = [], e = { CartNumber: r, Items: i } return e; }*/ function BraindwCaptureCategory(category) { var _bndwOb2 = document.createElement('script'); _bndwOb2.async = true; _bndwOb2.src = _PURLBNDW + "/tracking/capture?HASH="+ _HASHBNDW +"&minify=1&iscategory=true&og:categorycode=" + category; _bndwOb2.charset = "UTF-8"; document.head.appendChild(_bndwOb2); } function BraindwCaptureProduct(skuProduct, isCart, bdwcategories, catCode, inf) { try { let oldPrice = document.querySelectorAll('.price-final_price .price')[0].innerText; let priceInternet = document.querySelectorAll('.price-final_price .price')[1].innerText; var price = priceInternet; var imgProperty = document.querySelector("meta[property='og:image']"); let image = ""; image = imgProperty.content.split('?')[0]; let $title = document.querySelector('.page-title .base'); let title = $title.innerText; let url = document.URL; let categoriescodes = ""; let categorycode = ""; if (bdwcategories != "") { categoriescodes = bdwcategories; categorycode = catCode; } let info = ""; if (inf != undefined){ info = inf; } if (skuProduct && priceInternet && image && title && url) { var data = { CodeProduct: skuProduct, Title: title, Price: priceInternet, Brand: "", CategoryCode: categorycode, UrlImage: image, UrlProduct: url, CategoriesCodes: categoriescodes, PriceSale: priceInternet, OldPrice: oldPrice, }; var urlParameters = "og:title=" + title + "&og:image=" + image + "&og:url=" + url + "&og:categoriescodes=" + categoriescodes + '&og:codeproduct=' + skuProduct + '&og:brand=' + '&og:categorycode=' + categorycode + '&og:price=' + price + '&og:priceold=' + oldPrice + '&og:pricesale=' + priceInternet + '&iscart=' + isCart + '&info=' + info; ; var _bndwOb2 = document.createElement('script'); _bndwOb2.async = true; _bndwOb2.src = _PURLBNDW + "/tracking/capture?HASH="+ _HASHBNDW + "&" + urlParameters; _bndwOb2.charset = "UTF-8"; document.head.appendChild(_bndwOb2); bdw_getProduct(data); } } catch (error) { console.log(error); } } function capturesFichaProduct(bdwProductSku){ console.log('bdw 1: card') var bdwCategoryList = ""; bdwCategoryList = getListCategories(); if(bdwCategoryList.length > 0){ var bdwCategoryCode = bdwCategoryList.split(',')[0]; BraindwCaptureProduct(bdwProductSku, 0, bdwCategoryList, bdwCategoryCode); }else{ BraindwCaptureProduct(bdwProductSku, 0, '', ''); } BraindwAddEvent('#product-addtocart-button, #product-addtocart-button-sticky', 'click', function(e){ console.log('bdw 2: click addtocart',bdwCategoryCode); if (bdwCategoryCode!='' && bdwCategoryCode!= undefined){ BraindwCaptureProduct(bdwProductSku, 1, bdwCategoryList, bdwCategoryCode); } else{ var info = 1; BraindwCaptureProduct(bdwProductSku, 1, bdwCategoryList, bdwCategoryCode, info); } setTimeout(() => { BraindwPushMiniCart(); }, 1500); }); } var bdwMiniCartEvent = false; var bdwReintentMiniCart = 4; function BraindwPushMiniCart(){ bdwReintentMiniCart = bdwReintentMiniCart - 1; if(bdwReintentMiniCart > 0 && !bdwMiniCartEvent) { try{ console.log('bdw evaluate minicart'); let e = { sessionDate: braindw_getSessionDate() }; let _searchTerm = braindw_getSearch(); if (_searchTerm) { e.search = _searchTerm; } e.cartOpened = Braindw_getMiniCart(); if(e.cartOpened.Items.length>0){ bdwMiniCartEvent = true; braindw_sendPersistency(e, localStorage.getItem('bdw_email')); console.log('bdw mc sendp'); } }catch{} setTimeout(() => { BraindwPushMiniCart(); }, 1500); } } function BraindwCaptureEmailsSite(){ /*var rgxHome = new RegExp(".*?:\/\/(.*)mcprod.cetrogar.com.ar\/?$"); if(rgxHome.test(location.href)){*/ if(document.querySelector("button.action.subscribe.primary")!=null) { document.querySelector("button.action.subscribe.primary").onclick = function() { event.preventDefault(); var email = document.querySelector("input#newsletter").value; if(email){ localStorage.setItem('bdw_email', email); //BraindwCookiePush(email); //SendEmail(email); } setTimeout(function() { jQuery("#newsletter-validate-detail").submit(); }, 1500); }; } if(location.href.indexOf('account/login')>-1){ document.querySelector("button#send2").onclick = function() { event.preventDefault(); var email = document.querySelector("input#email").value; if(email){ //BraindwCookiePush(email); localStorage.setItem('bdw_email', email); } setTimeout(function() { jQuery("#login-form").submit(); }, 1500); }; } if(location.href.indexOf('customer/account/create')>-1){ //var element = jQuery('input#inputEmailAge').last(); document.querySelector(".validateBtn").onclick = function() { var email = document.getElementById('inputEmailAge').value; if(email){ localStorage.setItem('bdw_email', email); } }; } bdwMappCapturaEmailCheckoutGuest(); setTimeout(function() { addCaptureEmail(); }, 1500); } var bdwMappedEventEmail = false; var bdwReintentMapping = 4; function bdwMappCapturaEmailCheckoutGuest() { //console.log('bdw bdwMappCapturaEmailCheckoutGuest'); if(location.href.indexOf('checkout/#shipping')>-1) { if(document.getElementById('customer-email-fieldset')!=null) { if(document.getElementById('customer-email-fieldset').querySelector("input[name='username']")!=null) { if(document.getElementById('customer-email-fieldset').querySelector("div.confirm-email button.action.primary")!=null) { if(!bdwMappedEventEmail) { bdwMappedEventEmail=true; document.getElementById('customer-email-fieldset').querySelector("div.confirm-email button.action.primary").addEventListener('click', e => { //function() { try{ var email = document.getElementById('customer-email-fieldset').querySelector("input[name='username']").value; if(email){ localStorage.setItem('bdw_email', email); BraindwCookiePush(email); } } catch (e) { console.log('guest', e); } }); } } } } } bdwReintentMapping = bdwReintentMapping - 1; if(bdwReintentMapping > 0 && !bdwMappedEventEmail) { setTimeout(() => { bdwMappCapturaEmailCheckoutGuest() }, 2000); } } function addCaptureEmail(){ if(location.href.indexOf('checkout/cart/') > -1 && document.querySelector("#bnt-social-login-authentication") != null){ document.querySelector("#bnt-social-login-authentication").onclick = function() { var email = document.querySelector("#social_login_email").value; if(email){ localStorage.setItem('bdw_email', email); BraindwCookiePush(email); } }; } } function getListCategories(){ var categoryPosition = document.querySelectorAll('.breadcrumbs li').length; var listCategories = ""; if(document.querySelector('#product_addtocart_form') != null){ for(i=2; i -1) a = Braindw_getCartOpened(); if (document.URL.indexOf('checkout/onepage/success') > -1) { a = Braindw_getCartClosed(); e.cartClosed = a; }else{ e.cartOpened = a; } braindw_sendPersistency(e, email); } function braindw_getSessionDate() { let result = null; try { let SalesChannel = "";//BraindwGetSucCookie(); result = { SalesChannel: SalesChannel, }; } catch (e) { console.log('braindw_getSessionDate error ', e); } return result; } function BraindwGetSucCookie(){ return ""; } function braindw_getSearch() { let result=null; try { var braindw_url = document.URL; if(braindw_url.toLowerCase().indexOf("/result")===-1) return result; if(document.getElementsByClassName('search results').length == 1){ result = { searchterm: braindwGetUrlParameter("q"), displayResult: 1}; }else{ result = { searchterm: braindwGetUrlParameter("q"), displayResult: 0}; } } catch (e) { console.log(e); } return result; } function Braindw_getCartOpened() { var e = null; var items = []; for(var i=0; i< document.querySelectorAll('tbody.cart.item').length; i++){ let item = jQuery("tbody.cart.item .item-info:eq("+i+")"); let productCode= item.find('.input-text.qty').attr('data-cart-item-id'); items.push({ ProductTitle: item.find('.product-item-name a').text(), ProductCode: productCode, ProductUrlImage: item.find('.product-image-photo').attr("src"), ProductQuantity: item.find('.control.qty .input-text.qty').val(), ProductQuantityDetails: '', ProductPrice: item.find('span.price-excluding-tax span.price').first().text(), PriceTotal: jQuery('.amount span.price').last().text(), Event: "Load" }) } e = { CartNumber: '', BranchOffice: '', Items: items }; return e; } function Braindw_getMiniCart() { var e = null; var items = []; try{ for(var i=0; i< document.querySelectorAll('#mini-cart .product-item').length; i++){ let item = document.querySelectorAll('#mini-cart .product-item')[i]; let productCode= item.querySelector('input.item-qty.cart-item-qty').getAttribute('data-cart-item-id'); items.push({ ProductTitle: item.querySelector('.product-item-name a').innerText, ProductCode: productCode, ProductUrlImage: item.querySelector('.product-image-photo').src, ProductQuantity: item.querySelector('.item-qty.cart-item-qty').value, ProductQuantityDetails: '', ProductPrice: item.querySelector('span.price span.price').innerText.replace('$ ',''), PriceTotal: item.querySelector('span.price span.price').innerText.replace('$ ',''), Event: "Load" }) } } catch(er){} e = { CartNumber: '', BranchOffice: '', Items: items }; return e; } function Braindw_getCartClosed() { let orderNumber = ""; if(jQuery('.checkout-success h5').text().indexOf('es:') > 0){ orderNumber = jQuery('.checkout-success h5').text().split('es:')[1].trim() } var cartClose = braindwObject.current.cartClose; if(braindwObject.current.cartClose.length != 0){ braindwObject.current.cartClose.splice(0); } cartClose.push ({ "id": orderNumber }); localStorage.setItem('braindw_object', JSON.stringify(braindwObject)); let r = orderNumber, i = [], e = { CartNumber: r, Items: i } return e; } function braindw_sendPersistency(e, emailGuest) { let n = { emailguest: emailGuest != undefined ? emailGuest : '', //emailguest: '', dataset: encodeURI(JSON.stringify(e)), page: "", url: window.location.href.split("?")[0], urlb: _NSURLBNDW + '/Script/braindw/'+ _HASHBNDW +'?hs=Thu Dec 04 2019 20:49:26 GMT-0300 (hora estándar de Argentina)', BranchOffice: "" }; fetch('https://p.braindw.com/Api/Data/Capture', { method: "POST", body: JSON.stringify(n), credentials: 'include', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', } }) .then((resp) => resp.json()) .then(function(data) { }) .catch(function(ex) { console.log(ex); }); } function BraindwCookiePush(email) { if (BraindwvalidateEmail(email)) { try { fetch(_NSURLBNDW + '/tracking/SetCookiesNdway?email=' + email + '&company=cetrogar_produccion', { credentials: "include", mode: 'no-cors', method: 'POST', }) .then(function(resp) { return resp.text(); }) .then(function(data) { Braindw_pushInfo(email); return false; }) .catch(function(ex) { console.log(ex); }); } catch (e) {} } } function BraindwvalidateEmail(email) { var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(String(email).toLowerCase()); } var BraindwDomReady = function (callback) { document.readyState === "interactive" || document.readyState === "complete" ? callback() : document.addEventListener("DOMContentLoaded", callback); }; var braindwObject = ""; if (localStorage.getItem('braindw_object') != null && localStorage.getItem('braindw_object') != undefined && localStorage.getItem('braindw_object') != '' && localStorage.getItem('braindw_object') != 'null' && localStorage.getItem('braindw_object') != '""') { braindwObject = JSON.parse(localStorage.getItem('braindw_object')); } else { createObjectBDW(); braindwObject = JSON.parse(localStorage.getItem('braindw_object')); } function createObjectBDW() { var braindwObject = { "filterSectionId": [], "history": { "productViewed": [], "productAdded": [], "searchedTerm": [], "categoryViewed": [], "collectionViewed": [] }, "current": { "product": {}, "category": {}, "collection": {}, "searchTerm": "", "cartOpen": [], "cartClose": [] }, "session": { "name": "", "email": "", "branchOffice": "", "sellerId": "", "guid": "", "country": "", "state": "", "city": "", "ip": "" } }; localStorage.setItem('braindw_object', JSON.stringify(braindwObject)); } //carro abandonado function BraindGetProductsCart(listCodes) { fetch(`https://u.braindw.com/Get/cetrogar?ext=json&company=cetrogar&productids=${listCodes}&minstock=1&sc=&limit=15&sale=0`) .then( function(response) { if (response.status !== 200) { console.log('Looks like there was a problem. Status Code: '); return; } response.json().then(function(data) { BraindPushCart(data) }); } ) .catch(function(err) { console.log('Fetch Error :-S', err); jQuery("#braindw_loader").attr('style', 'display:none'); }); } function showPopup(){ jQuery("body").append(' ' + '