Потребителска кошница

"; if (obj.action==undefined) { if (obj.closest!=undefined) { $(obj.selector).closest(obj.closest).append(html); } else { $(obj.selector).append(html); } } if (obj.action=='addClass') { $(obj.selector).addClass(obj.message); } if (obj.action=='current-prepend') { $(obj.selector).prepend(html); } if (obj.action=='html') { $(obj.selector).html(obj.trigger); } }); if (data.confirm!=undefined&&data.confirm_resend) { getBasket(); swal({ title: "Внимание", text: data.confirm, type: "info", showCancelButton: true, confirmButtonText: "Продължавам!", cancelButtonText: "Отказвам се", closeOnConfirm: false, showLoaderOnConfirm: true }, function(){ $("#loading").hide(); saveValues(submit); }); $("#loading").hide(); } if (data.alert!=undefined) { $("#loading").hide(); swal({ title: "Грешка", text: data.alert, type: "error" }); } if (data.notice!=undefined) { $("#loading").hide(); swal({ title: data.notice_title, text: data.notice, type: "info" }); } if (data.redirect!=undefined) { window.location=data.redirect; } } }); } /* 10 сек*/ setInterval(function () { saveValues(0);}, 10000); $(".radio-element .label-checkbox").on("click touchstart", function () { $(this).closest(".radio-element").find("input[type=radio]").trigger("click"); }); function hideShowDiv(hideSelector, showSelector) { $(hideSelector).hide(); $(showSelector).show(); } $(".shop-delivery input[type='radio']").on("click touchstart", function () { hideShowDiv(".shop-delivery div.delivery", ".shop-delivery div." + $(this).val()); // console.log($(this).val()); addDelivery($(this).val()); //console.log ->set delivery -> get new Total }); $(".shop-invoice input[type='checkbox']").on("click touchstart", function () { hideShowDiv(".shop-invoice div.invoice-1", ".shop-invoice div.invoice-" + ($(this).is(":checked") ? "1" : "0")); }); function visualisation(data) { basketInfo(data.items != undefined ? Object.keys(data.items).length : 0, data.sum_without_delivery+" "); $('.shopOrder tr.product,.shopOrder tr.total,.shopOrder tr.delivery').remove(); $.each(data.items, function (index, value) { addTableRow(value); }); var vouchersCount = $('.product.voucher').length; var noVouchersCount = $('.product').length - vouchersCount; if (noVouchersCount && data.delivery != undefined) { addTableRowDelivery(data.delivery); } noVouchersCount ? $(".shop-delivery").show() : $(".shop-delivery").hide(); if (vouchersCount) { $("#payments-0").attr('disabled', true).attr('checked', false); } $("#Total").val(data.sum); addTableRowTotal('Сума без ДДС', data.sum_without_vats, "total"); addTableRowTotal('ДДС 20% ', data.vats, "total"); addTableRowTotal('Общо', data.sum, "total"); initRemoveButton(); if (data.promocode != undefined) { $(".c4").show(); $("td[colspan='3']").attr("colspan","4"); $(".promocode-message").html("
Код " + data.promocode.code + " Ви носи " + data.promocode.discount + "% отстъпка от непромоционални продукти
"); $(".promocode-form").remove(); } else { $(".c4").hide(); $("td[colspan='4']").attr("colspan","3"); } } function getBasket() { var d = new Date(); $.getJSON("validation.php", { action: "getBasket", nocache: d.getTime() }, function (data) { visualisation(data); }); } var DeliveryNr=0; function addDelivery(type) { DeliveryNr++; var Temp=DeliveryNr; if (type==undefined) { $(".shop-delivery input:checked").val(); } var d = new Date(); var n = d.getTime(); $.getJSON("validation.php", { action: "addDelivery", type: type, date: n }, function (data) { if (Temp==DeliveryNr) { visualisation(data); $("#loading").hide(); } // console.log(Temp,DeliveryNr,data) }); } function addPromoCode(code) { $("#loading").show(); $.getJSON("validation.php", { action: "addPromoCode", code: code }, function (data) { if (data.message.class == 'error') { $(".promocode-message").html("
" + data.message.description + "
"); $("#FormPromoCode").val(''); $("#loading").hide(); } else { addDelivery(); } }); } function addInBasket(price_id, quantity) { $.getJSON("validation.php", { method: "set", action: "addInBasket", price_id: price_id, quantity: quantity }, function (data) { addDelivery(); }); } function addTableRowDelivery(product) { var oneTableRow = '' + '' + product.description + '' + '' + product.price + ' лв.' + '' + product.quantity + '' + ' ' + '' + product.sum + ' лв.' + ' ' + ''; if (product.price!=null) { $('.shopOrder').append(oneTableRow);} } function addTableRow(product) { var noWeightClass = product.weight == 0 ? " voucher " : ""; var promotionLbl = ''; //product.discount_type == 'promo' ? '' : ""; var oneTableRow = '' + '' + promotionLbl + product.description + '' + '' + product.price + ' лв.' + '' + '' + product.discount_sum + ' лв.' + '' + product.sum + ' лв.' + '' + ''; $('.shopOrder').append(oneTableRow); } function addTableRowTotal(label, sum, className = 'total') { var oneTableRow = '' + '' + label + '' + '' + sum + ' лв.' + ' ' + ''; $('.shopOrder').append(oneTableRow); } function initRemoveButton() { $(".c6 i.fa-remove").on("click touchstart", function () { addInBasket($(this).attr("data-id"), 0); }); $(".orderCont").on("blur", function () { addInBasket($(this).attr("data-id"), $(this).val()); }); } // addDelivery(); // console.log("run"); setTimeout(function(){ $(".livesearch-postcodes-ul li").remove(); }, 1000); /* $("[name='Form[payments]']").on("click",function () { saveValues(0); addDelivery(); });*/