function addToCartAction (){ localCall('addToCart', {pickedProduct:pickedProduct}, (msg)=>{ refreshCart(msg); let btnadd = document.getElementById('addToCart'); if(btnadd){ btnadd.querySelector('.addedCart').style.display=""; btnadd.querySelector('.notaddedCart').style.display="none"; btnadd.classList.add('adaugat'); setTimeout(() => { btnadd.querySelector('.addedCart').style.display="none"; btnadd.querySelector('.notaddedCart').style.display=""; btnadd.classList.remove('adaugat'); }, 4000) } // -- //-- }, failAddToCart, 'POST'); if(typeof pickedProduct.name != 'undefined' && typeof ttq == 'object'){ //ttq.instance('C62I6MC6RDRHMAMD39PG').track('AddToCart'); } if(typeof pickedProduct.name != 'undefined' && typeof fbq == 'function'){ fbq('track', 'AddToCart', { content_name: pickedProduct.name.replace(/&/g, "&"), content_ids: [pickedProduct.id], content_type: 'product', value: pickedProduct.price, currency: 'RON' }); } if(typeof pickedProduct.id != 'undefined' && typeof gtag == 'function'){ gtag('event','add_to_cart', { value:pickedProduct.price, currency: 'RON' , items: [ { item_id: pickedProduct.id, google_business_vertical: 'retail', quantity: 1, item_name: pickedProduct.name.replace(/&/g, "&"), item_variant: pickedProduct.sizeText, item_category: pickedProduct.category, item_category2: pickedProduct.maincat } ] }); } } function failAddToCart(msg){ gotError = JSON.parse(msg); if(gotError){ //alert(gotError.error_text); if(typeof gotError.error_detail !== 'undefined'){ let noti = document.getElementById('stockNotification'); if(noti){ noti.innerHTML = gotError.error_detail; noti.classList.add('ultimulProdus'); } } } } function showBigSlide(){ const clickk = this.dataset['order']; let pictures = document.getElementsByClassName('thumbImage'); let bigslide = document.getElementById('bigslide'); bigslide.innerHTML = ''; let nrpict =0 ; for(const pict of pictures){ let lislide = document.createElement('li'); lislide.innerHTML = ''; bigslide.append(lislide); nrpict++; } let imagefull = document.getElementById('imageFull'); if(imagefull){ document.getElementById('body').classList.add('hideOverflow'); imagefull.style.display = ''; document.getElementsByClassName bigslide.style.columns = nrpict; let bigcarousel = new Carousel('bigslide'); bigcarousel.addControls('arrowright1','arrowLeft1'); bigcarousel.goto(clickk); } } function getFullImageQuality(){ let pictures = document.getElementsByClassName('thumbImage'); for(const pict of pictures){ pict.addEventListener('click', showBigSlide); let dumyimg = new Image(); dumyimg.addEventListener('load',(event)=>{ pict.src = (pict.src).replace('thumbs/', 'photos/'); }); dumyimg.src = (pict.src).replace('thumbs/', 'photos/'); } } var count = 1; var countEl = document.getElementById("quantity"); function plus(){ count++; countEl.value = count; } function minus(){ if (count > 1) { count--; countEl.value = count; } } // click outside const specifiedElement = document.getElementById('selector'); if(specifiedElement){ document.getElementById('selector').addEventListener('click', function() { document.getElementById('selectorList').classList.toggle('viewSelect'); }); document.addEventListener('click', event => { const isClickInside = specifiedElement.contains(event.target) if (!isClickInside) { document.getElementById('selectorList').classList.remove('viewSelect'); } }) } let openSizes = document.getElementById('openSizes'); if(openSizes) openSizes.addEventListener('click', ()=>{ let tblmod = document.getElementById('tabelMarimi'); if(tblmod){ document.getElementById('body').classList.add('hideOverflow'); document.getElementById('overlay').classList.add('overlayed'); tblmod.style.display = "block"; } }) let closeBtn = document.getElementsByClassName("closeParent"); Array.from(closeBtn).forEach(close => { if(!close.classList.contains('clickable')){ close.classList.add('clickable'); close.addEventListener('click', ()=> {document.getElementById('body').classList.remove('hideOverflow'); document.getElementById('overlay').classList.remove('overlayed'); close.parentNode.style.display = 'none'}); } }) function closePopups(t){ document.getElementById('body').classList.remove('hideOverflow'); document.getElementById('overlay').classList.remove('overlayed'); t.style.display = 'none'; } function getProductVariations(id){ localCall("getProductsVariations", 'id[]='+id, msg =>{ if(typeof msg.items[id] === 'undefined'){ console.log(msg); return false; } Object.values(msg.items[id]).forEach(sizeE => { console.log(sizeE); }); } , fail => {console.log(fail)}); } function pickThisProduct(){ let pa = this.attributes['data-value']; let va = parseInt(this.attributes['data-available'].value); let si = this.attributes['data-size'].value; let sit = this.innerText; Array.from(document.getElementsByClassName('size-available')).forEach(ll => ll.classList.remove('selected')); if(pa && pa.value){ let dsl = document.getElementById('selectedItem'); if(dsl){ dsl.innerHTML = this.innerHTML+" - ";//put by sizeId if you want } this.classList.add('selected'); pickedProduct.id = pa.value; pickedProduct.sizeText = sit; let stoknot =document.getElementById('stockNotification'); if(va < 4 && va > 0){ if(va == 1){ stoknot.innerHTML = 'Ultimul produs'; }else{ stoknot.innerHTML = 'Ultimele '+(va.toString())+' produse'; } //stoknot.innerHTML = (va==1?"Ultimul":"Ultimele")+" "+(va>1?va:"")+" produs"+(va>1?"e":"")+"" }else{ stoknot.innerHTML = 'In stoc'; } } }