var mamezi_lookbook_config = "eyJzaG9wX2lkIjoiOSIsImZvbGRlciI6Imxvb2tib29rIn0="; var lookbookJsonString = atob(mamezi_lookbook_config); var lookbookConfig = JSON.parse(lookbookJsonString); $(function () { initFrontApi(); function initFrontApi() { if (typeof frontAPI !== 'undefined') { __LookbookInitScript(); } else { setTimeout(function () { initFrontApi() }, 50); } } }); var imagePins = []; function MameziLookbook(){ var self = this; this.id = -1; this.init = function(imageId ,imageConfigurator, imagePin, appConfig, callback){ self.id = imageId; var imageConfigurator; imageId = "id_" + self.id; if (imageConfigurator === null || imagePin.imageError == "true") { return ""; } if (imageConfigurator.active === "1") { if (imagePin.imageError === undefined && imagePin.imageError !== true) { let product_ids = []; const reg = new RegExp("[0-9]+$"); for (var key in imagePin[imageId]) { if (!isNaN(parseInt(key)) && reg.test(imagePin[imageId][key].content)) { product_ids.push(parseInt(imagePin[imageId][key].content)); } else if (!isNaN(parseInt(key)) && !reg.test(imagePin[imageId][key].content)) { delete imagePin[imageId][key]; } } if (product_ids.length > 0) { frontAPI.getProducts(function(data){ var products = data; var appConfig = {}; for (let i = 0; i < products.list.length; i++) { for (let key in imagePin[imageId]) { if (products.list[i].id == imagePin[imageId][key].content) { imagePin[imageId][key].main_image = products.list[i].main_image; imagePin[imageId][key].name = products.list[i].name; imagePin[imageId][key].coords.long -= 32; imagePin[imageId][key].url = products.list[i].url; // console.log("imagePIn", imagePin[imageId][key]) if (appConfig.price == null || appConfig.price === "undefined") { if (products.list[i].price.gross.promo !== undefined) { imagePin[imageId][key].price = products.list[i].price.gross.final; imagePin[imageId][key].old_price = products.list[i].price.gross.base; } else { imagePin[imageId][key].price = products.list[i].price.gross.final; imagePin[imageId][key].old_price = ""; } } else if (appConfig.price === "brak") { imagePin[imageId][key].price = ""; imagePin[imageId][key].old_price = ""; } else { if (products.list[i].price.gross.currency_base !== undefined) { if (appConfig.price === "n") { if (products.list[i].price.net.currency_promo !== undefined) { imagePin[imageId][key].price = products.list[i].price.net.currency_promo; imagePin[imageId][key].old_price = products.list[i].price.net.currency_base; } else { imagePin[imageId][key].price = products.list[i].price.net.currency_base; imagePin[imageId][key].old_price = ""; } } else if (appConfig.price === "bn") { if (products.list[i].price.gross.currency_promo !== undefined && products.list[i].price.net.currency_promo !== undefined) { imagePin[imageId][key].price = products.list[i].price.gross.currency_promo + " (netto: " + products.list[i].price.net.currency_promo + ")"; imagePin[imageId][key].old_price = products.list[i].price.gross.currency_base + " (netto: " + products.list[i].price.net.currency_base + ")"; } else { imagePin[imageId][key].price = products.list[i].price.gross.currency_base + " (netto: " + products.list[i].price.net.currency_base + ")"; imagePin[imageId][key].old_price = ""; } } else { if (products.list[i].price.gross.currency_promo !== undefined) { imagePin[imageId][key].price = products.list[i].price.gross.currency_promo; imagePin[imageId][key].old_price = products.list[i].price.gross.currency_base; } else { imagePin[imageId][key].price = products.list[i].price.gross.currency_base; imagePin[imageId][key].old_price = ""; } } } else { if (appConfig.price === "n") { if (products.list[i].price.net.promo !== undefined) { imagePin[imageId][key].price = products.list[i].price.net.final; imagePin[imageId][key].old_price = products.list[i].price.net.base; } else { imagePin[imageId][key].price = products.list[i].price.net.final; imagePin[imageId][key].old_price = ""; } } else if (appConfig.price === "bn") { if (products.list[i].price.gross.promo !== undefined && products.list[i].price.net.promo !== undefined) { imagePin[imageId][key].price = products.list[i].price.gross.final + " (netto: " + products.list[i].price.net.final + ")"; imagePin[imageId][key].old_price = products.list[i].price.gross.base + " (netto: " + products.list[i].price.net.base + ")"; } else { imagePin[imageId][key].price = products.list[i].price.gross.final + " (netto: " + products.list[i].price.net.final + ")"; imagePin[imageId][key].old_price = ""; } } else { if (products.list[i].price.gross.promo !== undefined) { imagePin[imageId][key].price = products.list[i].price.gross.final; imagePin[imageId][key].old_price = products.list[i].price.gross.base; } else { imagePin[imageId][key].price = products.list[i].price.gross.final; imagePin[imageId][key].old_price = ""; } } } } } } } for (let key in imagePin[imageId]) { if (typeof imagePin[imageId][key].name === "undefined" && key !== "canvas") { delete imagePin[imageId][key]; } } var result = makeHTML(imageConfigurator, imageId, imagePin); callback(result) }, { ids: product_ids, urlParams: "?limit=49" }); } else { var result = ""; callback("") } } else { callback("") //return ""; } } else { callback(""); //return ""; } } function makeHTML(imageConfigurator, imageId, imagePin){ imagePins[imageId] = imagePin[imageId]; var result = ""; result += ""; //console.log(imagePin[imageId]) if (appConfig.show_image === "1") { result += "
" + " " + "
" + "
" + "
" + "
" + " " + " {[name]} {[price]} {[old_price]}" + " " + "
" + " \"{[name]}\" " + "
" + "
" + "
" + "
" + " " + "
" + "
" + "
" + "
"; } else { result += "
" + " " + " " + " " + " " + "
" + "
" + "
" + "
"; } return result; } } function __LookbookInitScript(selector) { selector = selector || 'body'; new Shortcode(document.querySelector(selector), { lookbook: function (callback) { var imageId = this.options.id; var imageConfigurator; var imgconf = $.ajax({ type: "post", url: "https://appstore.mamezi.pl/" + lookbookConfig.folder + "/getImageConfig.php", data: { image_id: imageId, shop_id: lookbookConfig.shop_id }, async: true }) .done(function (json) { imageConfigurator = JSON.parse(json); }) .fail(function (json) { return ""; }); var pinconf = $.ajax({ type: "post", url: "https://appstore.mamezi.pl/" + lookbookConfig.folder + "/getPins.php", data: { image_id: "id_" + imageId, shop_id: lookbookConfig.shop_id }, async: true }) .done(function (json) { imagePin = JSON.parse(json); }) .fail(function (json) { return ""; }); var priceconf = $.ajax({ type: "post", url: "https://appstore.mamezi.pl/" + lookbookConfig.folder + "/getPriceConfig.php", data: { shop_id: lookbookConfig.shop_id }, async: true }) .done(function (json) { appConfig = JSON.parse(json); }) .fail(function (json) { appConfig.price = "b"; appConfig.show_image = "0"; }); $.when(imgconf, pinconf, priceconf).done(function(){ if(JSON.parse(imgconf.responseText).amountOfProducts > 0) { var lookbook = new MameziLookbook(); lookbook.init(imageId, imageConfigurator, imagePin, appConfig, callback); } else { callback(""); } }); } }, function (block, classname) { $('.' + classname + ' .pin').easypinShow({ data: imagePins, responsive: true, popover: { show: false, animate: false }, }); if(typeof Shop.prototype.callBackMamezi != "undefined"){ if(typeof Shop.prototype.callBackMamezi.lookbookCallback !== "undefined"){ Shop.prototype.callBackMamezi.lookbookCallback(imagePins, block); } } if(Object.keys(imagePins).length == 0){ $("."+classname).remove(); } }); var string = JSON.stringify(imagePins); } $(function () { $("body").on("click", ".easypin-marker", function () { if ($(this).hasClass("clicked")) { $(".easypin-marker").removeClass("clicked") } else { $(".easypin-marker").removeClass("clicked") $(this).addClass("clicked") } }) }); function mamezi_loadImage(obj){ $(obj).parent().addClass("loaded"); }