// let mx_mod_basket_refresh = function (basket){}; jQuery(function($) { let mx_predefined_days = {"predefined_free_days":"2024-04-01,2024-03-31"}; let mx_days_tab = {"monday":"1","tuesday":"1","wednesday":"1","thursday":"1","friday":"1","saturday":"1","sunday":"1"}; function getTranslation(var_name,current_lang=Shop.lang.name){ if(!(current_lang in translations_array[var_name])){ translation = translations_array[var_name]['__default']; }else{ translation = translations_array[var_name][current_lang]; } return translation; } $(document).ready(function(){ function APIloader () { if (!window.frontAPI) { setTimeout(APIloader, 0); } else { let basket_quantity = frontAPI.getBasketInfo({}).basket.count; if (basket_quantity == 0) { console.log('klgklsdf'); localStorage.removeItem('mx_chosen_date'); } let mx_canceled_days = []; // console.log(mx_days_tab, basket_quantity); for(mx_day in mx_days_tab) { if(mx_days_tab[mx_day] == 0) { let mx_day_val = 0; if (mx_day == 'monday') { mx_day_val = 1; } else if(mx_day == 'tuesday') { mx_day_val = 2; } else if(mx_day == 'wednesday') { mx_day_val = 3; } else if(mx_day == 'thursday') { mx_day_val = 4; } else if(mx_day == 'friday') { mx_day_val = 5; } else if(mx_day == 'saturday') { mx_day_val = 6; } else if(mx_day == 'sunday') { mx_day_val = 0; } mx_canceled_days.push(mx_day_val); } } console.log(mx_canceled_days); if ($('body').hasClass('shop_product')) { let mx_prod_id = $('input[name=product_id]').val(); let mx_product_category_id = frontAPI.getProduct({id: mx_prod_id}).category.id; let mx_product_category = frontAPI.getProduct({id: mx_prod_id}).category.name; let mx_product_attribute = frontAPI.getProduct({id: mx_prod_id}).attributes; let mx_predefined_arr = []; for(mx_id in mx_product_attribute) { if (mx_product_attribute[mx_id].name == 'Minimalny czas odbioru') { mx_product_attribute = mx_product_attribute[mx_id].value; } } mx_predefined_arr = mx_predefined_days['predefined_free_days'].split(','); var i = 0; while(i < mx_product_attribute) { var d = new Date(); d.setDate(d.getDate() + i); var month = d.getMonth()+1; var day = d.getDate(); var output = d.getFullYear() + '-' + ((''+month).length<2 ? '0' : '') + month + '-' + ((''+day).length<2 ? '0' : '') + day; mx_predefined_arr.push(output); i++; } console.log(mx_product_category); if (mx_product_category_id == 16 || mx_product_category_id == 17 || mx_product_category_id == 18 || mx_product_category_id == 19) { $('.addtobasket').addClass('mx_disable_btn'); $('.stocks select').on('change', function() { if (!$('#datepicker').val()) { setTimeout(function() { $('.addtobasket').addClass('mx_disable_btn'); }, 250); } }); console.log(mx_canceled_days, '1231231'); $('.form-basket').before('
Data odbioru:
'); $('#box_productfull').after('
') $('body').on('change', '#datepicker', function() { $('.addtobasket').removeClass('mx_disable_btn'); }) $('.button_wrap').on('click', function() { if ($(this).children('button').hasClass('mx_disable_btn') || !$('#datepicker').val()) { $('.mx_cdd_calendar').addClass('mx_make_up'); $('.mx_mask, .mx_modal').show(); } }) $('.mx_modal .btn.btn-red').on('click', function() { $('.mx_modal, .mx_mask').hide(); }) $('.addtobasket').on('click', function() { if (!localStorage.getItem("mx_chosen_date")) { localStorage.setItem("mx_chosen_date", $('#datepicker').val()); localStorage.setItem("mx_highest_dateblock_val", mx_product_attribute); } else { if(localStorage.getItem("mx_highest_dateblock_val") >= mx_product_attribute) { localStorage.setItem("mx_chosen_date", $('#datepicker').val()); localStorage.setItem("mx_highest_dateblock_val", mx_product_attribute); } else { alert('Wybrana data jest nieosiągalna ze względu na inne produkty w koszyku.'); } } }) $.datepicker.regional.pl = { closeText: "Zamknij", prevText: "<Poprzedni", nextText: "Następny>", currentText: "Dziś", monthNames: [ "Styczeń", "Luty", "Marzec", "Kwiecień", "Maj", "Czerwiec", "Lipiec", "Sierpień", "Wrzesień", "Październik", "Listopad", "Grudzień" ], monthNamesShort: [ "Sty", "Lu", "Mar", "Kw", "Maj", "Cze", "Lip", "Sie", "Wrz", "Pa", "Lis", "Gru" ], dayNames: [ "Niedziela", "Poniedziałek", "Wtorek", "Środa", "Czwartek", "Piątek", "Sobota" ], dayNamesShort: [ "Nie", "Pn", "Wt", "Śr", "Czw", "Pt", "So" ], dayNamesMin: [ "N", "Pn", "Wt", "Śr", "Cz", "Pt", "So" ], weekHeader: "Tydz", dateFormat: "dd.mm.yy", firstDay: 1, isRTL: false, showMonthAfterYear: false, yearSuffix: "" }; $.datepicker.setDefaults( $.datepicker.regional[ "pl" ] ); if (mx_canceled_days.length == 1) { $( "#datepicker" ).datepicker({ dateFormat: 'yy MM dd', showOn: "button", minDate: d, buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif", beforeShowDay: function(date) { var string = jQuery.datepicker.formatDate('yy-mm-dd', date); var mx_day = date.getDay(); return [(mx_day != mx_canceled_days[0] && mx_day != mx_canceled_days[1]) && mx_predefined_arr.indexOf(string) == -1]; } }); } else if(mx_canceled_days.length == 2) { $( "#datepicker" ).datepicker({ dateFormat: 'yy MM dd', showOn: "button", minDate: d, buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif", // buttonImageOnly: true, beforeShowDay: function(date) { var string = jQuery.datepicker.formatDate('yy-mm-dd', date); var mx_day = date.getDay(); return [(mx_day != mx_canceled_days[0] && mx_day != mx_canceled_days[1]) && mx_predefined_arr.indexOf(string) == -1]; } }); } else if(mx_canceled_days.length == 3) { $( "#datepicker" ).datepicker({ dateFormat: 'yy MM dd', showOn: "button", minDate: d, buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif", buttonImageOnly: true, beforeShowDay: function(date) { var string = jQuery.datepicker.formatDate('yy-mm-dd', date); var mx_day = date.getDay(); return [(mx_day != mx_canceled_days[0] && mx_day != mx_canceled_days[1] && mx_day != mx_canceled_days[2]) && mx_predefined_arr.indexOf(string) == -1]; } }); } else if(mx_canceled_days.length == 4) { $( "#datepicker" ).datepicker({ dateFormat: 'yy MM dd', showOn: "button", minDate: d, buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif", buttonImageOnly: true, beforeShowDay: function(date) { var string = jQuery.datepicker.formatDate('yy-mm-dd', date); var mx_day = date.getDay(); return [(mx_day != mx_canceled_days[0] && mx_day != mx_canceled_days[1] && mx_day != mx_canceled_days[2] && mx_day != mx_canceled_days[3]) && mx_predefined_arr.indexOf(string) == -1]; } }); } else if(mx_canceled_days.length == 5) { $( "#datepicker" ).datepicker({ dateFormat: 'yy MM dd', showOn: "button", minDate: d, buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif", buttonImageOnly: true, beforeShowDay: function(date) { var string = jQuery.datepicker.formatDate('yy-mm-dd', date); var mx_day = date.getDay(); return [(mx_day != mx_canceled_days[0] && mx_day != mx_canceled_days[1] && mx_day != mx_canceled_days[2] && mx_day != mx_canceled_days[3] && mx_day != mx_canceled_days[4]) && mx_predefined_arr.indexOf(string) == -1]; } }); } else if(mx_canceled_days.length == 6) { $( "#datepicker" ).datepicker({ dateFormat: 'yy MM dd', showOn: "button", minDate: d, buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif", buttonImageOnly: true, beforeShowDay: function(date) { var string = jQuery.datepicker.formatDate('yy-mm-dd', date); var mx_day = date.getDay(); return [(mx_day != mx_canceled_days[0] && mx_day != mx_canceled_days[1] && mx_day != mx_canceled_days[2] && mx_day != mx_canceled_days[3] && mx_day != mx_canceled_days[4] && mx_day != mx_canceled_days[5]) && mx_predefined_arr.indexOf(string) == -1]; } }); } else if(mx_canceled_days.length == 7) { $( "#datepicker" ).datepicker({ dateFormat: 'yy MM dd', showOn: "button", minDate: d, buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif", buttonImageOnly: true, beforeShowDay: function(date) { var string = jQuery.datepicker.formatDate('yy-mm-dd', date); var mx_day = date.getDay(); return [(mx_day != mx_canceled_days[0] && mx_day != mx_canceled_days[1] && mx_day != mx_canceled_days[2] && mx_day != mx_canceled_days[3] && mx_day != mx_canceled_days[4] && mx_day != mx_canceled_days[5] && mx_day != mx_canceled_days[6]) && mx_predefined_arr.indexOf(string) == -1]; } }); } else if(mx_canceled_days.length == 0 && mx_predefined_arr == 0) { $( "#datepicker" ).datepicker({ dateFormat: 'yy MM dd', showOn: "button", minDate: d, buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif", buttonImageOnly: true }); } else if(mx_canceled_days.length == 0) { $( "#datepicker" ).datepicker({ dateFormat: 'yy MM dd', showOn: "button", minDate: d, buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif", buttonImageOnly: true, beforeShowDay: function(date) { var string = jQuery.datepicker.formatDate('yy-mm-dd', date); var mx_day = date.getDay(); return [mx_predefined_arr.indexOf(string) == -1]; } }); } // $( "#datepicker" ).datepicker({ // beforeShowDay: noMondays // }); } } else if($('body').hasClass('shop_basket')) { if (localStorage.getItem("mx_chosen_date")) { let mx_chosen_date = localStorage.getItem("mx_chosen_date"); let mx_predefined_arr = []; mx_predefined_arr = mx_predefined_days['predefined_free_days'].split(','); var i = 0; while(i < localStorage.getItem("mx_highest_dateblock_val")) { var d = new Date(); var month = d.getMonth()+1; var day = d.getDate() + i; var output = d.getFullYear() + '-' + ((''+month).length<2 ? '0' : '') + month + '-' + ((''+day).length<2 ? '0' : '') + day; mx_predefined_arr.push(output); i++; } $('.summary-container').after('
Wybrana data dostawy
'); $('#datepicker').val(mx_chosen_date); $.datepicker.regional.pl = { closeText: "Zamknij", prevText: "<Poprzedni", nextText: "Następny>", currentText: "Dziś", monthNames: [ "Styczeń", "Luty", "Marzec", "Kwiecień", "Maj", "Czerwiec", "Lipiec", "Sierpień", "Wrzesień", "Październik", "Listopad", "Grudzień" ], monthNamesShort: [ "Sty", "Lu", "Mar", "Kw", "Maj", "Cze", "Lip", "Sie", "Wrz", "Pa", "Lis", "Gru" ], dayNames: [ "Niedziela", "Poniedziałek", "Wtorek", "Środa", "Czwartek", "Piątek", "Sobota" ], dayNamesShort: [ "Nie", "Pn", "Wt", "Śr", "Czw", "Pt", "So" ], dayNamesMin: [ "N", "Pn", "Wt", "Śr", "Cz", "Pt", "So" ], weekHeader: "Tydz", dateFormat: "dd.mm.yy", firstDay: 1, isRTL: false, showMonthAfterYear: false, yearSuffix: "" }; $.datepicker.setDefaults( $.datepicker.regional[ "pl" ] ); if (mx_canceled_days.length == 1) { $( "#datepicker" ).datepicker({ dateFormat: 'yy MM dd', showOn: "button", minDate: d, buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif", beforeShowDay: function(date) { var string = jQuery.datepicker.formatDate('yy-mm-dd', date); var mx_day = date.getDay(); return [(mx_day != mx_canceled_days[0] && mx_day != mx_canceled_days[1]) && mx_predefined_arr.indexOf(string) == -1]; } }); } else if(mx_canceled_days.length == 2) { $( "#datepicker" ).datepicker({ dateFormat: 'yy MM dd', showOn: "button", minDate: d, buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif", // buttonImageOnly: true, beforeShowDay: function(date) { var string = jQuery.datepicker.formatDate('yy-mm-dd', date); var mx_day = date.getDay(); return [(mx_day != mx_canceled_days[0] && mx_day != mx_canceled_days[1]) && mx_predefined_arr.indexOf(string) == -1]; } }); } else if(mx_canceled_days.length == 3) { $( "#datepicker" ).datepicker({ dateFormat: 'yy MM dd', showOn: "button", minDate: d, buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif", buttonImageOnly: true, beforeShowDay: function(date) { var string = jQuery.datepicker.formatDate('yy-mm-dd', date); var mx_day = date.getDay(); return [(mx_day != mx_canceled_days[0] && mx_day != mx_canceled_days[1] && mx_day != mx_canceled_days[2]) && mx_predefined_arr.indexOf(string) == -1]; } }); } else if(mx_canceled_days.length == 4) { $( "#datepicker" ).datepicker({ dateFormat: 'yy MM dd', showOn: "button", minDate: d, buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif", buttonImageOnly: true, beforeShowDay: function(date) { var string = jQuery.datepicker.formatDate('yy-mm-dd', date); var mx_day = date.getDay(); return [(mx_day != mx_canceled_days[0] && mx_day != mx_canceled_days[1] && mx_day != mx_canceled_days[2] && mx_day != mx_canceled_days[3]) && mx_predefined_arr.indexOf(string) == -1]; } }); } else if(mx_canceled_days.length == 5) { $( "#datepicker" ).datepicker({ dateFormat: 'yy MM dd', showOn: "button", minDate: d, buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif", buttonImageOnly: true, beforeShowDay: function(date) { var string = jQuery.datepicker.formatDate('yy-mm-dd', date); var mx_day = date.getDay(); return [(mx_day != mx_canceled_days[0] && mx_day != mx_canceled_days[1] && mx_day != mx_canceled_days[2] && mx_day != mx_canceled_days[3] && mx_day != mx_canceled_days[4]) && mx_predefined_arr.indexOf(string) == -1]; } }); } else if(mx_canceled_days.length == 6) { $( "#datepicker" ).datepicker({ dateFormat: 'yy MM dd', showOn: "button", minDate: d, buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif", buttonImageOnly: true, beforeShowDay: function(date) { var string = jQuery.datepicker.formatDate('yy-mm-dd', date); var mx_day = date.getDay(); return [(mx_day != mx_canceled_days[0] && mx_day != mx_canceled_days[1] && mx_day != mx_canceled_days[2] && mx_day != mx_canceled_days[3] && mx_day != mx_canceled_days[4] && mx_day != mx_canceled_days[5]) && mx_predefined_arr.indexOf(string) == -1]; } }); } else if(mx_canceled_days.length == 7) { $( "#datepicker" ).datepicker({ dateFormat: 'yy MM dd', showOn: "button", minDate: d, buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif", buttonImageOnly: true, beforeShowDay: function(date) { var string = jQuery.datepicker.formatDate('yy-mm-dd', date); var mx_day = date.getDay(); return [(mx_day != mx_canceled_days[0] && mx_day != mx_canceled_days[1] && mx_day != mx_canceled_days[2] && mx_day != mx_canceled_days[3] && mx_day != mx_canceled_days[4] && mx_day != mx_canceled_days[5] && mx_day != mx_canceled_days[6]) && mx_predefined_arr.indexOf(string) == -1]; } }); } else if(mx_canceled_days.length == 0 && mx_predefined_arr == 0) { $( "#datepicker" ).datepicker({ dateFormat: 'yy MM dd', showOn: "button", minDate: d, buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif", buttonImageOnly: true }); } else if(mx_canceled_days.length == 0) { $( "#datepicker" ).datepicker({ dateFormat: 'yy MM dd', showOn: "button", minDate: d, buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif", buttonImageOnly: true, beforeShowDay: function(date) { var string = jQuery.datepicker.formatDate('yy-mm-dd', date); var mx_day = date.getDay(); return [mx_predefined_arr.indexOf(string) == -1]; } }); } } } else if($('body').hasClass('shop_basket_address')) { $('#additional_4').val(localStorage.getItem("mx_chosen_date")); } else if($('body').hasClass('shop_product_list')) { let mx_product_category_id = $('.current').attr('id'); mx_product_category_id = parseInt(mx_product_category_id.replace('hcategory_', '')); console.log(mx_product_category_id); if (mx_product_category_id == 16 || mx_product_category_id == 17 || mx_product_category_id == 18 || mx_product_category_id == 19) { $('.products .product').each(function() { $('.basket').hide(); let mx_path = $(this).find('.prodname').attr('href'); $(this).find('.basket').after('Zobacz'); }); } } // function setCustomDate(date) { // var clazz = ""; // var arr1 = highlightDays(date); // if (arr1[1] != "") clazz = arr1[1]; // var arr2 = disableAllTheseDays(date); // var arr3 = $.datepicker.noWeekends(date); // return [(!arr2[0] || !arr3[0]) ? false : true, clazz]; // } // $(function () { // $("#dp").datepicker({ // minDate: 0, // dateFormat: 'mm/dd/yy', // inline: true, // numberOfMonths: [1, 2], // dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], // beforeShowDay: setCustomDate // <-----change function // }); // }); } } APIloader(); }); });