//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 deze_leverancier = deze.data('leverancier_id');
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_leverancier];
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_leveranciers_info(leverancier){
var returnedArray = [];
return returnedArray;
}
var leveranciers_ar = {"1":{"leverancierID":"1","leveranciers":"Varossieau\/PPG","leveranciers_basename":"varossieau","prijs_drempel":"3000.00","bezorg_tarief":"150.00","active":"1"},"2":{"leverancierID":"2","leveranciers":"kuldipsingh","leveranciers_basename":"kuldipsingh","prijs_drempel":"1000.00","bezorg_tarief":"350.00","active":"1"},"3":{"leverancierID":"3","leveranciers":"BEM","leveranciers_basename":"bem","prijs_drempel":"0.00","bezorg_tarief":"0.00","active":"1"},"4":{"leverancierID":"4","leveranciers":"VABI","leveranciers_basename":"vabi","prijs_drempel":"0.00","bezorg_tarief":"0.00","active":"1"},"5":{"leverancierID":"5","leveranciers":"82 Trading","leveranciers_basename":"82-trading","prijs_drempel":"0.00","bezorg_tarief":"0.00","active":"1"},"6":{"leverancierID":"6","leveranciers":"DETO","leveranciers_basename":"deto","prijs_drempel":"0.00","bezorg_tarief":"0.00","active":"1"},"7":{"leverancierID":"7","leveranciers":"Fernandes Technical","leveranciers_basename":"fernandes-technical","prijs_drempel":"0.00","bezorg_tarief":"0.00","active":"1"},"8":{"leverancierID":"8","leveranciers":"ARGOS","leveranciers_basename":"argos","prijs_drempel":"0.00","bezorg_tarief":"0.00","active":"1"},"9":{"leverancierID":"9","leveranciers":"test weblocher","leveranciers_basename":"test-weblocher","prijs_drempel":"0.00","bezorg_tarief":"0.00","active":"1"},"10":{"leverancierID":"10","leveranciers":"test weblocher","leveranciers_basename":"test-weblocher-1","prijs_drempel":"0.00","bezorg_tarief":"0.00","active":"1"},"11":{"leverancierID":"11","leveranciers":"Houtmarkt Kwatta","leveranciers_basename":"houtmarkt-kwatta","prijs_drempel":"0.00","bezorg_tarief":"0.00","active":"1"}};console.log(leveranciers_ar);
function get_items_from_local_storage(focus){
//alert('get itmes')
//alert(drempel_varossieau + tarief_varossieau);
var display_aantal = 0;
var totaal_prijs = 0;
$('.wl_shop_row').remove();
//var tr_mail = "
product | aantal | prijs SRD | totaal |
";
var tr_mail = "";
tr_mail = "";
$('#contact_iframe').contents().find('#winkelmanditems_html').val(tr_mail);
//$('.temp_mailbox').html('');
//$('.temp_mailbox').append(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);
deze.closest('tr').hide(1000);
deze.closest('tr').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];
var prod_leverancier = retrieved_array[9];
//alert('aantal= '+product_aantal);
var array = [product_code,product_naam,product_aantal,product_prijs,product_image,product_href,product_identifier,product_opmerking,entryID,prod_leverancier];
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').data('prijs');
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_old(2)).attr('data-prijs',nieuwe_berekende_totaal_prijs);
$('.totaal_product').each(function() {
var dit = $(this);
var waarde = dit.attr('data-prijs') * 1;
console.log(waarde);
totaal_prijs = totaal_prijs + waarde;
});
console.log('wl_shop_total_price: '+totaal_prijs);
$('.wl_shop_total_price').html(totaal_prijs.toMoney_old(2));
//deze.focus();
if (deze_waarde == ''){
deze.addClass('wl_shop_aantal_leeg');
}else{
deze.removeClass('wl_shop_aantal_leeg');
}
});
$(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();
//temp_test();
});
$(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];
var prod_leverancier = retrieved_array[9];
//alert('aantal= '+product_aantal);
var array = [product_code,product_naam,product_aantal,product_prijs,product_image,product_href,product_identifier,product_opmerking,entryID,prod_leverancier];
localStorage.setItem(detail[0], JSON.stringify(array));
if (old_prijs != product_prijs){
console.log("product_code: "+product_code+" old_prijs: "+old_prijs+" new 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();
}
});
});
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;
};
////////////