//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 = 'Please provide a quantity'; 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', 'This Product is already in your cart, would you like to add it anyway?',wl_shop_hoe_product_toevoegen,false,'Ja','Nee',deze); wl_shop_product_optellen(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 deze_eenheid = deze.data('wl_eenheid'); var deze_afwijking = deze.data('wl_afwijking'); 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,deze_eenheid,deze_afwijking]; var d=new Date(); var timestamp = d.getTime(); var array = {'artikelid':deze_artikelid,'product':deze_product,'aantal':aantal,'prijs':deze_prijs,'image':deze_image,'href':deze_href,'artikel_identifier':artikel_id_identifier,'opmerking':deze_opmerking,'entryid':deze_entry_id,'eenheid':deze_eenheid,'afwijking':deze_afwijking,'timestamp':timestamp}; 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) added to your cart! Would you like to view your cart?',wl_shop_ga_naar_winkelmand,remove_green_color_alert,'View cart','continue shopping',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 dynamicSort(property) { var sortOrder = 1; if(property[0] === "-") { sortOrder = -1; property = property.substr(1); } return function (a,b) { /* next line works with strings and numbers, * and you may want to customize it to your needs */ var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0; return result * sortOrder; } } function get_items_from_local_storage(focus){ var product_afwijking_aanwezig = false; var koers_array = get_koers_per_regio(); var koers = koers_array[0]; var koers_label = koers_array[1]; $('.valuta_changer').html(koers_label); //koers2 = koers[1]; //console.log('koers: '+koers_label); var display_aantal = 0; var totaal_prijs = 0; $('.wl_shop_row').remove(); var tr_mail = ""; var arraysort_var = new Array(); var sorted_arraysort_var = new Array(); for (i = 0; i < localStorage.length; i++) { //console.log(localStorage.key(i) + "=[" + localStorage.getItem(localStorage.key(i)) + "]"); if(localStorage.key(i).indexOf('wl_shop_') == 0 ){ arraysort_var.push(JSON.parse(localStorage.getItem(localStorage.key(i)))); } } arraysort_var.sort(dynamicSort("timestamp")); for (i = 0; i < arraysort_var.length; i++) { var retrieved_array = arraysort_var[i]; var product_code = retrieved_array.artikelid; var product_naam = retrieved_array.product; var product_aantal = retrieved_array.aantal; var product_prijs = retrieved_array.prijs; var product_image = retrieved_array.image; var product_href = retrieved_array.href; var product_identifier = retrieved_array.artikel_identifier; var product_opmerking = retrieved_array.opmerking; var entryID = retrieved_array.entryid; var timestamp = retrieved_array.timestamp; var product_eenheid = retrieved_array.eenheid; var product_afwijking = retrieved_array.afwijking; var product_afwijking_marker = ''; var product_afwijking_class = ''; if (product_afwijking == 1){ product_afwijking_marker = ' *'; product_afwijking_class = 'product_afwijking_class'; product_afwijking_aanwezig = true; } //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 = "
Remark: "+product_opmerking+"
"; } //current_eenheid = 'kg'; //current_region_eenheid = 1; product_prijs = product_prijs * 1; product_prijs = product_prijs * current_region_eenheid; //console.log('product_prijs '+product_prijs); //console.log('product_prijs tomoney'+product_prijs.toMoney(2)); var product_prijs_tbv_totaal = product_prijs.toMoney(2); //////var totaal_prijs_excl_aantal = ((product_prijs_tbv_totaal * 1)) * (koers * 1); var totaal_prijs_excl_aantal = ((product_prijs * 1)) * (koers * 1); totaal_prijs_excl_aantal = totaal_prijs_excl_aantal.toMoney(2); var totaal_prijs_product = ((totaal_prijs_excl_aantal * 1) * (product_aantal *1)); //var totaal_prijs_product = ((product_aantal *1) * (product_prijs_tbv_totaal * 1)) * (koers * 1); totaal_prijs = totaal_prijs + totaal_prijs_product; totaal_prijs_product = totaal_prijs_product.toMoney(2); product_prijs = (product_prijs * 1) * (koers * 1); product_prijs = product_prijs.toMoney(2); 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.toMoney(2)); wl_shop_pulse_widget(); //tr_mail += "
ProductEenheidQuantity ("+current_eenheid+")Price "+koers_label+"Total "+koers_label+"
"+product_naam+product_afwijking_marker+"
art: "+product_code+""+product_opmerking_insert+"
"+product_eenheid+product_afwijking_marker+""+product_prijs+""+totaal_prijs_product+"
"+product_naam+product_afwijking_marker+"
art: "+product_code+""+product_opmerking_insert+"
"+product_eenheid+product_afwijking_marker+""+product_aantal+""+product_prijs+""+totaal_prijs_product+"
Total "+koers_label+""+totaal_prijs.toMoney(2)+"
"; //$('#contact_iframe').contents().find('#winkelmanditems_html').val(tr_mail); tr_mail += "Total"+totaal_prijs.toMoney(2)+""; if (product_afwijking_aanwezig){ $('#prijs_afwijking_text').show(); tr_mail += "
* LET OP! Producten met een sterretje zijn producten
waarvan de gewichten bij levering iets
kunnen afwijken van het bestelde gewicht.
We nemen vóór levering hierover contact op met u!"; }else{ $('#prijs_afwijking_text').hide(); } $('#contact_iframe').contents().find('#winkelmanditems_html').val(tr_mail); }else{ $('.wl_shop_mandje_leeg').show(); $('.wl_shop_table_wrapper').hide(); } $('.wl_unit_converter').html(current_eenheid); } function wl_shop_ask_to_delete(deze){ wl_alert('confirm', 'Remove this item from your cart?',wl_shop_delete_row,false,'yes','no',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.artikelid; var product_naam = retrieved_array.product; var product_aantal = deze_waarde; var product_prijs = retrieved_array.prijs; var product_image = retrieved_array.image; var product_href = retrieved_array.href; var product_identifier = retrieved_array.artikel_identifier; var product_opmerking = retrieved_array.opmerking; var entryID = retrieved_array.entryid; var product_eenheid = retrieved_array.eenheid; var product_afwijking = retrieved_array.afwijking; var timestamp = retrieved_array.timestamp; //alert('aantal= '+product_aantal); //var array = [product_code,product_naam,product_aantal,product_prijs,product_image,product_href,product_identifier,product_opmerking,entryID,product_eenheid,product_afwijking]; var array = {'artikelid':product_code,'product':product_naam,'aantal':product_aantal,'prijs':product_prijs,'image':product_image,'href':product_href,'artikel_identifier':product_identifier,'opmerking':product_opmerking,'entryid':entryID,'eenheid':product_eenheid,'afwijking':product_afwijking,'timestamp':timestamp}; 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.toMoney(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.toMoney(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.aantal; 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(); } } prevent_double_pulse = false; function wl_shop_pulse_widget(){ if (prevent_double_pulse == false){ prevent_double_pulse = true; 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); window.setTimeout(function(){ prevent_double_pulse = false; }, 2000); }, 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.entryid; } } // 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.prijs * 1; var product_code = retrieved_array.artikelid; var product_naam = retrieved_array.product; var product_aantal = retrieved_array.aantal; var product_prijs = detail[1] * 1; var product_image = retrieved_array.image; var product_href = retrieved_array.href; var product_identifier = retrieved_array.artikel_identifier; var product_opmerking = retrieved_array.opmerking; var entryID = retrieved_array.entryid; var product_eenheid = retrieved_array.eenheid; var product_afwijking = retrieved_array.afwijking; var timestamp = retrieved_array.timestamp; //alert('aantal= '+product_aantal); var array = {'artikelid':product_code,'product':product_naam,'aantal':product_aantal,'prijs':product_prijs,'image':product_image,'href':product_href,'artikel_identifier':product_identifier,'opmerking':product_opmerking,'entryid':entryID,'eenheid':product_eenheid,'afwijking':product_afwijking,'timestamp':timestamp}; if (product_prijs != 0){ 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','Some prices of products in your cart have been updatet',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(); } }); }); Number.prototype.toMoney_old = function(decPlaces) { if (decPlaces == null){ decPlaces = 0 } var n = this, decPlaces = decPlaces, decSeparator = ",", thouSeparator = ".", sign = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0)) + "", j = (j = i.length) > 3 ? j % 3 : 0, decimals = Number(Math.round(n +'e'+ decPlaces) +'e-'+ decPlaces).toFixed(decPlaces), result = sign + (j ? i.substr(0, j) + thouSeparator : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thouSeparator) + (decPlaces ? decSeparator + Math.abs(decimals-i).toFixed(decPlaces).slice(2) : ""); return result; }; Number.prototype.toMoney = function(decPlaces) { if (decPlaces == null){ decPlaces = 0 } var result = Math.round(parseFloat((this * Math.pow(10, decPlaces)).toFixed(13))) / Math.pow(10, decPlaces); result = result.toFixed(decPlaces); return result; }; ////////////