//stop items in de local storage na klikken op de knop $(document).on('click','.diensten_inner_image','data',function(){ //clear_wl_shop_items_from_local_storage(); }); $(document).on('click','.wl_shop_remove_row','data',function(){ var deze = $(this); wl_shop_ask_to_delete(deze); }); $(document).on('click','.wl_bestel_product','data',function(){ wl_shop_count_items = 0; var deze = $(this); //var vorige = deze.prev(); //var aantal = vorige.val(); var deze_entry_id = deze.data('entry_id'); var vorige = deze.closest('.wl_shop_productpage').find('#wl_shop_id_'+deze_entry_id); var aantal = vorige.val(); var deze_artikelid = deze.data('artikelid'); aantal = aantal * 1; //alert(aantal); if (aantal == '' || aantal == 0){ var html = 'Vul eerst een aantal in'; vorige.velocity("callout.shake"); wl_alert('alert', html,false,false,'Ok',''); return false; } if (localStorage.getItem("wl_shop_"+deze_artikelid) === null) { add_product_to_winkelmand(deze); }else{ wl_alert('confirm', 'Product komt al voor in de winkelmand, toch toevoegen?',wl_shop_hoe_product_toevoegen,false,'Ja','Nee',deze); } }); function wl_shop_hoe_product_toevoegen(deze){ //var vorige = deze.prev(); //var aantal = vorige.val(); var deze_entry_id = deze.data('entry_id'); var vorige = deze.closest('.wl_shop_productpage').find('#wl_shop_id_'+deze_entry_id); var aantal = vorige.val(); wl_alert('confirm', 'Wil u '+aantal+' stuks optellen bij het product in de winkelmand? Of wil u het product als extra regel toevoegen in de winkelmand?',wl_shop_product_optellen,product_als_nieuwe_regel_toevoegen,'Optellen','Nieuwe regel',deze); } function wl_shop_product_optellen(deze){ // var vorige = deze.prev(); // var aantal = vorige.val(); var deze_entry_id = deze.data('entry_id'); var vorige = deze.closest('.wl_shop_productpage').find('#wl_shop_id_'+deze_entry_id); var aantal = vorige.val(); aantal = aantal * 1; var deze_artikelid = deze.data('artikelid'); var retrieved_array_optellen = JSON.parse(localStorage.getItem("wl_shop_"+deze_artikelid)); var aantal_in_storage = retrieved_array_optellen[2]; aantal_in_storage = aantal_in_storage * 1; nieuw_aantal = aantal_in_storage + aantal; // $('.wl_shop_row_'+deze_artikelid).remove(); add_product_to_winkelmand(deze, nieuw_aantal); } var wl_shop_count_items = 0; function product_als_nieuwe_regel_toevoegen(deze){ //var vorige = deze.prev(); //var aantal = vorige.val(); var deze_entry_id = deze.data('entry_id'); var vorige = deze.closest('.wl_shop_productpage').find('#wl_shop_id_'+deze_entry_id); var aantal = vorige.val(); aantal = aantal * 1; var deze_artikelid = deze.data('artikelid'); wl_shop_count_items = (wl_shop_count_items + 1) *1; if (localStorage.getItem('wl_shop_'+deze_artikelid+'_'+wl_shop_count_items) === null) { $('.wl_shop_row').remove(); add_product_to_winkelmand(deze, false, wl_shop_count_items); }else{ //alert('bestaat al: wl_shop_'+deze_artikelid+'_'+wl_shop_count_items); product_als_nieuwe_regel_toevoegen(deze); } } function add_product_to_winkelmand(deze, nieuw_aantal, count_items){ //var vorige = deze.prev(); //var aantal = vorige.val(); var deze_entry_id = deze.data('entry_id'); var vorige = deze.closest('.wl_shop_productpage').find('#wl_shop_id_'+deze_entry_id); var aantal = vorige.val(); var origineel_aantal = aantal; if (nieuw_aantal != null && nieuw_aantal != false ){ aantal = nieuw_aantal; } aantal = aantal * 1; //var deze_opmerking = $('#wl_shop_opmerking_'+deze_entry_id).val(); var deze_opmerking = ''; if (deze.closest('.wl_shop_productpage').find('#wl_shop_opmerking_'+deze_entry_id).length){ deze_opmerking = deze.closest('.wl_shop_productpage').find('#wl_shop_opmerking_'+deze_entry_id).val(); } var deze_product = deze.data('product'); var deze_prijs = deze.data('prijs'); var deze_artikelid = deze.data('artikelid'); var deze_image = deze.data('wl_image'); var deze_href = deze.data('wl_href'); var artikel_id_identifier = '0'; if (count_items != null){ artikel_id_identifier = deze_artikelid+"_"+count_items; //alert('deze_artikelid= '+deze_artikelid) } var array = [deze_artikelid,deze_product,aantal,deze_prijs,deze_image,deze_href,artikel_id_identifier,deze_opmerking,deze_entry_id]; if (count_items != null){ deze_artikelid = deze_artikelid+"_"+count_items; //alert('deze_artikelid= '+deze_artikelid) } localStorage.setItem('wl_shop_'+deze_artikelid, JSON.stringify(array)); //array2 = JSON.parse(localStorage.getItem("array")); if ($('#wl_shop_insert_here').length){ get_items_from_local_storage(); }else{ update_winkelmand_icoon(); } wl_alert('confirm', ''+origineel_aantal+' item(s) toegevoegd aan de winkelmand! Wilt u de winkelmand nu bekijken?',wl_shop_ga_naar_winkelmand,remove_green_color_alert,'Mandje bekijken','verder shoppen',deze); $('.confirm_txt_content').addClass('wl-shop_alert_winkelmand'); //wl_shop_count_items = 0; } function wl_shop_ga_naar_winkelmand(){ $('.winkelmand_link').trigger('click'); window.setTimeout(function(){ $('.confirm_txt_content').removeClass('wl-shop_alert_winkelmand'); }, 500); } function remove_green_color_alert(){ window.setTimeout(function(){ $('.confirm_txt_content').removeClass('wl-shop_alert_winkelmand'); wl_shop_pulse_widget(); }, 500); } function get_items_from_local_storage(focus){ var display_aantal = 0; var totaal_prijs = 0; $('.wl_shop_row').remove(); var tr_mail = ""; for (i = 0; i < localStorage.length; i++) { //console.log(localStorage.key(i) + "=[" + localStorage.getItem(localStorage.key(i)) + "]"); // if(localStorage.key(i).startsWith("wl_shop_") ){ if(localStorage.key(i).indexOf('wl_shop_') == 0 ){ var retrieved_array = JSON.parse(localStorage.getItem(localStorage.key(i))); var product_code = retrieved_array[0]; var product_naam = retrieved_array[1]; var product_aantal = retrieved_array[2]; var product_prijs = retrieved_array[3]; var product_image = retrieved_array[4]; var product_href = retrieved_array[5]; var product_identifier = retrieved_array[6]; var product_opmerking = retrieved_array[7]; var entryID = retrieved_array[8]; //alert(product_opmerking); if (product_identifier == '0' || product_identifier == null){ product_identifier = product_code; } var product_opmerking_insert = ""; if (product_opmerking != ''){ //alert('t'); product_opmerking_insert = "
Opmerking: "+product_opmerking+"
"; } var totaal_prijs_product = (product_aantal *1) * (product_prijs * 1); totaal_prijs = totaal_prijs + totaal_prijs_product; var totaal_prijs_product = totaal_prijs_product.toFixed(2); product_prijs = product_prijs * 1; var tr_data = ""; $('#wl_shop_insert_here').append(tr_data); tr_mail += ""; product_aantal = product_aantal * 1; display_aantal = display_aantal + product_aantal; } } var winkelmand_aantal = "
"+display_aantal+"
"; $('.wl-shop_winkelmand_aantal').remove(); if (display_aantal != 0){ $('.winkelmand_link').append(winkelmand_aantal); if (focus != null){ var focus_item = $('#'+focus); var focus_waarde = focus_item.val(); focus_item.focus(); focus_item.val(''); focus_item.val(focus_waarde); } $('.wl_shop_mandje_leeg').hide(); $('.wl_shop_table_wrapper').show(); $('.wl_shop_total_price').html(totaal_prijs.toFixed(2)); wl_shop_pulse_widget(); tr_mail += "
productaantalprijs SRDtotaal
"+product_naam+"
art: "+product_code+""+product_opmerking_insert+"
"+product_prijs.toFixed(2)+""+totaal_prijs_product+"
"+product_naam+"
art: "+product_code+""+product_opmerking_insert+"
"+product_aantal+""+product_prijs.toFixed(2)+""+totaal_prijs_product+"
Totaal (Inclusief BTW)"+totaal_prijs.toFixed(2)+"
"; $('#contact_iframe').contents().find('#winkelmanditems_html').val(tr_mail); }else{ $('.wl_shop_mandje_leeg').show(); $('.wl_shop_table_wrapper').hide(); } } function wl_shop_ask_to_delete(deze){ wl_alert('confirm', 'Wilt u dit item verwijderen uit de winkelmand?',wl_shop_delete_row,false,'ja','nee',deze); } function wl_shop_delete_row(deze){ var deze_id = deze.attr('id'); deze_id_stripped = deze_id.substring(7); $('.wl_shop_row_'+deze_id_stripped).hide(1000); $('.wl_shop_row_'+deze_id_stripped).find('td').fadeOut(150); //}, 100); localStorage.removeItem('wl_shop_'+deze_id_stripped); // update_winkelmand_icoon(); window.setTimeout(function(){ get_items_from_local_storage() }, 1000); } function clear_wl_shop_items_from_local_storage(){ //loop door alle Localstorage items heen Object.keys(localStorage).forEach(function(key){ //if(key.startsWith("wl_shop_") ){ if(key.indexOf('wl_shop_') == 0 ){ //console.log(key); localStorage.removeItem(key); } get_items_from_local_storage(); //console.log(localStorage.getItem(key)); }); } $(document).on('input','.wl_numbers_only','',function(){ var deze = $(this); var deze_waarde = deze.val(); deze_waarde = deze_waarde.replace(/[^0-9\.\,]/g,''); if (deze_waarde.indexOf(',') > -1){ deze_waarde = deze_waarde.replace(/,/g, '.'); } deze.val(deze_waarde); }); $(document).on('input','.wl_shop_aantal_table','',function(){ var deze = $(this); var deze_identifier = deze.data('localstorage_id'); //deze_identifier = deze_identifier.substring(12); //deze_identifier = "wl_shop_"+deze_identifier; //alert(deze_identifier); var deze_id = deze.attr('id'); var deze_product_prijs = deze.data('product_prijs'); var deze_waarde = deze.val(); var retrieved_array = JSON.parse(localStorage.getItem(deze_identifier)); var product_code = retrieved_array[0]; var product_naam = retrieved_array[1]; //var product_aantal = retrieved_array[2]; var product_aantal = deze_waarde; var product_prijs = retrieved_array[3] * 1; var product_image = retrieved_array[4]; var product_href = retrieved_array[5]; var product_identifier = retrieved_array[6]; var product_opmerking = retrieved_array[7]; var entryID = retrieved_array[8]; //alert('aantal= '+product_aantal); var array = [product_code,product_naam,product_aantal,product_prijs,product_image,product_href,product_identifier,product_opmerking,entryID]; localStorage.setItem(deze_identifier, JSON.stringify(array)); //get_items_from_local_storage(deze_id); var totaal_prijs = 0; var eenheids_prijs = deze.closest('.wl_shop_row').find('.eenheids_prijs').html(); eenheids_prijs = eenheids_prijs * 1; deze_waarde = deze_waarde * 1; //console.log('deze_waarde= '+deze_waarde+' eenheids_prijs='+eenheids_prijs); var nieuwe_berekende_totaal_prijs = deze_waarde * eenheids_prijs; deze.closest('.wl_shop_row').find('.totaal_product').html(nieuwe_berekende_totaal_prijs.toFixed(2)); $('.totaal_product').each(function() { var dit = $(this); var waarde = dit.html() * 1; console.log(waarde); totaal_prijs = totaal_prijs + waarde; }); $('.wl_shop_total_price').html(totaal_prijs.toFixed(2)) //deze.focus(); }); $(document).on('change','.wl_shop_aantal_table','',function(){ get_items_from_local_storage(); }); /* $(document).on('change','.wl_numbers_only','',function(){ var deze = $(this); var tt = deze.val(); if (tt.indexOf(',') > -1){ tt = tt.replace(/,/g, '.'); deze.val(tt); deze.trigger('change'); } }); */ function update_winkelmand_icoon(){ var display_aantal = 0; for (i = 0; i < localStorage.length; i++) { //console.log(localStorage.key(i) + "=[" + localStorage.getItem(localStorage.key(i)) + "]"); //if(localStorage.key(i).startsWith("wl_shop_") ){ if(localStorage.key(i).indexOf('wl_shop_') == 0 ){ var retrieved_array = JSON.parse(localStorage.getItem(localStorage.key(i))); var product_aantal = retrieved_array[2]; product_aantal = product_aantal * 1; display_aantal = display_aantal + product_aantal; } } var winkelmand_aantal = "
"+display_aantal+"
"; $('.wl-shop_winkelmand_aantal').remove(); if (display_aantal != 0){ $('.winkelmand_link').append(winkelmand_aantal); $('.wl_shop_mandje_leeg').hide(); $('.wl_shop_table_wrapper').show(); wl_shop_pulse_widget(); }else{ $('.wl_shop_mandje_leeg').show(); $('.wl_shop_table_wrapper').hide(); } } function wl_shop_pulse_widget(){ window.setTimeout(function(){ $('.wl-shop_winkelmand_aantal').addClass('wl-shop_winkelmand_aantal_anim'); window.setTimeout(function(){ $('.wl-shop_winkelmand_aantal').removeClass('wl-shop_winkelmand_aantal_anim'); }, 500); }, 100); } $(document).ready(function () { update_winkelmand_icoon(); }); $(document).on('click','.update_prijzen','data',function(){ var productIDs = new Object(); var val = ''; for (i = 0; i < localStorage.length; i++) { //console.log(localStorage.key(i) + "=[" + localStorage.getItem(localStorage.key(i)) + "]"); val = localStorage.key(i); //if(localStorage.key(i).startsWith("wl_shop_") ){ if(localStorage.key(i).indexOf('wl_shop_') == 0 ){ var retrieved_array = JSON.parse(localStorage.getItem(localStorage.key(i))); productIDs[val] = retrieved_array[8]; } } // alert(productIDs); console.log(productIDs); $.ajax({ url: 'index.php', type: 'GET', data: {class:'entry',task:'wl_shop_get_prijzen_for_IDs',attributes:productIDs}, cache: false, // dataType:'json', success: function (html) { //alert(html); var rows = html.split('|'); var prijzen_aangepast = false; for (var key in rows) { var detail = rows[key].split('='); //alert(detail[1]); var retrieved_array = JSON.parse(localStorage.getItem(detail[0])); var old_prijs = retrieved_array[3] * 1; var product_code = retrieved_array[0]; var product_naam = retrieved_array[1]; var product_aantal = retrieved_array[2]; var product_prijs = detail[1] * 1; var product_image = retrieved_array[4]; var product_href = retrieved_array[5]; var product_identifier = retrieved_array[6]; var product_opmerking = retrieved_array[7]; var entryID = retrieved_array[8]; //alert('aantal= '+product_aantal); var array = [product_code,product_naam,product_aantal,product_prijs,product_image,product_href,product_identifier,product_opmerking,entryID]; localStorage.setItem(detail[0], JSON.stringify(array)); if (old_prijs != product_prijs){ prijzen_aangepast = true; } // localStorage.detail[0][3] = 200; } if (prijzen_aangepast){ wl_alert('alert','Prijzen in de winkelmand zijn geupdatet',false,false,'Ok','',false); } get_items_from_local_storage(); }, error: function(error){ wl_alert('alert','Connection lost, please try again.' + error,false,false,'Ok','',false); console.log('error'+error); }, complete: function(){ $('.loading').hide(); } }); }); ////////////