let mxOdswiezGratis=function mxOdswiezGratis(basket){};(function appProduktGratisowy($){let position='buttons';let selector='';let sum_basket='sum_products';let product_border_color='#333333';let product_border_radius='0px';let product_name_font='12px';let product_info_background='rgba(51, 51, 51, 0.6)';let product_info_color='#ffffff';let product_info_font='15px';let product_info_align='left';let product_info_border_color='#333333';let product_info_border_radius='0px';let clicked_on_image='url';let clicked_on_name='url';let clicked_on_button='add';let arrows_background='#d8d8d8';let arrows_color='#333333';let arrows_font='14px';let arrows_border_color='#333333';let arrows_border_radius='0px';let line_color='#03d503';let line_end_color='#02b002';let line_background_color='#d3d3d3';let tag_background_color='#d3f4ca';let tag_font_color='#333333';let tag_off_background_color='#eeeeee';let tag_off_font_color='#333333';let tag_font='13px';let tag_padding='5px';let tag_border_radius_tl='0px';let tag_border_radius_tr='0px';let tag_border_radius_br='0px';let product_promo_font='14px';let product_description_font='14px';let shopId=526;let translations_array={"text_addToBasket":{"__default":"wybierz prezent","pl_PL":"WYBIERZ PREZENT"},"text_variant":{"__default":"Ten produkt otrzymujesz jako prezent","pl_PL":"Ten produkt otrzymujesz jako prezent"},"text_boxhead":{"__default":"Wybierz prezent do Twojego zam\u00f3wienia!","pl_PL":"Wybierz prezent do Twojego zam\u00f3wienia!"},"text_tag":{"__default":"xxx","pl_PL":"xxx"},"text_productExceed":{"__default":"W koszyku jest ju\u017c maksymalna liczba prezent\u00f3w. Usu\u0144 kt\u00f3ry\u015b z nich, aby zmieni\u0107 wyb\u00f3r.","pl_PL":"W koszyku jest ju\u017c maksymalna liczba prezent\u00f3w. Usu\u0144 kt\u00f3ry\u015b z nich, aby zmieni\u0107 wyb\u00f3r."},"text_productLowFreeLeft":{"__default":"Gratisy s\u0105 dost\u0119pne dla zam\u00f3wie\u0144 o warto\u015bci powy\u017cej yyy","pl_PL":"Gratisy s\u0105 dost\u0119pne dla zam\u00f3wie\u0144 o warto\u015bci powy\u017cej yyy"},"text_productLowPrice":{"__default":"Brakuje Ci jeszcze xxx, \u017ceby wybra\u0107 ten gratis.","pl_PL":"Brakuje Ci jeszcze xxx, \u017ceby wybra\u0107 ten gratis."},"text_productLowMaxPrice":{"__default":"Prezent dost\u0119pny dla produkt\u00f3w powy\u017cej yyy","pl_PL":"Prezent dost\u0119pny dla produkt\u00f3w powy\u017cej yyy"},"text_productAbovePrice":{"__default":"Prezent powy\u017cej xxx","pl_PL":"Prezent powy\u017cej xxx"},"text_blockBuying":{"__default":"Ten produkt jest dost\u0119pny tylko jako gratis do zam\u00f3wienia","pl_PL":"Ten produkt jest dost\u0119pny tylko jako gratis do zam\u00f3wienia"},"html_boxfooter":{"__default":"","pl_PL":""}};let freeProducts={"pl_PL":[{"productId":8474,"name":"Sezamki bez cukru 27 g Santini","image":"","price":100,"description":"","settings":{"blockBuying":false,"categoriesChildrens":false,"sumCategories":false,"sumProducers":false,"showHigherPrices":true,"needAllSettings":true,"skipCountLimit":false,"highestPrice":false,"price":100,"categories":{},"producers":{},"products":{},"usersGroups":{"0":"Wszystkie grupy klient\u00f3w"}}},{"productId":494,"name":"Sezamki w Czekoladzie BIO 27 g 3 szt. Rapunzel","image":"","price":100,"description":"","settings":{"blockBuying":false,"categoriesChildrens":false,"sumCategories":false,"sumProducers":false,"showHigherPrices":true,"needAllSettings":true,"skipCountLimit":false,"highestPrice":false,"price":100,"categories":{},"producers":{},"products":{},"usersGroups":{"0":"Wszystkie grupy klient\u00f3w"}}},{"productId":13068,"name":"Chusteczki Bambusowe Nawil\u017cane 10 szt. Bamboolove","image":"","price":150,"description":"","settings":{"blockBuying":false,"categoriesChildrens":false,"sumCategories":false,"sumProducers":false,"showHigherPrices":true,"needAllSettings":true,"skipCountLimit":false,"highestPrice":false,"price":150,"categories":{},"producers":{},"products":{},"usersGroups":{"0":"Wszystkie grupy klient\u00f3w"}}},{"productId":1357,"name":"\u017belki Misie bez \u017belatyny Bezglutenowe BIO 100 g BioMinki","image":"","price":200,"description":"","settings":{"blockBuying":false,"categoriesChildrens":false,"sumCategories":false,"sumProducers":false,"showHigherPrices":true,"needAllSettings":true,"skipCountLimit":false,"highestPrice":false,"price":200,"categories":{},"producers":{},"products":{},"usersGroups":{"0":"Wszystkie grupy klient\u00f3w"}}}]};let freeProductsIds={"pl_PL":[8474,494,13068,1357]};let allFreeProductsIds={"pl_PL":[8474,494,13068,1357]};let freeProductsCounts={"0":"1"};let optionGroupId=2;let optionId=9;let delayedPreloader=1;let forceSingleDownload=0;let template=0;let container_margin_bottom=0;let product_padding=0;let product_border_width=0;let product_image_width=150;let product_image_height=200;let product_image_margin=10;let product_name_margin=10;let product_info_margin=20;let product_info_letter_spacing=2;let product_info_border_width=0;let product_width=200;let product_min_margin=10;let product_name_height=40;let product_button_margin=20;let arrows_hover_visible=1;let arrows_width=40;let arrows_height=40;let arrows_margin=-40;let container_margin=0;let arrows_border_width=0;let line_height=7;let line_margin=10;let tag_triangle_height=7;let product_margin=10;let product_promo_margin=10;let product_description_margin=10;freeProducts=freeProducts[Shop.lang.name]||[];freeProductsIds=freeProductsIds[Shop.lang.name]||[];if(location.href.indexOf('mx_debug')!=-1){let types=['blockBuying','categoriesChildrens','sumCategories','sumProducers','showHigherPrices','needAllSettings','skipCountLimit','highestPrice'];let container=$('
').css({position:'absolute',top:'80px',left:'50%',transform:'translate(-50%, 0)',background:'white',border:'1px solid #000',padding:'20px','border-radius':'10px','font-family':'Open Sans','text-align':'center','z-index':'999',});$('
X
').css({position:'absolute',top:0,right:0,width:'30px',height:'30px','line-height':'28px','font-size':'20px',margin:'5px',border:'1px solid #000','border-radius':'30px',cursor:'pointer',}).click(function(){container.remove();}).appendTo(container);let table=container.append('
').find('table');let header=table.append('').find('tr');for(let item of['productId','price','flags','categories','producers','products','usersGroups']){$(`${item}`).css({padding:'5px 10px'}).appendTo(header);} for(let item of freeProducts){let row=$('');let flags=0;for(let type of types){flags<<=1;flags|=item.settings[type];} $(`${item.productId}`).css({padding:'5px 10px'}).appendTo(row);$(`${item.settings.price}`).css({padding:'5px 10px'}).appendTo(row);$(`${flags.toString(2).padStart(types.length,0)}`).css({padding:'5px 10px'}).appendTo(row);$(`${JSON.stringify(item.settings.categories).slice(1, -1).replaceAll('},','}
')}`).css({padding:'5px 10px','text-align':'left'}).appendTo(row);$(`${JSON.stringify(item.settings.producers).slice(1, -1).replaceAll('},','}
')}`).css({padding:'5px 10px','text-align':'left'}).appendTo(row);$(`${JSON.stringify(item.settings.products).slice(1, -1).replaceAll('},','}
')}`).css({padding:'5px 10px','text-align':'left'}).appendTo(row);$(`${JSON.stringify(item.settings.usersGroups).slice(1, -1).replaceAll('},','}
')}`).css({padding:'5px 10px','text-align':'left'}).appendTo(row);row.appendTo(table);} container.append(`
Flags: ${types.join(', ')}
`);container.appendTo('body');} let escapeHtml=function escapeHtml(unsafe){return unsafe.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'");};let getTranslation=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;};let text_addToBasket=escapeHtml(getTranslation('text_addToBasket'));let text_variant=escapeHtml(getTranslation('text_variant'));let text_boxhead=escapeHtml(getTranslation('text_boxhead'));let text_tag=escapeHtml(getTranslation('text_tag'));let text_productExceed=escapeHtml(getTranslation('text_productExceed'));let text_productLowFreeLeft=escapeHtml(getTranslation('text_productLowFreeLeft'));let text_productLowPrice=escapeHtml(getTranslation('text_productLowPrice'));let text_productLowMaxPrice=escapeHtml(getTranslation('text_productLowMaxPrice'));let text_productAbovePrice=escapeHtml(getTranslation('text_productAbovePrice'));let text_blockBuying=escapeHtml(getTranslation('text_blockBuying'));let html_boxfooter=getTranslation('html_boxfooter');let current_curr=Shop.values.currency?Shop.values.currency:"PLN";let current_lang=Shop.lang.name?Shop.lang.name:"pl_PL";let priceFormater=new Intl.NumberFormat(current_lang.split('_').join('-'),{style:'currency',currency:current_curr});let priceFormat=function priceFormat(price){return priceFormater.format(price);};if(template==0){$('head').append('');$('head').append('');} let APIloader=function APIloader(){if(!window.frontAPI||template==0&&typeof jQuery().owlCarousel!=='function'){setTimeout(APIloader,0);} else{let userGroupId=null;let sum=0;let basketPromo=0;let maxPrice=0;let producers={};let categories={};let expresionProducts={};let htmlToUpdate={};let freeProductsLeft=0;let initialFreeProductsLeft=0;let addedFreeProductsSkippedCountLimit=[];let container=$('
');let avaibleIds=[];let productDatas={};let isPreloader=false;let waitingForIds=true;let waitingForFrontApi=true;let waitingForSoobasket=false;if($('#box_basketlist').length>0){if(typeof GlobalSoolutionSoobasket!='undefined'){waitingForSoobasket=true;}} let generatePreloader=function generatePreloader(){if(container==null)return false;isPreloader=true;if(position=='container'){container.appendTo(selector);}else{if(typeof GlobalSoolutionSoobasket!='undefined'&&$('.el-table .el-table__row').length!=0){if(position=='products'){$('
').insertAfter($('.el-table').parent().next());$('
').insertAfter('.mx_free_products_container');} if(position=='price'){$('
').insertAfter('.el-form + .fixed-summary');$('
').appendTo('.mx_free_products_container');} if(position=='buttons'){$('
').insertAfter($('.el-table').parent().next().next());$('
').appendTo('.mx_free_products_container');}} else{if(position=='products'){$('
').insertAfter('#box_basketlist .productlist');} if(position=='price'){$('
').insertBefore('#box_basketlist #cart-options .buttons');} if(position=='buttons'){$('
').insertAfter('#box_basketlist');}} container.appendTo('.mx_free_products_container');} if(text_boxhead!=''){if(typeof GlobalSoolutionSoobasket!='undefined'&&$('.el-table .el-table__row').length!=0){$('

'+text_boxhead+'

').insertBefore(container);} else{$('
'+text_boxhead+'
').insertBefore(container);}} if(html_boxfooter!=''){$('').append($(``).text()).insertAfter(container);} container.css({'height':'250px','display':'flex','align-items':'center','justify-content':'center'});container.append('');};let generateHtml=function generateHtml(){if(waitingForFrontApi||waitingForSoobasket)return;if(!isPreloader)generatePreloader();let isAdding=false;let prevWidth=0;if(container.find('.line_filler').length>0)prevWidth=container.find('.line_filler').get(0).offsetWidth;let tempElement=$('
').insertBefore(container);container.remove();container=$('
').insertAfter(tempElement);tempElement.remove();if(template==0){container.addClass('template_slider owl-carousel');for(let freeProduct of freeProducts){if(!avaibleIds.includes(freeProduct.productId))continue;let product=productDatas[freeProduct.productId];let name=freeProduct.name!=''?freeProduct.name:product.name;let image=freeProduct.image!=''?freeProduct.image:'/environment/cache/images/300_300_productGfx_'+(product.main_image_filename?product.main_image_filename:'__overlay.jpg');let description=freeProduct.description!=''?freeProduct.description:product.shortDescription;let exceedSkipCountLimit=freeProduct.settings.skipCountLimit&&addedFreeProductsSkippedCountLimit.includes(freeProduct.productId);let exceedCountLimit=!freeProduct.settings.skipCountLimit&&freeProductsLeft<=0;let notEnoughMaxPrice=freeProduct.settings.highestPrice&&maxPrice`);let mx_image=$(`
`).appendTo(productHtml);let mx_image_inner=$(``);if(clicked_on_image=='url'){mx_image_inner=$(``);} else if(clicked_on_image=='add'){mx_image_inner.addClass('mx_pointer');elementsAddingToBasket.push(mx_image_inner);} mx_image_inner.appendTo(mx_image);mx_image_inner.append(`${escapeHtml(name)}`);let mx_name=$(`
`).appendTo(productHtml);let mx_name_inner=$(``);if(clicked_on_name=='url'){mx_name_inner=$(``);} else if(clicked_on_name=='add'){mx_name_inner.addClass('mx_pointer');elementsAddingToBasket.push(mx_name_inner);} mx_name_inner.appendTo(mx_name);mx_name_inner.append(escapeHtml(name));let mx_button=$(`
`).appendTo(productHtml);let mx_button_inner=$(``);if(clicked_on_button=='url'){mx_button_inner=$(``);} else if(clicked_on_button=='add'){mx_button_inner.addClass('mx_pointer');elementsAddingToBasket.push(mx_button_inner);} mx_button_inner.appendTo(mx_button);mx_button_inner.append(text_addToBasket);mx_button.append(``);if(notEnoughSum||notEnoughMaxPrice){productHtml.addClass('is_off');} if(exceedSkipCountLimit||exceedCountLimit||notEnoughSum||notEnoughMaxPrice){mx_button.addClass('is_off');mx_button_inner.removeClass('btn-red');} for(let element of elementsAddingToBasket){element.on('click.add',function(){if(exceedSkipCountLimit||exceedCountLimit||notEnoughSum||notEnoughMaxPrice)return;if(isAdding)return;isAdding=true;let options={};options[optionId]=true;let response=frontAPI.addToBasket({data:{product_id:freeProduct.productId,options:options}});if(response.added.length==0){console.error('appProduktGratisowy',response);alert('Przepraszamy, wystąpił problem przy dodawaniu prezentu do koszyka. Prosimy o wpisanie nazwy prezentu w uwagach do zamówienia.');}else{addedFreeProducts=[];if(localStorage.mx_app_produkt_gratisowy){addedFreeProducts=JSON.parse(localStorage.mx_app_produkt_gratisowy);} addedFreeProducts.push(response.added[0].id);localStorage.mx_app_produkt_gratisowy=JSON.stringify(addedFreeProducts);location.replace(location.href);}});} if(exceedSkipCountLimit){if(text_productExceed!=''){productHtml.append('
'+text_productExceed+'
');}} else if(exceedCountLimit){if(initialFreeProductsLeft==0){if(freeProduct.settings.price!=0){if(text_productLowPrice!=''){productHtml.append('
'+text_productLowPrice.replace('xxx',priceFormat(freeProduct.settings.price-sum)).replace('yyy',priceFormat(freeProduct.settings.price))+'
');}}else{let temp=Object.keys(freeProductsCounts)[Math.min(1,Object.keys(freeProductsCounts).length)];productHtml.append('
'+text_productLowFreeLeft.replace('xxx',priceFormat(temp-sum)).replace('yyy',priceFormat(temp))+'
');}}else{if(text_productExceed!=''){productHtml.append('
'+text_productExceed+'
');}}} else if(notEnoughMaxPrice){if(text_productLowPrice!=''){productHtml.append('
'+text_productLowMaxPrice.replace('xxx',priceFormat(freeProduct.settings.price-maxPrice)).replace('yyy',priceFormat(freeProduct.settings.price))+'
');}} else if(notEnoughSum){if(text_productLowPrice!=''){productHtml.append('
'+text_productLowPrice.replace('xxx',priceFormat(freeProduct.settings.price-sum)).replace('yyy',priceFormat(freeProduct.settings.price))+'
');}} container.append(productHtml);} container.on('refreshed.owl.carousel',function(e){if(e.relatedTarget.$stage.width()','',],responsiveBaseElement:'.mx_free_products .owl-stage-outer',responsive:responsive,});let drawLine=function drawLine(){let line=$('
');let width=0;let afterTag=0;let step=0;for(let freeProduct of freeProducts){if(!avaibleIds.includes(freeProduct.productId))continue;let price=freeProduct.settings.price;if(stepprice){width=-left;} if(sum>step){if(sum<=price){width=-width+(left+width)*(sum-step)/(price-step);}else{afterTag=-width+box.offsetWidth*(sum-price)/(price-step);}} if(price<=sum){line.append('
'+text_tag.replace('xxx',priceFormat(price))+'
');}else{line.append('
'+text_tag.replace('xxx',priceFormat(price))+'
');} step=price;}} if(sum>step){width=afterTag;} line.prepend('
');setTimeout(function(){line.find('.line_filler').css('width',width+'px');},1);if(step!=0){container.find('.owl-stage .line').remove();line.appendTo(container.find('.owl-stage'));let tagHeight=line.find('.line_tag').get(0).scrollHeight;line.css('top',tagHeight-line.height());line.find('.line_tag').css('top',-(tagHeight-line.height()));container.find('.owl-stage').css('padding-top',tagHeight+line_margin*1+'px');}else{container.find('.owl-stage').css('padding-top',0);}};setTimeout(drawLine,1);} if(template==1){container.addClass('template_list');for(let freeProduct of freeProducts){if(!avaibleIds.includes(freeProduct.productId))continue;let product=productDatas[freeProduct.productId];let name=freeProduct.name!=''?freeProduct.name:product.name;let image=freeProduct.image!=''?freeProduct.image:'/environment/cache/images/300_300_productGfx_'+(product.main_image_filename?product.main_image_filename:'__overlay.jpg');let description=freeProduct.description!=''?freeProduct.description:product.shortDescription;let exceedSkipCountLimit=freeProduct.settings.skipCountLimit&&addedFreeProductsSkippedCountLimit.includes(freeProduct.productId);let exceedCountLimit=!freeProduct.settings.skipCountLimit&&freeProductsLeft<=0;let notEnoughMaxPrice=freeProduct.settings.highestPrice&&maxPrice`);let mx_image=$(`
`).appendTo(productHtml);let mx_image_inner=$(``);if(clicked_on_image=='url'){mx_image_inner=$(``);} else if(clicked_on_image=='add'){mx_image_inner.addClass('mx_pointer');elementsAddingToBasket.push(mx_image_inner);} mx_image_inner.appendTo(mx_image);mx_image_inner.append(`${escapeHtml(name)}`);let mx_info=$(`
`).appendTo(productHtml);if(freeProduct.settings.price>0&&text_productAbovePrice!=''){let mx_promo=$(`
`).appendTo(mx_info);mx_promo.append(text_productAbovePrice.replace('xxx',priceFormat(freeProduct.settings.price)));} let mx_name=$(`
`).appendTo(mx_info);let mx_name_inner=$(``);if(clicked_on_name=='url'){mx_name_inner=$(``);} else if(clicked_on_name=='add'){mx_name_inner.addClass('mx_pointer');elementsAddingToBasket.push(mx_name_inner);} mx_name_inner.appendTo(mx_name);mx_name_inner.append(escapeHtml(name));let mx_description=$(`
`).appendTo(mx_info);mx_description.append(description);let mx_button=$(`
`).appendTo(mx_info);let mx_button_inner=$(``);if(clicked_on_button=='url'){mx_button_inner=$(``);} else if(clicked_on_button=='add'){mx_button_inner.addClass('mx_pointer');elementsAddingToBasket.push(mx_button_inner);} mx_button_inner.appendTo(mx_button);mx_button_inner.append(text_addToBasket);mx_button.append(``);if(notEnoughSum||notEnoughMaxPrice){productHtml.addClass('is_off');} if(exceedSkipCountLimit||exceedCountLimit||notEnoughSum||notEnoughMaxPrice){mx_button.addClass('is_off');mx_button_inner.removeClass('btn-red');} for(let element of elementsAddingToBasket){element.on('click.add',function(){if(exceedSkipCountLimit||exceedCountLimit||notEnoughSum||notEnoughMaxPrice)return;if(isAdding)return;isAdding=true;let options={};options[optionId]=true;let response=frontAPI.addToBasket({data:{product_id:freeProduct.productId,options:options}});if(response.added.length==0){console.error('appProduktGratisowy',response);alert('Przepraszamy, wystąpił problem przy dodawaniu prezentu do koszyka. Prosimy o wpisanie nazwy prezentu w uwagach do zamówienia.');}else{addedFreeProducts=[];if(localStorage.mx_app_produkt_gratisowy){addedFreeProducts=JSON.parse(localStorage.mx_app_produkt_gratisowy);} addedFreeProducts.push(response.added[0].id);localStorage.mx_app_produkt_gratisowy=JSON.stringify(addedFreeProducts);location.replace(location.href);}});} if(exceedSkipCountLimit){if(text_productExceed!=''){productHtml.append('
'+text_productExceed+'
');}} else if(exceedCountLimit){if(initialFreeProductsLeft==0){if(freeProduct.settings.price!=0){if(text_productLowPrice!=''){productHtml.append('
'+text_productLowPrice.replace('xxx',priceFormat(freeProduct.settings.price-sum)).replace('yyy',priceFormat(freeProduct.settings.price))+'
');}}else{let temp=Object.keys(freeProductsCounts)[Math.min(1,Object.keys(freeProductsCounts).length)];productHtml.append('
'+text_productLowFreeLeft.replace('xxx',priceFormat(temp-sum)).replace('yyy',priceFormat(temp))+'
');}}else{if(text_productExceed!=''){productHtml.append('
'+text_productExceed+'
');}}} else if(notEnoughMaxPrice){if(text_productLowPrice!=''){productHtml.append('
'+text_productLowMaxPrice.replace('xxx',priceFormat(freeProduct.settings.price-maxPrice)).replace('yyy',priceFormat(freeProduct.settings.price))+'
');}} else if(notEnoughSum){if(text_productLowPrice!=''){productHtml.append('
'+text_productLowPrice.replace('xxx',priceFormat(freeProduct.settings.price-sum)).replace('yyy',priceFormat(freeProduct.settings.price))+'
');}} container.append(productHtml);}}};let selectProducts=function selectProducts(){avaibleIds=[];let downloadIds=[];for(let freeProduct of freeProducts){let isProducer=false,isCategory=false,isExpresionProduct=false,isPrice=false,isUserGroup=false;let counter=0;let adder=0;if(Object.keys(freeProduct.settings.producers).length>0){for(let producerId in freeProduct.settings.producers){if(typeof producers[producerId]!='undefined'){counter+=producers[producerId].quantity;adder+=producers[producerId].price;if(freeProduct.settings.producers[producerId].quantity<=producers[producerId].quantity&&freeProduct.settings.producers[producerId].price<=producers[producerId].price){isProducer=true;break;}}} if(!isProducer&&freeProduct.settings.sumProducers){for(let producerId in freeProduct.settings.producers){if(freeProduct.settings.producers[producerId].quantity<=counter&&freeProduct.settings.producers[producerId].price<=adder){isProducer=true;break;}}}}else{isProducer=true;} counter=0;adder=0;if(Object.keys(freeProduct.settings.categories).length>0){for(let cateroryId in freeProduct.settings.categories){if(typeof categories[cateroryId]!='undefined'){let countChildrens=0;let sumChildrens=0;if(freeProduct.settings.categoriesChildrens){countChildrens+=categories[cateroryId].quantity;sumChildrens+=categories[cateroryId].price;}else{countChildrens+=categories[cateroryId].quantity;sumChildrens+=categories[cateroryId].price;} counter+=countChildrens;adder+=sumChildrens;if(freeProduct.settings.categories[cateroryId].quantity<=countChildrens&&freeProduct.settings.categories[cateroryId].price<=sumChildrens){isCategory=true;break;}}} if(!isCategory&&freeProduct.settings.sumCategories){for(let cateroryId in freeProduct.settings.categories){if(freeProduct.settings.categories[cateroryId].quantity<=counter&&freeProduct.settings.categories[cateroryId].price<=adder){isCategory=true;break;}}}}else{isCategory=true;} if(Object.keys(freeProduct.settings.products).length>0){for(let productId in freeProduct.settings.products){if(typeof expresionProducts[productId]!='undefined'){if(freeProduct.settings.products[productId].quantity<=expresionProducts[productId].quantity&&freeProduct.settings.products[productId].price<=expresionProducts[productId].price){isExpresionProduct=true;break;}}}}else{isExpresionProduct=true;} if(freeProduct.settings.highestPrice){if(freeProduct.settings.price<=maxPrice){isPrice=true;}}else{if(freeProduct.settings.price<=sum){isPrice=true;}} if(!(0 in freeProduct.settings.usersGroups)){if(userGroupId in freeProduct.settings.usersGroups){isUserGroup=true;}}else{if(!(userGroupId in freeProduct.settings.usersGroups)){isUserGroup=true;}} if(freeProduct.settings.needAllSettings){if(!isProducer||!isCategory||!isExpresionProduct||!isUserGroup){continue;} if(!isPrice&&!freeProduct.settings.showHigherPrices){continue;}}else{if((!isUserGroup||0 in freeProduct.settings.usersGroups&&Object.keys(freeProduct.settings.usersGroups).length==1)&&(!isProducer||Object.keys(freeProduct.settings.producers).length==0)&&(!isCategory||Object.keys(freeProduct.settings.categories).length==0)&&(!isExpresionProduct||Object.keys(freeProduct.settings.products).length==0)){if(!isPrice&&!freeProduct.settings.showHigherPrices){continue;}}else{freeProduct.settings.price=0;}} if(freeProduct.productId in productDatas){avaibleIds.push(freeProduct.productId);} else{downloadIds.push(freeProduct.productId);}} if(avaibleIds.length==0&&downloadIds.length==0){container.parent().remove();container=null;return false;} waitingForIds=false;if(!isPreloader&&delayedPreloader&&!waitingForSoobasket)generatePreloader();waitingForFrontApi=true;if(downloadIds.length==0){waitingForFrontApi=false;generateHtml();} else{let promises=[];let downloadChunkCount=Math.ceil(downloadIds.length/50);for(let i=1;i<=downloadChunkCount;i++){promises.push(new Promise(function(resolve,reject){frontAPI.getProducts(function(products){if(products.count>0){for(let product of products.list){if(!product.can_buy)continue;productDatas[product.id]=product;avaibleIds.push(product.id);}} resolve(true);},{ids:downloadIds.slice((i-1)*50,i*50),urlParams:'?limit=50'});}));} Promise.all(promises).then(function(){if(avaibleIds.length0){let recurentGetProduct=function recurentGetProduct(key=0){frontAPI.getProduct(function(product){if(!('error_description'in product)&&product.can_buy){productDatas[product.id]=product;avaibleIds.push(product.id);} if(key==remainingIds.length-1||!forceSingleDownload&&avaibleIds.length>=15){if(avaibleIds.length==0){container.parent().remove();container=null;return false;} waitingForFrontApi=false;generateHtml();}else{recurentGetProduct(key+1);}},{id:remainingIds[key]});}();} else{waitingForFrontApi=false;generateHtml();}} else{waitingForFrontApi=false;generateHtml();}});} return true;};let refreshFromBasket=function refreshFromBasket(basket){sum=0;basketPromo=1;maxPrice=0;producers={};categories={};expresionProducts={};htmlToUpdate={};freeProductsLeft=0;initialFreeProductsLeft=0;addedFreeProductsSkippedCountLimit=[];if(userGroupId==null){userGroupId=-1;let userId=Shop.fn.getVisitorId();if(userId!=null){let user=frontAPI.getUser({id:userId});if(0 in user.groups){userGroupId=user.groups[0].group_id;}}} let addedFreeProducts=[];if(localStorage.mx_app_produkt_gratisowy){addedFreeProducts=JSON.parse(localStorage.mx_app_produkt_gratisowy);} sum=0;basketPromo=1;switch(sum_basket){case'sum_products':sum=Math.round(basket.basket.sum_products_float*100)/100;break;case'sum_shipping':sum=Math.round((basket.basket.sum_products_float+basket.basket.sum_float-basket.basket.sum_no_shipping_float)*100)/100;break;case'sum_no_shipping':sum=Math.round(basket.basket.sum_no_shipping_float*100)/100;if(basket.promos!=null){for(let key in basket.promos){basketPromo+=basket.promos[key].percent;} basketPromo=1-Math.min(basketPromo,100)/ 100;} break;case'sum':sum=Math.round(basket.basket.sum_float*100)/100;if(basket.promos!=null){for(let key in basket.promos){basketPromo+=basket.promos[key].percent;} basketPromo=1-Math.min(basketPromo,100)/ 100;} break;default:console.error('appProduktGratisowy maxsote.pl - niewłaściwy sposób sumowania');} freeProductsLeft=0;for(let price in freeProductsCounts){if(price<=sum)freeProductsLeft=freeProductsCounts[price];} initialFreeProductsLeft=freeProductsLeft;let reload=false;let basketProductsIds=[];for(let product of basket.products){basketProductsIds.push(product.id);let freeKey=freeProductsIds.indexOf(product.product_id);if(freeKey==-1){for(let langKey in allFreeProductsIds){if(langKey==Shop.lang.name)continue;let langFreeKey=allFreeProductsIds[langKey].indexOf(product.product_id);let addedFreeProductsKey=addedFreeProducts.indexOf(product.id);if(langFreeKey!=-1&&product.variant!=''){frontAPI.removeFromBasket({id:product.id});if(addedFreeProductsKey!=-1)addedFreeProducts.splice(addedFreeProductsKey,1);reload=true;}}} let addedFreeProductsKey=addedFreeProducts.indexOf(product.id);if(freeKey!=-1&&product.variant!=''){if(freeProducts[freeKey].settings.skipCountLimit){if(product.quantity>1){frontAPI.removeFromBasket({id:product.id});if(addedFreeProductsKey!=-1)addedFreeProducts.splice(addedFreeProductsKey,1);reload=true;continue;} addedFreeProductsSkippedCountLimit.push(product.product_id);} else{if(freeProductsLeft0){for(let producerId in freeProducts[freeKey].settings.producers){if(typeof producers[producerId]!='undefined'){counter+=producers[producerId].quantity;adder+=producers[producerId].price;if(freeProducts[freeKey].settings.producers[producerId].quantity<=producers[producerId].quantity&&freeProducts[freeKey].settings.producers[producerId].price<=producers[producerId].price){isProducer=true;break;}}} if(!isProducer&&freeProducts[freeKey].settings.sumProducers){for(let producerId in freeProducts[freeKey].settings.producers){if(freeProducts[freeKey].settings.producers[producerId].quantity<=counter&&freeProducts[freeKey].settings.producers[producerId].price<=adder){isProducer=true;break;}}}}else{isProducer=true;} counter=0;adder=0;if(Object.keys(freeProducts[freeKey].settings.categories).length>0){for(let cateroryId in freeProducts[freeKey].settings.categories){if(typeof categories[cateroryId]!='undefined'){let countChildrens=0;let sumChildrens=0;if(freeProducts[freeKey].settings.categoriesChildrens){countChildrens+=categories[cateroryId].quantity;sumChildrens+=categories[cateroryId].price;}else{countChildrens+=categories[cateroryId].quantity;sumChildrens+=categories[cateroryId].price;} counter+=countChildrens;adder+=sumChildrens;if(freeProducts[freeKey].settings.categories[cateroryId].quantity<=countChildrens&&freeProducts[freeKey].settings.categories[cateroryId].price<=sumChildrens){isCategory=true;break;}}} if(!isCategory&&freeProducts[freeKey].settings.sumCategories){for(let cateroryId in freeProducts[freeKey].settings.categories){if(freeProducts[freeKey].settings.categories[cateroryId].quantity<=counter&&freeProducts[freeKey].settings.categories[cateroryId].price<=adder){isCategory=true;break;}}}}else{isCategory=true;} if(Object.keys(freeProducts[freeKey].settings.products).length>0){for(let productId in freeProducts[freeKey].settings.products){if(typeof expresionProducts[productId]!='undefined'){if(freeProducts[freeKey].settings.products[productId].quantity<=expresionProducts[productId].quantity&&freeProducts[freeKey].settings.products[productId].price<=expresionProducts[productId].price){isExpresionProduct=true;break;}}}}else{isExpresionProduct=true;} if(freeProducts[freeKey].settings.highestPrice){if(freeProducts[freeKey].settings.price<=maxPrice){isPrice=true;}}else{if(freeProducts[freeKey].settings.price<=sum){isPrice=true;}} if(!(0 in freeProducts[freeKey].settings.usersGroups)){if(userGroupId in freeProducts[freeKey].settings.usersGroups){isUserGroup=true;}}else{if(!(userGroupId in freeProducts[freeKey].settings.usersGroups)){isUserGroup=true;}} if(freeProducts[freeKey].settings.needAllSettings){if(!isProducer||!isCategory||!isExpresionProduct||!isPrice||!isUserGroup){frontAPI.removeFromBasket({id:product.id});if(addedFreeProductsKey!=-1)addedFreeProducts.splice(addedFreeProductsKey,1);reload=true;}}else{if((!isUserGroup||0 in freeProducts[freeKey].settings.usersGroups&&Object.keys(freeProducts[freeKey].settings.usersGroups).length==1)&&(!isProducer||Object.keys(freeProducts[freeKey].settings.producers).length==0)&&(!isCategory||Object.keys(freeProducts[freeKey].settings.categories).length==0)&&(!isExpresionProduct||Object.keys(freeProducts[freeKey].settings.products).length==0)&&!isPrice){frontAPI.removeFromBasket({id:product.id});if(addedFreeProductsKey!=-1)addedFreeProducts.splice(addedFreeProductsKey,1);reload=true;}}} else if(freeProducts[freeKey].settings.blockBuying){frontAPI.removeFromBasket({id:product.id});if(addedFreeProductsKey!=-1)addedFreeProducts.splice(addedFreeProductsKey,1);reload=true;}}} let diffAddedFreeProducts=[];for(let item of addedFreeProducts){if(basketProductsIds.includes(item)){diffAddedFreeProducts.push(item);}} addedFreeProducts=diffAddedFreeProducts;localStorage.mx_app_produkt_gratisowy=JSON.stringify(addedFreeProducts);if(reload)location.replace(location.href);if(!selectProducts())return false;return true;};mxOdswiezGratis=function mxOdswiezGratis(basket){waitingForSoobasket=false;if(container==null){container=$('
');generatePreloader();} refreshFromBasket(basket);};frontAPI.getBasketInfo(function(basket){if(!refreshFromBasket(basket))return false;if($('#box_basketsummary').length>0){for(let freeKey in htmlToUpdate){let product=htmlToUpdate[freeKey];let item;$('#box_basketsummary [data-product-id="'+product.product_id+'"]').each(function(index2,item2){if($(item2).find('.variant').text().trim()==product.variant){item=$(item2);return false;}});if(freeProducts[freeKey].image!=''){item.find('.img img').attr('src',freeProducts[freeKey].image);} if(freeProducts[freeKey].name!=''){item.find('.name a').html(escapeHtml(freeProducts[freeKey].name)).attr('title',escapeHtml(freeProducts[freeKey].name));} item.find('.name .variant').html(text_variant);item.find('.price').html(product.price);}} if($('#box_basketlist').length>0){if(typeof GlobalSoolutionSoobasket!='undefined'){waitingForSoobasket=true;let waitingFunction=function waitingFunction(){if($('#box_basketlist').is(':visible')){for(let freeKey in htmlToUpdate){let product=htmlToUpdate[freeKey];let item=$('#box_basketlist [href$="/basket/remove/'+product.id+'"]').parent().parent();if(freeProducts[freeKey].image!=''){item.find('.img img').attr('src',freeProducts[freeKey].image);} if(freeProducts[freeKey].name!=''){item.find('.name a').html(escapeHtml(freeProducts[freeKey].name)).attr('title',escapeHtml(freeProducts[freeKey].name));} item.find('.name .variant').html(text_variant);item.find('.quantity input').val(product.quantity).prop('readonly',true).css({'background':'#33333333','cursor':'auto'});item.find('.quantity .wce_qdec, .quantity .wce_qinc').remove();item.find('.price').html(product.price);} waitingForSoobasket=false;if(!isPreloader&&(!delayedPreloader||delayedPreloader&&!waitingForIds))generatePreloader();generateHtml();} else if($('.el-table .el-table__row').length==0){setTimeout(waitingFunction,100);} else{for(let freeKey in htmlToUpdate){let product=htmlToUpdate[freeKey];let item=$('.el-table .basket_product_id_'+product.id);if(freeProducts[freeKey].image!=''){item.find('img').attr('src',freeProducts[freeKey].image).css({'max-width':'75px'});} if(freeProducts[freeKey].name!=''){item.find('.name a').html(escapeHtml(freeProducts[freeKey].name)).attr('title',escapeHtml(freeProducts[freeKey].name));} item.find('.name .variant').html(text_variant);item.find('.quantity-input').append('
');item.find('.quantity-input input').val(product.quantity).prop('readonly',true);item.find('.el-table_1_column_5 .cell').html(`${product.price}`);} waitingForSoobasket=false;if(!isPreloader&&(!delayedPreloader||delayedPreloader&&!waitingForIds))generatePreloader();generateHtml();}};waitingFunction();} else{for(let freeKey in htmlToUpdate){let product=htmlToUpdate[freeKey];let item=$('#box_basketlist [href$="/basket/remove/'+product.id+'"]').parent().parent();if(freeProducts[freeKey].image!=''){item.find('.img img').attr('src',freeProducts[freeKey].image).css({'max-width':'75px'});} if(freeProducts[freeKey].name!=''){item.find('.name a').html(escapeHtml(freeProducts[freeKey].name)).attr('title',escapeHtml(freeProducts[freeKey].name));} item.find('.name .variant').html(text_variant);item.find('.quantity input').val(product.quantity).prop('readonly',true).css({'background':'#33333333','cursor':'auto'});item.find('.quantity .wce_qdec, .quantity .wce_qinc').remove();item.find('.price').html(product.price);} if(!isPreloader&&!delayedPreloader)generatePreloader();}}},{});}};if($('#box_productfull').length>0){for(let freeProduct of freeProducts){$(`#box_productfull #option_${optionId}`).parent().parent().parent().parent().remove();if(freeProduct.productId==Shop.pageId&&Boolean(freeProduct.settings.blockBuying)){$('#box_productfull .form-basket > fieldset').hide();$('#box_productfull .form-basket').append(`
${text_blockBuying}
`);} else{$(`#box_productfull .stocks`).show();}} $(`.stocks-bundle [data-variant-id="${optionId}"]`).parent().parent().parent().remove();} else if($('.shop_product_list').length>0){for(let freeProduct of freeProducts){if(freeProduct.settings.blockBuying){$(`[data-product-id="${freeProduct.productId}"] .addtobasket`).hide();$(`[data-product-id="${freeProduct.productId}"] .mx_app_ilosc`).hide();}}} else{let applyCurrencyRate=function(currencyRate){if(currencyRate==1)return;let freeProductsCountsCopy=Object.assign({},freeProductsCounts);freeProductsCounts={};for(let step in freeProductsCountsCopy){freeProductsCounts[step*currencyRate]=freeProductsCountsCopy[step];} for(let lang in freeProducts){let freeProductsLang=freeProducts[lang];for(let key1 in freeProductsLang){let freeProduct=freeProductsLang[key1];freeProduct.price*=currencyRate;for(let key2 in freeProduct.settings){let settings=freeProduct.settings[key2];settings.price*=currencyRate;for(let objectId in settings.categories){let object=settings.categories[objectId];object.price*=currencyRate;} for(let objectId in settings.producers){let object=settings.producers[objectId];object.price*=currencyRate;} for(let objectId in settings.products){let object=settings.products[objectId];object.price*=currencyRate;}}}}};let cache_currency='';if(localStorage.mx_app_produkt_gratisowy_currency){cache_currency=localStorage.mx_app_produkt_gratisowy_currency;} if(cache_currency!=current_curr){let link="https://mxapp4.maxserver.pl/appProduktGratisowy/getCurrencyRate.php";let postData={shopId:shopId,currency:current_curr};$.post(link,postData).done((response)=>{response=JSON.parse(response);if('error'in response)return false;localStorage.mx_app_produkt_gratisowy_currency=current_curr;localStorage.mx_app_produkt_gratisowy_currency_rate=response.rate;applyCurrencyRate(response.rate);APIloader();});} else{applyCurrencyRate(localStorage.mx_app_produkt_gratisowy_currency_rate*1);APIloader();}} let style='';style+=` \n`;$("head").append(style);}(jQuery)); //# sourceURL=script_appProduktGratisowy