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');
}
// --
//--
}, 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.name != 'undefined' && typeof gtag == 'function'){
gtag('event','add_to_cart', {
'value':pickedProduct.price,
'items': [
{
'id': pickedProduct.id,
'google_business_vertical': 'retail'
}
]
});
}
}
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(){
// /console.log(this);
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('arrowright2','arrowLeft2');
if(typeof this.attributes['data-posx'] !== 'undefined'){
bigcarousel.goto(this.attributes['data-posx'].value);
}
}
}
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 productId = this.attributes['data-product-id'].value
let price = this.attributes['data-price'].value
let priceS = this.attributes['data-price-s'].value
let priceL = this.attributes['data-price-l'].value
let url = new URL(window.location.href)
url.searchParams.set("pid", productId)
window.location.href = url;
// let html = ''
// if (priceS > 0) {
// let discount = Math.ceil(100 - price/priceS*100);
// html = `${discount} %`
// +`