jQuery(function($) { if(window.location.href.indexOf('mx_add_kupon') !== -1 || window.location.href.indexOf('?mxz/') !== -1) { current_href = window.location.href.split('mx_add_kupon='); kupon = current_href[1]; $(document).ready(function() { if($('#promocodeshow').length) { $('#promocodeshow').click(); $('input[name="promocode"]').val(kupon); $('.promocode button[type="submit"]').click(); } else { console.log('MX - kod rabatowy jest już wpisany.'); } }); } if(window.location.href.indexOf('maxsote_zapisany_koszyk') !== -1 || window.location.href.indexOf('?mxz/') !== -1) { $('body').append('
loading...
'); } $(document).ready(function() { function modApiLoader() { if(!window.frontAPI) { setTimeout(modApiLoader,1); return } function add_to_basket_recursive(products,i,func_on_complete) { if(i>=products.length) { //koniec func_on_complete(); return; } product = products[i]; add_data = { stock_id: product.stock_id, quantity: product.quantity, }; console.log(product); if(product.variant) { add_data["options"] = {}; current_options = product.variant.split(';'); current_options_names = []; for(k in current_options) { option_string = current_options[k].trim().split(':'); option_name = option_string[0].trim(); option_value = option_string[1].trim(); current_options_names.push({ option_name: option_name, option_value: option_value, }); } frontAPI.getProduct(function (product_info) { option_value_id_array = {}; // console.log(product_info.options_configuration); for(k in product_info.options_configuration) { option = product_info.options_configuration[k]; for(k1 in current_options_names) { option_id = false; ovalue_id = false; //console.log(current_options_names[k1].option_name,option.name); if(current_options_names[k1].option_name == option.name) { option_id = option.id; if(option.type=='text') { ovalue_id = current_options_names[k1].option_value; } if(option.type=='checkbox') { if(current_options_names[k1].option_value == 'tak') { ovalue_id = true; } else if(current_options_names[k1].option_value == 'nie') { ovalue_id = false; } } else { for(k2 in option.values) { //console.log(current_options_names[k1].option_value,option.values[k2].name); if(current_options_names[k1].option_value == option.values[k2].name) { ovalue_id = option.values[k2].id; } // else if(current_options_names[k1].option_value == option.values[k2].name) // { // ovalue_id = option.values[k2].name; // } } } } //console.log(option_id,ovalue_id); if(option_id && ovalue_id) { add_data["options"][option_id] = ovalue_id; } } } // console.log('----------',add_data); frontAPI.addToBasket(function (addInfo) { add_to_basket_recursive(products,i+1,func_on_complete); }, { data: add_data }); }, { id: product.product_id }); } else { frontAPI.addToBasket(function (addInfo) { add_to_basket_recursive(products,i+1,func_on_complete); }, { data: add_data }); } } function remove_from_basket_recursive(products,i,func_on_complete) { if(i>=products.length) { //koniec func_on_complete(); return; } product = products[i]; frontAPI.removeFromBasket(function (removeInfo) { remove_from_basket_recursive(products,i+1,func_on_complete); }, { id: product.id }); } var current_lang = Shop.lang.name; if(window.location.href.indexOf('maxsote_zapisany_koszyk') !== -1 || window.location.href.indexOf('?mxz/') !== -1) { koszyk_id = 0; friendly_url = ''; if(window.location.href.indexOf('maxsote_zapisany_koszyk') !== -1) { current_href = window.location.href.split('maxsote_zapisany_koszyk='); current_href = current_href[1].split('&'); current_href = current_href[0]; koszyk_id = current_href.replace(/\D/g,''); } else { current_href = window.location.href.split('?mxz/'); current_href = current_href[1].split('&'); friendly_url = current_href[0]; } $.post('https://hotinfo.maxserver.pl/appZapiszKoszyk/pobierz_koszyk.php',{ koszyk_id: koszyk_id, friendly_url: friendly_url, shop_id: 94, },function(products_to_add) { if('error' in products_to_add) { $('.mx_body_preloader').html('Przepraszamy, coś poszło nie tak.'); setTimeout(function() { $('.mx_body_preloader').fadeOut(200); },1000); } frontAPI.getBasketInfo(function (basketInfo) { // console.log(basketInfo); remove_from_basket_recursive(basketInfo.products,0,function() { new_products = products_to_add['products']; add_to_basket_recursive(new_products,0,function() { $('.mx_body_preloader').fadeOut(1000); add_kupon = ''; kupon = products_to_add['kupon']; if(kupon.length > 0) { add_kupon = '?mx_add_kupon='+kupon; } window.location.href = '/'+current_lang+'/basket'+add_kupon; }); }); // console.log(products_to_add); }); }); } var active_link = 1; var active_csv = 0; if($('body').hasClass('shop_basket')) { var translations_array = '{"btn_link_text":{"__default":"Zapisz koszyk","pl_PL":"Zapisz koszyk"},"btn_csv_text":{"__default":"Pobierz koszyk w CSV","pl_PL":"Pobierz koszyk w CSV"}}'; translations_array = JSON.parse(translations_array); //todo zrobic cala klase do zarzadzania translacjami var container = $('
') if(active_link) { if(!(current_lang in translations_array['btn_link_text'])) { btn_link_translation = translations_array['btn_link_text']['__default']; } else { btn_link_translation = translations_array['btn_link_text'][current_lang]; } btn_link = $(''); btn_link.click(function() { container.find('.maxsote_div_loading').fadeIn(100); frontAPI.getBasketInfo(function(basket) { basket.shippings = {}; basket.countries = {}; $.post('https://hotinfo.maxserver.pl/appZapiszKoszyk/zapisz_koszyk.php?id=94',{ basket: basket },function(response) { koszyk_id = response; if(container.find('.maxsote_koszyk_link_input').length<1) { container.append($('
Link do koszyka:')); } maxsote_koszyk_link_input = container.find('.maxsote_koszyk_link_input'); current_href = window.location.href.split('/'); base_url = current_href[0]+'/'+current_href[1]+'/'+current_href[2]; if(current_lang != 'pl_PL') { base_url = base_url + '/' + current_lang +'/index'; } maxsote_koszyk_link_input.val(base_url+'?maxsote_zapisany_koszyk='+koszyk_id); maxsote_koszyk_link_input.unbind().focus(function() { $(this).select(); }); maxsote_koszyk_link_input.select(); container.find('.maxsote_div_loading').fadeOut(100); }); }); }); container.append(btn_link); } if(active_csv) { if(!(current_lang in translations_array['btn_csv_text'])) { btn_csv_translation = translations_array['btn_csv_text']['__default']; } else { btn_csv_translation = translations_array['btn_csv_text'][current_lang]; } btn_csv = $(''); btn_csv.click(function() { container.find('.maxsote_div_loading').fadeIn(100); frontAPI.getBasketInfo(function(basket) { var new_basket = { "p": [], }; for(k in basket.products) { cur_csv_prod = { 'n' : basket.products[k]['name'], 'p' : basket.products[k]['price_float'], 'q' : basket.products[k]['quantity'], 'u' : basket.products[k]['unit']['name'], 's' : basket.products[k]['sum_float'], 'v' : basket.products[k]['variant'], } new_basket["p"].push(cur_csv_prod); } var iframe = $('');//.css('display','none') iframe.prop('src','https://hotinfo.maxserver.pl/appZapiszKoszyk/koszyk_csv.php?'+$.param(new_basket)); iframe.appendTo($('body')); container.find('.maxsote_div_loading').fadeOut(100); }); }); container.append(btn_csv); } container.append($('
loading...
').css('display','none')); if(true) { container.appendTo($('#tm_box_basketlist')); } else { container.insertAfter($('.productlist')); } } } modApiLoader(); }); });