$(function () { visible = false; var methods; managerSetted = typeof (ManageItemsWS) != 'undefined'; if (managerSetted) { methods = { init: function (options) { }, addItem: function (id, giftListId, applyDiscount) { ManageItemsWS.AddItem(id, giftListId, applyDiscount, function (result) { updateShoppingCartMSG(result, id, applyDiscount == '1'); }); return false; }, addItemFromWishList: function (id, applyDiscount) { ManageItemsWS.AddItemFromWishList(id, applyDiscount, function (result) { updateShoppingCartMSG(result, id, applyDiscount == '1'); }); return false; }, moveItemToWishList: function (id) { if (id) $.prompt('Are you sure you want to move the selected item to your WishList?', { top: '35%', buttons: { Ok: true, Cancel: false }, callback: confirmMoveToWishListResult }); //confirm('Are you sure you want to delete this item?')) return false; }, removeItem: function (id) { if (id) $.prompt('Are you sure you want to delete the selected item?', { top: '35%', buttons: { Ok: true, Cancel: false }, callback: confirmDeleteResult }); //confirm('Are you sure you want to delete this item?')) }, showAll: function (showShoppingCart) { ManageItemsWS.GetAll(function (result) { constructShoppingCart(result); }); } }; } else { methods = { init: notLoaded, addItem: notLoaded, addItemFromWishList: notLoaded, moveItemToWishList: notLoaded, removeItem: notLoaded, showAll: notLoaded }; } // Inicialize the plugin jQuery.checkOutManager = function (method) { // Method calling logic if (methods[method]) { return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); } else if (typeof method === 'object' || !method) { return methods.init.apply(this, arguments); } else { $.error('Method ' + method + ' does not exist on jQuery.checkOutManager'); } }; // Display the cart $("#toggleController").click(function () { toggleWindow(); }); $(".view-chart").click(function () { //if (!visible) toggleWindow(); }); $("#continueShopping").click(function () { toggleWindow(); }); //Remove from cart $('.btnRemoveFromCart').click(function () { $.checkOutManager('removeItem', $(this).attr('itemid')); return false; }); //Move to wish List $('.btnMoveToWishList').click(function () { $.checkOutManager('moveItemToWishList', $(this).attr('itemid')); return false; }); }); function confirmDeleteResult(v, m, f) { if (v) //user clicked OK ManageItemsWS.RemoveItem(f.id, updateShoppingCartAfterRemove); } function confirmMoveToWishListResult(v, m, f) { if (v) //user clicked OK { //function updateShoppingCartAndRedirect(result) { //updateShoppingCartAfterRemove(result); location.href = top.location.protocol + '/account/wish-list.aspx?itemid=' + f.id + '&fromCart=true'; //} //ManageItemsWS.MoveItemToWishList(f.id, updateShoppingCartAndRedirect); } } function notLoaded() { $.prompt("Error ManagerSetter incorrect"); } function constructShoppingCart(result) { var text = $('#ctl00_floating_lblCount').text(); var totalItem = parseInt(text ? text : 0); for (var item in result) { $('.EmptyItems').remove(); $('.jspContainer').show(); $('.checkOut').show(); var row = "
\'\'
" + result[item].Title + "" + (result[item].HasDiscount ? result[item].FormatedOriginalPrice : result[item].FormatedPrice) + "" + (result[item].HasDiscount ? "" + result[item].FormatedPrice + "" : "") + "
DeleteMove to Wish List
"; // Add the new book $('#tblItems > tbody:last').append(row); totalItem = totalItem + 1; // Update the total $('#ctl00_floating_lblTotal').text('TOTAL: ' + result[item].FormatedTotalCart); //Remove bindings for the click to prevent the event fired more than one time $('.btnRemoveFromCart').unbind('click'); //Bind the delete button with the function $('.btnRemoveFromCart').click(function () { $.checkOutManager('removeItem', $(this).attr('itemid')); return false; }); //Remove bindings for the click to prevent the event fired more than one time $('.btnMoveToWishList').unbind('click'); //Move to wish List $('.btnMoveToWishList').click(function () { $.checkOutManager('moveItemToWishList', $(this).attr('itemid')); return false; }); } // Update the total $('#ctl00_floating_lblCount').text(totalItem); $('#ctl00_lblCount').text(totalItem); var currency = $('#ddlCurrency').val(); if (currency != "USD" && $.isFunction(window.ConvertShoppingCartPrices)) ConvertShoppingCartPrices(currency, $('#ddlSymbol').val()); } function updateShoppingCartMSG(result, id, applyDiscount) { var message = ""; if (result.Id == -2) { message = "The book already exists in the shopping bag"; $.prompt(message); } else { if (result.Id == -10) { message = "We're sorry, this item has been sold"; $.prompt(message); } else { if (result.Id == -3) { message = "We're sorry, this item currently on reserve, inquire for more information"; $.prompt(message); } else { if (result.Id == -777) { message = "There was an error moving the book from the Wish List"; $.prompt(message); } else { if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { window.location.href = window.location.protocol + "//" + window.location.host + "/Checkout/Items.aspx"; } TrackAddShoppingCartItem(result); //Elimino el mensaje de Empty Items $('.EmptyItems').remove(); $('.jspContainer').show(); $('.checkOut').show(); var text = $('#ctl00_floating_lblCount').text(); //+ " / " + result.Id; var totalItem = parseInt(text ? text : 0); var row = ""; var currency = $('#ddlCurrency').val(); CurrencyConverterWS.CurrencyConversionFromBook(result.Id, currency, $('#ddlSymbol').val(), applyDiscount, function (price) { row = "
\'\'
" + result.Title + "" + price.Price + "" + (price.DiscountedPrice != '' ? "" + price.DiscountedPrice + "" : "") + "
DeleteMove to Wish List
"; $("#tblItems tbody:last").append(row); // Update the total $('#ctl00_floating_lblCount').text(totalItem + 1); $('#ctl00_lblCount').text(totalItem + 1); //Remove bindings for the click to prevent the event fired more than one time $('.btnRemoveFromCart').unbind('click'); //Bind the delete button with the function $('.btnRemoveFromCart').click(function() { $.checkOutManager('removeItem', $(this).attr('itemid')); return false; }); //Remove bindings for the click to prevent the event fired more than one time $('.btnMoveToWishList').unbind('click'); //Move to wish List $('.btnMoveToWishList').click(function() { $.checkOutManager('moveItemToWishList', $(this).attr('itemid')); return false; }); showWindow(true, function() {}); var bookIds = $("#tblItems tr td:first-child").map(function() { return $(this).attr("class"); }).get(); wireUpEvents(bookIds); CurrencyConverterWS.CurrencyConversionForBooksSum(bookIds, currency, $('#ddlSymbol').val(), function (totalPrice) { // Update the total $('#ctl00_floating_lblTotal').text('TOTAL: ' + totalPrice); }, function () { }); }); } } } } } function updateShoppingCartAfterRemove(result) { if (result.Id == -2) { $.prompt("The book you are trying to delete don´t exists."); return; } if (result.Id == -3) { $.prompt("You need to login."); return; } TrackRemoveShoppingCartItem(result); var text = $('#ctl00_floating_lblCount').text(); //+ " / " + result.Id; var totalItem = parseInt(text ? text : 0); // Update the total $('#ctl00_floating_lblCount').text(totalItem - 1); $('#ctl00_lblCount').text(totalItem - 1); //Delete the item $('.' + result.Id).remove(); var bookIds = []; $('#tblItems').find('.pric').each(function () { var book = $(this).parent().attr('class'); if ($.inArray(book, bookIds) == -1) { bookIds.push(book); } }); CurrencyConverterWS.CurrencyConversionForBooksSum(bookIds, $('#ddlCurrency').val(), $('#ddlSymbol').val(), function (totalPrice) { // Update the total $('#ctl00_floating_lblTotal').text('TOTAL: ' + totalPrice); }, function () { }); if ((totalItem - 1) == 0) { //coloco el mensaje de EmptyItems $('.jspContainer').fadeOut(); $('.checkOut').fadeOut(); $('#itemsContainer').append('

You have 0 items in your shopping bag, please add an item to continue.

'); } } function showShoppingCart(items) { var text = $('#msgShooping').text(); $.each(items, function () { text = text + " / " + this.Id; }); $('#msgShooping').text(text); showWindow(true); } function showWindow(show, fadeInCallback) { var top = $(window).scrollTop() + $(window).height() / 2 - $('#popCart').height() / 2; $('.popCart').css("top", top); if (!$('.popCart').is(':visible') && show) { $("#divGrayOutBag").fadeIn(); $(".bag-box").fadeIn(500, fadeInCallback); $(".view-chart").toggleClass("active"); visible = true; } else if (!show) { $(".bag-box").fadeOut(); $("#divGrayOutBag").fadeOut(); $(".view-chart").toggleClass("active"); visible = false; } } function toggleWindow() { //$('#checkoutFloating').toggle("fast"); $(".bag-box").toggle(); $(".view-chart").toggleClass("active"); visible = !visible; }