(function(){ var elmProduits=$("#produits"); var baseProduit=$('\
\
\  €\ \
\ '); $.getJSON("/json.php?id=bdc&lang=en",function(data,status){ var produit=data.produit; var conditionnement=data.conditionnement; var elmTotal=$(); var elmErreurs=$(); var form=$(); function calculTotal(livraison){ var total=0; var nbr_btl=0; var fdp=0; var remise=0; var promo=0; promo = $(".promo .valeur").text(); if(promo==""){promo=0;} $.each(produit,function(k,v){ nbr_btl+=v.conditionnement.conditionnement*v.quantite; if(v.prix_remise!="0.00"){ if (promo>0){ total+=v.quantite*v.prix; } else { total+=v.quantite*v.prix_remise; } } else { total+=v.quantite*v.prix; } }); if(typeof livraison == 'undefined'){ livraison=0; } if(nbr_btl>0 && nbr_btl <7){ fdp=10; } if(nbr_btl>6 && nbr_btl <13){ fdp=15; } if(nbr_btl>12 && nbr_btl <25){ fdp=20; } if(nbr_btl>24 && nbr_btl <42){ fdp=35; } if(nbr_btl>41 || livraison>=3){ fdp=0; } if(nbr_btl>59 && nbr_btl<150){ remise=3; } if(nbr_btl>149){ remise=5; } $(".fdp .valeur").text(aff_prix(fdp)); $(".remise .valeur").text(aff_prix(remise)); elmTotal.text(aff_prix(total)); if (remise>0 && promo>0){ $("#remise").css('display', ''); var calcul = total-(total*10/100); var cumul = total-(total*remise/100)-((total-(total*remise/100))*promo/100); if(cumul < calcul){ var calculremise = calcul; //totalttc=total-(calculremise*total/100); $(".totalttc .valeur").text(aff_prix(calculremise+fdp)); } else { var calculremise = cumul; //totalttc=total-(calculremise*total/100); $(".totalttc .valeur").text(aff_prix(calculremise+fdp)); } } else if(remise>0 && promo==0){ $("#remise").css('display', ''); totalttc=total-(remise*total/100); $(".totalttc .valeur").text(aff_prix(totalttc+fdp)); } else if(remise==0 && promo>0){ $("#remise").css('display', 'none'); totalttc=total-(promo*total/100); $(".totalttc .valeur").text(aff_prix(totalttc+fdp)); } /*if (typeof $(".remise .valeur") != 'undefined') { //alert('remise'); totalttc=total-(remise*total/100); $(".totalttc .valeur").text(aff_prix(totalttc+fdp)); }*/ else { //alert('sans remise'); $("#remise").css('display', 'none'); $(".totalttc .valeur").text(aff_prix(total+fdp)); } } $.each(conditionnement,function(k,v){ v.produit=[]; }); $.each(produit,function(k,v){ var _conditionnement=conditionnement[v.conditionnement]; _conditionnement.produit.push(v); v.conditionnement=_conditionnement; v.elm=baseProduit.clone(); //$(".selection",v.elm).append(v.ordre); var image=$.creeLightbox(v.image, v.image_mini,{minWidth:49,minHeight:175}); $(".image",v.elm).append(image); /*$(".cadre",v.elm).click(function(){ image.triggerHandler('click'); });*/ image.attr({title:v.titre+" - "+v.conditionnement.titre_bdc_en+" - "+aff_prix(v.prix)+" €"}); $(".titre",v.elm).text(v.titre); $(".conditionnement",v.elm).text((function(texte){return texte.substr(0,1).toUpperCase()+texte.substr(1);})(v.conditionnement.titre_bdc_en)); var promo=0; promo = $(".promo .valeur").text(); if(promo==""){promo=0;} if(v.prix_remise!="0.00"){ if (promo>0){ v.prix=parseFloat(v.prix); $.fancybox.dialog.alert("An already reduced rate cannot be combined with a promo code!"); } else { v.prix=parseFloat(v.prix_remise); } } else { v.prix=parseFloat(v.prix); } $(".prix>.valeur",v.elm).text(aff_prix(v.prix)); //v.quantite=0; var input=$("").val(v.quantite); $(".quantite",v.elm).append(input); //initialisation sstot $(".sstot",v.elm).text(aff_prix(v.prix*v.quantite)); $(".supprimer",v.elm).append('remove'); var rad = document.bdc.addr_livr; var prev = null; for(var i = 0; i < rad.length; i++) { rad[i].onclick = function () { //(prev)? console.log(prev.value):null; if(this !== prev) { prev = this; } var livraison = this.value; calculTotal(livraison); }; } input.inputNumber({max:v.conditionnement.max||999}); input.change(function(){ v.quantite=toInt(this.value); calculTotal(); v.elm.toggleClass("selected",v.quantite>0); //$(".selection",v.elm)[v.quantite>0?"fadeIn":"fadeOut"](); //mise à jour des sstot $(".sstot",v.elm).text(aff_prix(v.prix*v.quantite)); }); v.elm.toggleClass("selected",v.quantite>0); //$(".selection",v.elm).toggle(v.quantite>0); $(document).ready(function(){ elmProduits.append(v.elm); }); /*dataLayer.push({ 'event': 'begin_checkout', 'ecommerce': { 'items': [{ "id": v.ordre, "name": v.titre, "list_name": "Champagne", "brand": "GONET SULCOVA", "category": "Champagne", "variant": v.conditionnement.titre_bdc_en, "list_position": v.ordre, "quantity": v.quantite, "price": v.prix }] } });*/ }); var titres=$(">.produit>.titre",elmProduits); titres.height(titres.heighter()); /* if(!$.browser.msie||$.browser.version<=9) $(">.produit",elmProduits).each(function(k,v){ $(this) .css({scale:0}) .hide() .delay(k*50) .show() .animate({scale:1},200); }); */ $(function(){ elmTotal=$(".total .valeur"); var panneau_erreur=$("#panneau_erreur"); form=$("#bdc"); form.submit(function(){//test erreurs var erreurs=[]; var total=0; $.each(conditionnement,function(k1,v1){ var quantite=0; $.each(v1.produit,function(k2,v2){ quantite+=v2.quantite; }); total+=quantite; if(v1.max!==null && quantite>v1.max) { erreurs.push("The order is limited to "+accord(v1.max,v1.titre_en)+"."); return true; } var modulo=quantite%v1.quantite; if(modulo>0){ var complement=(v1.quantite-modulo); erreurs.push("The shipment is done in boxes of "+accord(v1.quantite,v1.titre_en)+",\nyou have selected "+accord(quantite,v1.titre_en)+",\nadd "+accord(complement,v1.titre_en)+" to complete the box."); } }); if(total==0){ erreurs.push("You have not selected any product"); } var elmErreurs=$('