var cart_path = "/services/cart" var cart = { 'add': function (productId, quantity) { $.ajax({ url: cart_path + "add", type: 'post', data: 'productId=' + productId + '&quantity=' + (typeof (quantity) != 'undefined' ? quantity : 1), dataType: 'json', success: function (json) { if (json['success']) { $.notify({ message: json['success'], target: '_blank' }, { element: 'body', position: null, type: "info", allow_dismiss: true, newest_on_top: false, placement: { from: "top", align: "right" }, offset: 20, spacing: 10, z_index: 2031, delay: 5000, timer: 1000, url_target: '_blank', mouse_over: null, animate: { enter: 'animated fadeInDown', exit: 'animated fadeOutUp' }, onShow: null, onShown: null, onClose: null, onClosed: null, icon_type: 'class', template: '
' }); // Need to set timeout otherwise it wont update the total setTimeout(function () { $('#cart > button').html('Sepetim ' + json['total'] + ''); }, 100); $('#cart > ul').load('/particals/cartitems'); var loc = String(document.location); if (loc.indexOf("sepetim") >= 0) { window.location = "/sepetim"; } } else { $.notify({ message: json['error'], target: '_blank' }, { element: 'body', position: null, type: "error", allow_dismiss: true, newest_on_top: false, placement: { from: "top", align: "right" }, offset: 20, spacing: 10, z_index: 2031, delay: 5000, timer: 1000, url_target: '_blank', mouse_over: null, animate: { enter: 'animated fadeInDown', exit: 'animated fadeOutUp' }, onShow: null, onShown: null, onClose: null, onClosed: null, icon_type: 'class', template: '' }); } } }); }, 'update': function (key, quantity) { $.ajax({ url: cart_path + "add", type: 'post', data: 'productId=' + key + '&quantity=' + (typeof (quantity) != 'undefined' ? quantity : 1), dataType: 'json', success: function (json) { setTimeout(function () { $('#cart > button').html('Sepetim ' + json['total'] + ''); }, 100); $('#cart > ul').load('/particals/cartitems'); var loc = String(document.location); if (loc.indexOf("sepetim") >= 0) { window.location = "/sepetim"; } } }); }, 'remove': function (key) { $.ajax({ url: cart_path + "remove", type: 'post', data: 'productId=' + key, dataType: 'json', success: function (json) { // Need to set timeout otherwise it wont update the total setTimeout(function () { $('#cart > button').html('Sepetim ' + json['total'] + ''); }, 100); $('#cart > ul').load('/particals/cartitems'); var loc = String(document.location); if (loc.indexOf("sepetim") >= 0) { window.location = "/sepetim"; } } }); } } $(document).on("click", ".add-to-cart", function () { obj = $(this); var productId = parseInt(obj.data("productid")); var quantity = $(".product-quantity-" + productId).val() == undefined ? 1 : $(".product-quantity-" + productId).val(); cart.add(productId, quantity); }) $(document).on("click", ".update-cart", function () { obj = $(this); var productId = parseInt(obj.data("productid")); var quantity = $(".product-quantity-" + productId).val() == undefined ? 1 : $(".product-quantity-" + productId).val(); cart.update(productId, quantity); }) $(document).on("click", ".add-to-stock-alert", function () { obj = $(this); var productId = parseInt(obj.data("productid")); $.ajax({ url: cart_path + "stockAlert", type: 'post', data: 'productId=' + productId, dataType: 'json', success: function (json) { if (json['success']) { $.notify({ message: json['success'], target: '_blank' }, { element: 'body', position: null, type: "info", allow_dismiss: true, newest_on_top: false, placement: { from: "top", align: "right" }, offset: 20, spacing: 10, z_index: 2031, delay: 5000, timer: 1000, url_target: '_blank', mouse_over: null, animate: { enter: 'animated fadeInDown', exit: 'animated fadeOutUp' }, onShow: null, onShown: null, onClose: null, onClosed: null, icon_type: 'class', template: '' }); } else { $.notify({ message: json['error'], target: '_blank' }, { element: 'body', position: null, type: "error", allow_dismiss: true, newest_on_top: false, placement: { from: "top", align: "right" }, offset: 20, spacing: 10, z_index: 2031, delay: 5000, timer: 1000, url_target: '_blank', mouse_over: null, animate: { enter: 'animated fadeInDown', exit: 'animated fadeOutUp' }, onShow: null, onShown: null, onClose: null, onClosed: null, icon_type: 'class', template: '' }); } } }); });