jQuery(function($) { function APIloader() { if(!window.frontAPI) { setTimeout(APIloader,0); } else { var hotbasket_config = {"id":"288","0":"288","shop_id":"5f2df379a0412e1164dab46f2f9e822ad302bb8b","1":"5f2df379a0412e1164dab46f2f9e822ad302bb8b","active":"1","2":"1","border":"1","3":"1","border_thickness":"3","4":"3","border_color":"#e6dbc7","5":"#e6dbc7","font_color":"#000000","6":"#000000","font_size":"0","7":"0","custom_container":"","8":"","date_modified":"2022-03-11 13:16:44","9":"2022-03-11 13:16:44"}; var hotbasket_products = [{"id":"1190","0":"1190","shop_id":"5f2df379a0412e1164dab46f2f9e822ad302bb8b","1":"5f2df379a0412e1164dab46f2f9e822ad302bb8b","active":"1","2":"1","shoper_product_id":"38898","3":"38898","shoper_product_name":"Ozdobny celofan + wst\u0105\u017cka","4":"Ozdobny celofan + wst\u0105\u017cka","shoper_category_id":"0","5":"0","shoper_category_name":"","6":"","limit_category":"0","7":"0","hbprod_title":"Pakowanie w ozdobny celofan i wst\u0105\u017ck\u0119 (us\u0142uga dodatkowo p\u0142atna +6z\u0142)","8":"Pakowanie w ozdobny celofan i wst\u0105\u017ck\u0119 (us\u0142uga dodatkowo p\u0142atna +6z\u0142)","hbprod_description":"Po wybraniu tej opcji, produkty kt\u00f3re wska\u017cesz w polu \"Uwagi\" lub wszystkie zam\u00f3wione w przypadku braku informacji zostan\u0105 zapakowane w ozdobny celofan i przewi\u0105zane wst\u0105\u017ck\u0105. \r\nWA\u017bNE: Wszystkie kosze prezentowe s\u0105 zawsze pakowane w celofan.","9":"Po wybraniu tej opcji, produkty kt\u00f3re wska\u017cesz w polu \"Uwagi\" lub wszystkie zam\u00f3wione w przypadku braku informacji zostan\u0105 zapakowane w ozdobny celofan i przewi\u0105zane wst\u0105\u017ck\u0105. \r\nWA\u017bNE: Wszystkie kosze prezentowe s\u0105 zawsze pakowane w celofan.","hbprod_tooltip":"","10":"","hbprod_icon":"<\/i>","11":"<\/i>","default_checked":"0","12":"0","date_modified":"2022-03-11 13:19:44","13":"2022-03-11 13:19:44"},{"id":"1191","0":"1191","shop_id":"5f2df379a0412e1164dab46f2f9e822ad302bb8b","1":"5f2df379a0412e1164dab46f2f9e822ad302bb8b","active":"1","2":"1","shoper_product_id":"39107","3":"39107","shoper_product_name":"Bilecik okazjonalny","4":"Bilecik okazjonalny","shoper_category_id":"0","5":"0","shoper_category_name":"","6":"","limit_category":"0","7":"0","hbprod_title":"Bilecik okazjonalny z \u017cyczeniami (dodatkowo p\u0142atne +1,50z\u0142)","8":"Bilecik okazjonalny z \u017cyczeniami (dodatkowo p\u0142atne +1,50z\u0142)","hbprod_description":"\u017byczenia podaj nam w polu \"Uwagi\" podczas sk\u0142adania zam\u00f3wienia. ","9":"\u017byczenia podaj nam w polu \"Uwagi\" podczas sk\u0142adania zam\u00f3wienia. ","hbprod_tooltip":"","10":"","hbprod_icon":"<\/i>","11":"<\/i>","default_checked":"0","12":"0","date_modified":"2022-03-11 14:46:20","13":"2022-03-11 14:46:20"},{"id":"1228","0":"1228","shop_id":"5f2df379a0412e1164dab46f2f9e822ad302bb8b","1":"5f2df379a0412e1164dab46f2f9e822ad302bb8b","active":"0","2":"0","shoper_product_id":"38968","3":"38968","shoper_product_name":"Wk\u0142ad ch\u0142odz\u0105cy","4":"Wk\u0142ad ch\u0142odz\u0105cy","shoper_category_id":"0","5":"0","shoper_category_name":"","6":"","limit_category":"0","7":"0","hbprod_title":"\u017belowy wk\u0142ad ch\u0142odz\u0105cy (dodatkowo p\u0142atne +3,99z\u0142)","8":"\u017belowy wk\u0142ad ch\u0142odz\u0105cy (dodatkowo p\u0142atne +3,99z\u0142)","hbprod_description":"Po wybraniu tej opcji, to Twojego zam\u00f3wienia zostanie do\u0142o\u017cony wk\u0142ad ch\u0142odz\u0105cy, kt\u00f3ry zapewni bezpieczn\u0105 podr\u00f3\u017c w upalne dni.","9":"Po wybraniu tej opcji, to Twojego zam\u00f3wienia zostanie do\u0142o\u017cony wk\u0142ad ch\u0142odz\u0105cy, kt\u00f3ry zapewni bezpieczn\u0105 podr\u00f3\u017c w upalne dni.","hbprod_tooltip":"","10":"","hbprod_icon":"<\/i>","11":"<\/i>","default_checked":"0","12":"0","date_modified":"2022-05-11 10:49:27","13":"2022-05-11 10:49:27"}]; //przygotowanie zmiennych konfiguracyjnych var active = null; var border = null; var border_thickness = null; var border_color = null; var font_color = null; var font_size = null; var custom_container = null; var default_checked = null; $.each(hotbasket_config, function(index, value){ //each po tablicy z konfiguracja if(index == 'active')active=value; if(index == 'border')border=value; if(index == 'border_thickness')border_thickness=value; if(index == 'border_color')border_color=value; if(index == 'font_color')font_color=value; if(index == 'font_size')font_size=value; if(index == 'custom_container')custom_container=value; }); if(active == 1 && $('body').hasClass('shop_basket')){ //jesli dodatek jest wlaczony oraz skrypt znajduje sie w koszyku //tworzenie elementów hotbasket i ustawienie podstawowej konfiguracji $.each(hotbasket_products, function(index, value){ //each po tablicy z produktami hotbasket var active_product = parseInt(value['active']); var product_id = parseInt(value['shoper_product_id']); var default_checked = parseInt(value['default_checked']); if(active_product){ //jesli produkt jest aktywny //pobieranie informacji o produkcie z API var product = frontAPI.getProduct({ id: product_id }); if(!product['name']){ console.log("Maxsote Hotbasket Error - Product not found, ERROR CODE: PID"+product_id); }else{ var product_price = product['price']['gross']['final']; var shoper_product_name = product['name']; //tworzenie elementu var hotbasket_element = $('
').attr( { 'data-name': "maxsote_hotbasket" }).css( { "width": "100%", "padding": "10px 0", "margin": "10px 0", "color": font_color, "font-size": font_size+"pt", "position" : "static", "box-sizing" : "initial", "display" : "flex", "align-items" : "center" } ); //czekanie na soobasket, jesli istnieje if(typeof GlobalSoolutionSoobasket != 'undefined'){ shoper.addEvent("soobasket:loaded", function(event, basket){ hotbasket_element.insertAfter(".el-table__body"); }); } //ustalenie pozycji hotbasket if(custom_container!=="" || custom_container!=false){ //jesli jest ustalony custom container hotbasket_element.appendTo(custom_container); }else{ hotbasket_element.insertAfter("table.productlist"); } //sprawdzenie czy jest limit do kategorii if(value['shoper_category_id']!=0){ hotbasket_element.attr('data-limit_category', value['shoper_category_id']); } //uzupelnianie hotbasket trescia if($.trim(value['hbprod_icon']) != ""){ $("
").html(value['hbprod_icon']).appendTo(hotbasket_element); } $("
").appendTo(hotbasket_element); var hotbasket_kaprow = hotbasket_element.find(".kap_row"); $("
").appendTo(hotbasket_kaprow); var hotbasket_kaprow_upper = hotbasket_kaprow.find(".kr_upper"); $("").appendTo(hotbasket_kaprow_upper); var hotbasket_kaprow_cwrap = hotbasket_kaprow_upper.find(".checkbox-wrap"); var additional_product_id = product_id; var checked = ""; var disabled = "" $(".productlist tbody tr").each(function(){ var basket_product_id = $(this).data("product-id"); if(parseInt(additional_product_id) == parseInt(basket_product_id)){ checked = "checked='checked'"; } if(default_checked==1){ checked = "checked='checked'"; disabled = "disabled"; } }); $("").appendTo(hotbasket_kaprow_cwrap); $("").appendTo(hotbasket_kaprow_cwrap); $("").appendTo(hotbasket_kaprow_upper); var hotbasket_kaprow_desc = hotbasket_kaprow_upper.find(".desc"); //sprawdzanie czy jest wpisana nazwa produktu if($.trim(value['hbprod_title'])!==""){ $("").html(value['hbprod_title']).appendTo(hotbasket_kaprow_desc); }else{ $("").html(shoper_product_name).appendTo(hotbasket_kaprow_desc); } $("").text(product_price).appendTo(hotbasket_kaprow_upper); if($.trim(value['hbprod_description'])!=""){ $("
").appendTo(hotbasket_kaprow); var hotbasket_kaprow_lower = hotbasket_kaprow.find(".kr_lower"); $("
").appendTo(hotbasket_kaprow_lower).text(value['hbprod_description']); } //dodanie elementu do html if(custom_container!=="" || custom_container!=false){ //jesli jest ustalony custom container hotbasket_element.appendTo(custom_container); }else{ hotbasket_element.insertAfter("table.productlist"); } } } // end if active product }); //sprawdzenie czy dodatek ma mieć obramowanie i inne cssy if(border==1){ $(".maxsote_hotbasket").css("border","1px solid "+border_color); if(border_thickness){ border_thickness = parseInt(border_thickness); $(".maxsote_hotbasket").css("border-width",border_thickness+"px"); } } $(".kap_icon").css({ "padding" : "10px 15px", "padding-right" : "0px", "display" : "inline-block", "float" : "left", "font-family": "fontAwesome", "font-size" : "25pt", "min-width" : "60px", "text-align" : "center", "vertical-align" : "middle" }); $(".kap_row").css({ "vertical-align":"middle", "padding": "10px 20px", "display": "inline-block", "vertical-align": "middle" }); $(".kap_icon i").css("font-style","normal").addClass("fa"); $(".kap_price").css({ "font-weight":"bold", "margin-left":"10px" }); $(".kap_description").css({ "margin": "10px 0px", "font-size": "10pt" }); $(".maxsote_hotbasket .desc").css({ "margin-left" : "5px" }); //obsluga zaznaczenia wybranej opcji i ukrycia w tabeli function check_hotbasket_products(){ //pobieram info o produktach w koszyku let basket_info = frontAPI.getBasketInfo({ lang: 'pl_PL', currency: 'PLN' }); let current_basket_prod_ids = []; let need_to_refresh = false; $.each(basket_info['products'],function(key, value) { console.log(value['product_id']); var product = frontAPI.getProduct({ id: value['product_id'] }); var stock_id = product.stockId; current_basket_prod_ids[value['product_id']] = stock_id; }); //sprawdzam wszystkie produkty hotbasket $(".k_additional_product").each(function(){ let additional_product_id = $(this).data('product_id'); var checked = $(this).is(":checked"); if(checked == true){ if (!(additional_product_id in current_basket_prod_ids)) { var product = frontAPI.getProduct({ id: additional_product_id }); var stock_id = product.stockId; var addInfo = frontAPI.addToBasket({ lang: 'pl_PL', // optional currency: 'PLN', // optional data: { stock_id: stock_id, quantity: 1 } }); if (typeof addInfo === 'undefined') { console.log("nieprawidlowy produkt hotbasket"); } need_to_refresh = true; } }else{ if (additional_product_id in current_basket_prod_ids) { var current_product_id = $(this).data("product_id"); //id produktu (dodatek) var basket = frontAPI.getBasketInfo({ }); var basket_products = basket['products']; var basket_product_id = null; $.each(basket_products,function(key, value) { product_id = value['product_id']; if(product_id == current_product_id){ //znalazlem ten produkt dodatkowy w koszyku basket_product_id = value['id']; } }); if(basket_product_id){ var removeInfo = frontAPI.removeFromBasket({ id: basket_product_id }); need_to_refresh= true; } } } }); if(need_to_refresh){ location.reload(); } } check_hotbasket_products(); //obsluga zmiany $(document).ready(function() { $(".k_additional_product").change(function() { check_hotbasket_products(); }); }); } //end if enabled } } APIloader(); });