jQuery(function($) { function APIloader() { if(!window.frontAPI) { setTimeout(APIloader,0); } else { var hotbasket_config = {"id":"343","0":"343","shop_id":"918134ab0b8bf8200ed969e85402baf721d57a9a","1":"918134ab0b8bf8200ed969e85402baf721d57a9a","active":"1","2":"1","border":"0","3":"0","border_thickness":"1","4":"1","border_color":"#000000","5":"#000000","font_color":"#000000","6":"#000000","font_size":"15","7":"15","custom_container":"","8":"","date_modified":"2022-12-28 13:16:02","9":"2022-12-28 13:16:02"}; var hotbasket_products = [{"id":"1590","0":"1590","shop_id":"918134ab0b8bf8200ed969e85402baf721d57a9a","1":"918134ab0b8bf8200ed969e85402baf721d57a9a","active":"1","2":"1","shoper_product_id":"522","3":"522","shoper_product_name":"PAKOWANIE EKO","4":"PAKOWANIE EKO","shoper_category_id":"0","5":"0","shoper_category_name":"","6":"","limit_category":"0","7":"0","hbprod_title":"Jestem EKO","8":"Jestem EKO","hbprod_description":"Bielizn\u0119 zapakujemy w duchu eko - bez plastiku, wykorzystuj\u0105c br\u0105zowy karton i bibu\u0142\u0119.","9":"Bielizn\u0119 zapakujemy w duchu eko - bez plastiku, wykorzystuj\u0105c br\u0105zowy karton i bibu\u0142\u0119.","hbprod_tooltip":"","10":"","hbprod_icon":"<\/i>","11":"<\/i>","default_checked":"0","12":"0","date_modified":"2022-12-28 13:18:15","13":"2022-12-28 13:18:15"},{"id":"1592","0":"1592","shop_id":"918134ab0b8bf8200ed969e85402baf721d57a9a","1":"918134ab0b8bf8200ed969e85402baf721d57a9a","active":"1","2":"1","shoper_product_id":"352","3":"352","shoper_product_name":"PAKOWANIE NA PREZENT","4":"PAKOWANIE NA PREZENT","shoper_category_id":"0","5":"0","shoper_category_name":"","6":"","limit_category":"0","7":"0","hbprod_title":"Prezent","8":"Prezent","hbprod_description":"Bielizn\u0119 dostarczymy w eleganckim, czarnym pude\u0142ku ozdobionym wst\u0105\u017ck\u0105. Gotow\u0105 do wr\u0119czenia na prezent.","9":"Bielizn\u0119 dostarczymy w eleganckim, czarnym pude\u0142ku ozdobionym wst\u0105\u017ck\u0105. Gotow\u0105 do wr\u0119czenia na prezent.","hbprod_tooltip":"","10":"","hbprod_icon":"<\/i>","11":"<\/i>","default_checked":"0","12":"0","date_modified":"2022-12-28 13:21:51","13":"2022-12-28 13:21:51"},{"id":"2652","0":"2652","shop_id":"918134ab0b8bf8200ed969e85402baf721d57a9a","1":"918134ab0b8bf8200ed969e85402baf721d57a9a","active":"1","2":"1","shoper_product_id":"605","3":"605","shoper_product_name":"Li\u015bcik","4":"Li\u015bcik","shoper_category_id":"0","5":"0","shoper_category_name":"","6":"","limit_category":"0","7":"0","hbprod_title":"Li\u015bcik","8":"Li\u015bcik","hbprod_description":"Do pude\u0142ka do\u0142\u0105czymy kr\u00f3tki li\u015bcik z wiadomo\u015bci\u0105 od Ciebie. Prosimy umie\u015bci\u0107 jej tre\u015b\u0107 w komentarzu do zam\u00f3wienia (w kolejnym etapie koszyka).","9":"Do pude\u0142ka do\u0142\u0105czymy kr\u00f3tki li\u015bcik z wiadomo\u015bci\u0105 od Ciebie. Prosimy umie\u015bci\u0107 jej tre\u015b\u0107 w komentarzu do zam\u00f3wienia (w kolejnym etapie koszyka).","hbprod_tooltip":"","10":"","hbprod_icon":"<\/i>","11":"<\/i>","default_checked":"0","12":"0","date_modified":"2024-10-14 22:23:28","13":"2024-10-14 22:23:28"}]; //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(); });