$(document).ready(function(){ $("body").on('click', '.caseAdd, .goodCartAddCase', function(e) { var item_id = $(this).attr('item_id'); if (item_id == undefined) { item_id = $(this).parents('.itemBody').attr('item_id'); } if (item_id == undefined) { item_id = $(this).parent().attr('item_id'); } var added = $(this).attr('data-added'); var self = $(this); var type=$(this).attr('type'); var params = { item_id: item_id, addAction: "inc" } $.ajax({ url: "/ajax_case.phtml", data: params, type: 'GET', cache: false, success: function(html) { if (type=='getDiscount') { $(this).createOrder(0, {type: 'getDiscount'}); } else { $("#header .case").html(html); if (self.hasClass('btn')) { self.html(added); } } // var qty = $(".nav-frame .basket-link #case .number").html(); // $(".nav-mobile-list .qty").html(qty); // $("#header .case").addClass('floatable'); // setFloatCasePosition(); // $(this).showHint('добавлен в заказ', e, 'add'); } }); return false; }); $("body").on('click', '.caseTable .del, #caseContainer .btn-del-row', function(e) { var item_id = $(this).parents('tr').attr('item_id'); if (item_id==undefined) { item_id = $(this).parents('li').attr('item_id'); } params = { item_id: item_id, action: "rm" }; $.ajax({ url: "/ajax_case.phtml", data: params, type: 'GET', cache: false, success: function(html) { $("#caseContainer").html(html); // $(this).showHint('Удалено', e); $.ajax({ url: "/ajax_case.phtml", type: 'GET', cache: false, success: function(html) { $("#case").html(html); $(".nav-mobile-list .mob-case").html(html); } }); } }); return false; }); $("#caseContainer").on('click', '.count-box a', function(e) { var action= ($(this).hasClass('inc')?'inc':'dec'); var item_id = $(this).parents('li').attr('item_id'); var type = $(this).parents('.count-box').find('input').attr('name'); params = { item_id: item_id, action: action, type: type }; $.ajax({ url: "/ajax_case.phtml", data: params, type: 'GET', cache: false, success: function(html) { $("#caseContainer").html(html); $.ajax({ url: "/ajax_case.phtml", type: 'GET', cache: false, success: function(html) { $("#case").html(html); $(".nav-mobile-list .mob-case").html(html); } }); } }); return false; }); /* $(".caseTable .q input").live('keyup', function(e) { self = $(this); t_event = e; clearTimeout(t); t=setTimeout("timeUpdateQty()",1000); }); */ $("#caseContainer").on('click', '#createOrderButton', function() { var authorized = $(this).attr('authorized'); var orderComment = $("#orderComment").val(); var comm = $(this).attr('comm'); if ($('#createOrderButton').attr('disabled')=='disabled') { return; } $('#createOrderButton').attr('disabled', 'disabled'); $.ajax({ url: "/ajax_case.phtml", data: {orderComment: orderComment, action: 'setOrderComment'}, type: 'POST', cache: false, success: function(html) { window.location.href='/order/'; /* if (authorized == 1) { $(this).createOrder(comm); $('#createOrderButton').removeAttr('disabled'); } else { window.location.href='/register/?createOrder=1'; } */ } }); }); $("body").on("click", ".getDiscountRegistered", function() { var item_id = $(this).attr('item_id'); $(this).createOrder(0, {type: 'getDiscount', item_id: item_id}); return false; }); $.fn.createOrder = function(comm = 0, params = {} ) { $.ajax({ url: "/auth/ajax_order_case.phtml", data: params, type: 'GET', dataType: 'json', cache: false, success: function(data) { // console.log('data'); // console.log(data); if (data.status=='ok') { if (comm==1) { window.location.href='/admin/orders/?comm=1'; } else { if (params.type=='getDiscount') { dataLayer.push({ 'event': 'event-get-discount', 'order-number': data.npp, 'order_id': data.order_id, 'pageUrl': '', 'fio': data.fio, 'email': data.email, 'city': data.city, 'tel': data.tel, 'message': data.message }); $.fancybox({ 'padding' : 20, 'transitionIn' : 'none', 'transitionOut' : 'none', 'href' : '/forms/getDiscountSuccess.phtml?order_id='+data.order_id, 'type' : 'ajax', 'afterClose' : function() { window.location.reload(); } }); } else { dataLayer.push({ 'ecommerce': { 'currencyCode': 'RUB', 'purchase': { 'actionField': { 'id': data.npp, 'affiliation': 'Neopolis casa', 'revenue': data.revenue, 'tax': '0', 'shipping': data.shipping }, 'products': data.products } }, 'event': 'gtm-ee-purchase-event', 'gtm-ee-event-category': 'Enhanced Ecommerce', 'gtm-ee-event-action': 'Purchase', 'gtm-ee-event-non-interaction': 'False', 'fio': data.fio, 'email': data.email, 'city': data.city, 'tel': data.tel, 'message': data.message, 'order_id': data.order_id }); $.fancybox({ 'padding' : 20, 'transitionIn' : 'none', 'transitionOut' : 'none', 'href' : '/order/success.phtml', 'type' : 'ajax', 'afterClose' : function() { window.location.href='/user/'; } }); } } return true; } else { return false; } } }); } $("body").on('click', '.like', function(e) { var item_id = $(this).attr('item_id'); var authorized = $(this).hasClass('ok'); if (authorized) { if (item_id == undefined) { item_id = $(this).parents('.itemBody').attr('item_id'); } var params = { item_id: item_id } $.ajax({ url: "/ajax_like.phtml", data: params, type: 'GET', cache: false, success: function(html) { $.fancybox({ 'width' : 200, 'type' : 'html', 'padding' : 20, 'content' : "Товар добавлен в избранное" }); // $("#case").html(html); // $("#header .case").addClass('floatable'); // setFloatCasePosition(); // $(this).showHint('добавлен в заказ', e, 'add'); } }); } else { $.fancybox({ 'width' : 200, 'type' : 'html', 'padding' : 20, 'content' : "
Что бы сохранить список избранного и управлять им,
войдите в личный кабинет или зарегистрируйтесь.
" }); } return false; }); }); var t; var self; var t_event; function timeUpdateQty() { clearTimeout(t); var item_id = self.parents('tr').attr('item_id'); var qty = self.val(); var type = self.attr('name'); // if (t_event.which > 47 && t_event.which < 58) { if (qty>0) { params = { item_id: item_id, action: 'set', qty: qty, type: type }; $.ajax({ url: "/ajax_case.phtml", data: params, type: 'GET', cache: false, success: function(html) { $(".contentTable #container").html(html); $(this).showHint('Кол-во изменено', t_event); $.ajax({ url: "/ajax_case.phtml", type: 'GET', cache: false, success: function(html) { $("#header .case i").html(html); } }); } }); } }