var FreeShippingApp = { init: function () { if (IdeaCart.priceWithDiscount === undefined) { IdeaCart.priceWithDiscount = IdeaCart.totalPrice } if (this.position.includes("bottom")) { jQuery("body").append(this.appContent); }else{ jQuery("body").prepend(this.appContent); } this.createBar(); this.evenListener(); }, position: 'top', appContent : $('\u003Cstyle\u003E\n\u0020\u0020\u0020\u0020\u0023free\u002Dshipping\u002Dapp.top\u0020\u007B\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020top\u003A\u00200\u003B\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020width\u003A\u0020100\u0025\u003B\n\u0020\u0020\u0020\u0020\u007D\n\n\u0020\u0020\u0020\u0020\u0023free\u002Dshipping\u002Dapp.bottom\u0020\u007B\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020bottom\u003A\u00200\u003B\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020width\u003A\u0020100\u0025\u003B\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020position\u003A\u0020absolute\u003B\n\u0020\u0020\u0020\u0020\u007D\n\u003C\/style\u003E\n\n\n\u003Cdiv\u0020id\u003D\u0022free\u002Dshipping\u002Dapp\u0022\u0020class\u003D\u0022top\u0022\u003E\n\u003C\/div\u003E'), minimumCargoPrice: parseFloat('0'), barHtml: "", createBar: function () { if (document.getElementById('freeShippingBar') !== null) { return; } this.barHtml = ""; if (this.getCookie("freeshipping_bar_showed")) { return; } let freeShippingSettings = '\u007B\u0022id\u0022\u003A1135,\u0022user\u0022\u003Anull,\u0022name\u0022\u003A\u0022Kargo\u0020Bedava\u0022,\u0022conditionLessThanContent\u0022\u003A\u0022\u003Ch3\u003E\u003Cspan\u0020style\u003D\\\u0022color\u003A\u0020\u0023ecf0f1\u003B\\\u0022\u003EBug\u0026uuml\u003Bn\u0020Yapaca\\u011f\\u0131n\\u0131z\u0020T\u0026uuml\u003Bm\u0020Al\\u0131\\u015fveri\\u015flerinizde\u0020Kargo\u0020Bedeva\u0020\u0021\u0021\u0021\u0021\u003C\\\/span\u003E\u003C\\\/h3\u003E\u0022,\u0022conditionLessThanHtml\u0022\u003A\u0022\u003Cdiv\u0020id\u003D\\\u0022freeShippingBar\\\u0022\u0020style\u003D\\\u0022background\u002Dcolor\u003A\u0023bcd2e1\u003B\u0020height\u003A50px\u003Bdisplay\u003A\u0020flex\u003Bjustify\u002Dcontent\u003A\u0020center\u003Balign\u002Ditems\u003A\u0020center\u003B\\\u0022\u003E\u0020\u007Bicerik\u007D\u003C\\\/div\u003E\u0022,\u0022conditionGreaterThanContent\u0022\u003A\u0022\u003Ch3\u003E\u003Cspan\u0020style\u003D\\\u0022color\u003A\u0020\u0023ecf0f1\u003B\\\u0022\u003EBug\u0026uuml\u003Bn\u0020Yapaca\\u011f\\u0131n\\u0131z\u0020T\u0026uuml\u003Bm\u0020Al\\u0131\\u015fveri\\u015flerinizde\u0020Kargo\u0020Bedeva\u0020\u0021\u0021\u0021\u0021\u003C\\\/span\u003E\u003C\\\/h3\u003E\u0022,\u0022conditionGreaterThanHtml\u0022\u003A\u0022\u003Cdiv\u0020id\u003D\\\u0022freeShippingBar\\\u0022\u0020style\u003D\\\u0022background\u002Dcolor\u003A\u0023bcd2e1\u003B\u0020height\u003A50px\u003Bdisplay\u003A\u0020flex\u003Bjustify\u002Dcontent\u003A\u0020center\u003Balign\u002Ditems\u003A\u0020center\u003B\\\u0022\u003E\u0020\u007Bicerik\u007D\u003C\\\/div\u003E\u0022,\u0022conditionEmptyContent\u0022\u003A\u0022\u003Ch3\u003E\u003Cspan\u0020style\u003D\\\u0022color\u003A\u0020\u0023ecf0f1\u003B\\\u0022\u003E\u003Cstrong\u003EBug\u0026uuml\u003Bn\u0020Yapaca\\u011f\\u0131n\\u0131z\u0020T\u0026uuml\u003Bm\u0020Al\\u0131\\u015fveri\\u015flerinizde\u0020Kargo\u0020Bedeva\u0020\u0021\u0021\u0021\u0021\u003C\\\/strong\u003E\u003C\\\/span\u003E\u003C\\\/h3\u003E\u0022,\u0022conditionEmptyHtml\u0022\u003A\u0022\u003Cdiv\u0020id\u003D\\\u0022freeShippingBar\\\u0022\u0020style\u003D\\\u0022background\u002Dcolor\u003A\u0023bcd2e1\u003B\u0020height\u003A50px\u003Bdisplay\u003A\u0020flex\u003Bjustify\u002Dcontent\u003A\u0020center\u003Balign\u002Ditems\u003A\u0020center\u003B\\\u0022\u003E\u0020\u007Bicerik\u007D\u003C\\\/div\u003E\u0022,\u0022conditionEmptyBarIsShow\u0022\u003Atrue,\u0022conditionLessThanBarIsShow\u0022\u003Atrue,\u0022conditionGreaterThanBarIsShow\u0022\u003Atrue,\u0022position\u0022\u003A\u0022top\u0022,\u0022status\u0022\u003Atrue,\u0022createdAt\u0022\u003A\u00222022\u002D03\u002D17T16\u003A26\u003A36\u002B03\u003A00\u0022,\u0022updatedAt\u0022\u003A\u00222022\u002D03\u002D17T16\u003A26\u003A58\u002B03\u003A00\u0022\u007D'; freeShippingSettings = JSON.parse(freeShippingSettings); if (IdeaCart.itemCount < 1 && freeShippingSettings.conditionEmptyBarIsShow) { this.barHtml = FreeShippingApp.changeHtml(freeShippingSettings.conditionEmptyHtml, freeShippingSettings.conditionEmptyContent); } else if (IdeaCart.itemCount > 0 && IdeaCart.priceWithDiscount < this.minimumCargoPrice && freeShippingSettings.conditionLessThanBarIsShow) { this.barHtml = FreeShippingApp.changeHtml(freeShippingSettings.conditionLessThanHtml, freeShippingSettings.conditionLessThanContent); } else if (IdeaCart.itemCount > 0 && IdeaCart.priceWithDiscount >= this.minimumCargoPrice && freeShippingSettings.conditionGreaterThanBarIsShow) { this.barHtml = FreeShippingApp.changeHtml(freeShippingSettings.conditionGreaterThanHtml, freeShippingSettings.conditionGreaterThanContent); } this.appendBar(); }, changeHtml: function (conditionHtml, conditionContent) { var barHtml = conditionHtml; barHtml = barHtml.replace('{icerik}', conditionContent) barHtml = barHtml.replaceAll('{kargo_fiyati}', Number(this.minimumCargoPrice.toFixed(2))); barHtml = barHtml.replaceAll('{sepet_tutari}', IdeaCart.priceWithDiscount ? Number(IdeaCart.priceWithDiscount.toFixed(2)) : 0); barHtml = barHtml.replaceAll('{kalan_tutar}', Number((this.minimumCargoPrice - IdeaCart.priceWithDiscount).toFixed(2))); return barHtml; }, appendBar: function () { if (this.barHtml === ""){ return; } let barHtmlObject = $(this.barHtml)[0]; barHtmlObject.innerHTML += '
'; document.getElementById('free-shipping-app').append(barHtmlObject); }, closeBar: function () { let barElements = jQuery('#freeShippingBar'); if (barElements.length > 0) { this.setCookie('freeshipping_bar_showed', true, 30); } barElements.remove(); document.body.style.paddingTop = 0; }, setCookie: function (name, value, days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + (value || "") + expires + "; path=/"; }, getCookie: function (name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); } return null; }, evenListener: function () { $("#freeshipping-bar-close").on('click', function () { FreeShippingApp.closeBar(); }); let postPersist = IdeaCart.listeners.postPersist; IdeaCart.listeners.postPersist = function () { let bar = document.getElementById("freeShippingBar"); if (bar !== null){ bar.remove(); } FreeShippingApp.createBar(); return postPersist.apply(postPersist, arguments); } let postFlush = IdeaCart.listeners.postFlush; IdeaCart.listeners.postFlush = function () { let bar = document.getElementById("freeShippingBar"); if (bar !== null){ bar.remove(); } FreeShippingApp.createBar(); return postFlush.apply(postFlush, arguments); } let postRemove = IdeaCart.listeners.postRemove; IdeaCart.listeners.postRemove = function () { let bar = document.getElementById("freeShippingBar"); if (bar !== null){ bar.remove(); } FreeShippingApp.createBar(); return postRemove.apply(postRemove, arguments); } let postUpdate = IdeaCart.listeners.postUpdate; IdeaCart.listeners.postUpdate = function () { let bar = document.getElementById("freeShippingBar"); if (bar !== null){ bar.remove(); } FreeShippingApp.createBar(); return postUpdate.apply(postUpdate, arguments); } } }; FreeShippingApp.init();