var related_app_config = "eyJhcHBfYWN0aXZlIjoiMSIsInNob3BfaWQiOiI5NSIsImhlYWRlckFjdGl2ZSI6IjAiLCJoZWFkZXJUcmFuc2xhdGlvbnMiOiJ7fSIsInNob3dQcm9kdWN0TmFtZSI6IjAifQ=="; var produktyPowiazaneJsonString = atob(related_app_config) var produktyPowiazaneConfig = JSON.parse(produktyPowiazaneJsonString); if (produktyPowiazaneConfig['headerTranslations'] !== undefined) { produktyPowiazaneConfig['headerTranslations'] = JSON.parse(produktyPowiazaneConfig['headerTranslations']); } $(function () { if ($("#box_productfull").length) { initFrontRelatedProducts(); } }); function initFrontRelatedProducts() { if (typeof frontAPI !== 'undefined') { var related = new relatedProducts(); related.init(); } else { setTimeout(function () { initFrontRelatedProducts() }, 50); } } function relatedProducts() { var self = this; this.prodId; this.group; this.blockParent = $(".form-basket"); this.blockRelated; this.init = function () { var relatedProd = produkty_powiazane_data.connectedProductsIds; if (relatedProd === "") { return false; } relatedProd = relatedProd.replace("{", "["); relatedProd = relatedProd.replace("}", "]"); relatedProd = JSON.parse(relatedProd); self.prodId = $("body").attr("id").split("product")[1]; self.group = relatedProd; if (typeof self.group != "undefined" && (self.group.length > 1 || (self.group.length == 1 && self.group[0] != self.prodId))) { generateList(self.group); appendStyle(); } else { return false; } }; function appendStyle(){ $('head').prepend(''); } function generateList(list) { frontAPI.getProducts(function (products) { //get products if (products.list.length > 1) { generateBlocks(products.list); } }, { ids: list, urlParams: '?limit=50' }); } function generateBlocks(data) { let headerText = ""; if (produktyPowiazaneConfig.headerActive === "1") { if (Shop.lang.name !== "" && produktyPowiazaneConfig.headerTranslations !== undefined && produktyPowiazaneConfig.headerTranslations[Shop.lang.name] !== "") { headerText = produktyPowiazaneConfig.headerTranslations[Shop.lang.name]; } } var h4 = $('
', { text: headerText, class: 'relatedHeader' }); h4.css('display', 'inline-flex'); $(self.blockParent).before(h4); self.blockRelated = $("", { id: 'customRelated', class: 'box loading' }) $(h4).after(self.blockRelated); var processed = 0; var toProcess = data.length; $.each(data, function (k, v) { var item = $("", { class: 'related-item', href: v.url, title: v.name }) if (v.id == self.prodId) { $(item).addClass("current"); item.prependTo(self.blockRelated); } else { item.appendTo(self.blockRelated); } if (v.main_image === undefined) { var img = $("