/* Persistant Cart (universal cart) Javascript */ /* --------------------------------------------- */ // Commands // persistantCartCommands[0] = "show" action // persistantCartCommands[1] = "addProduct" action // persistantCartCommands[2] = "addEnsemble" action // persistantCartCommands[3] = "remove" action // persistantCartCommands[4] = "addCatalogItems" action var persistantCartCommands = new Array(6); persistantCartCommands[0] = "/catalog/personalize3/universal_cart.jsp"; persistantCartCommands[1] = "/checkout/add_item_pc.cmd"; persistantCartCommands[2] = "/checkout/add_items_pc.cmd"; persistantCartCommands[3] = "/checkout/delete_item_from_order.cmd"; persistantCartCommands[4] = "/checkout/add_catalog_order_items_to_basket.cmd"; persistantCartCommands[5] = "/personalize3/checkout/delete_item_from_personalization_queue.cmd"; persistantCartCommands[6] = "/personalize3/checkout/update_item_quantity.cmd"; var requestURL = ""; var persistantCartContainerId = "#widget-ucart"; var persistantCartCloseButClass = ".widget-ucart-close-but"; var hideTimeOuts= new Array(); var loading = false; // 2012/03/21 fix bug 292, add by xhji // Because the preview image's z-index is 10000, // so using 20000 to show popup cart using topest level var zIndexOfCartHide = 1; var zIndexOfCartShow = 20000; // 2012/03/21 fix bug 292, add by xhji /* Function(s) to Show the Basket Layer */ function showBasket(action,params) { if(loading == true) return false; showloading(); if(action == "show") { requestURL = persistantCartCommands[0]; } else if(action == "addProduct") { requestURL = persistantCartCommands[1];} else if(action == "addEnsemble") { requestURL = persistantCartCommands[2];} else if(action == "remove") { requestURL = persistantCartCommands[3];} else if(action == "addCatalogItems") { requestURL = persistantCartCommands[4];} else if(action == "remove_from_personalization") { requestURL = persistantCartCommands[5];} else if(action == "update_item_quantity") { requestURL = persistantCartCommands[6];} else { alert("missing action"); } requestURL = requestURL; params = "isAjaxRequest=Y&ts=" + timestamp() + "&action=" + action + "&" + params; loading = true; callback = function(){}; $.ajax({ type: "POST", url: requestURL, data: params, dataType: "html", timeout: 150000, cache: false, global:false, success: function(data) { loading = false; hideloading(); $(persistantCartContainerId).append(data); // 2012/03/21 fix bug 292, add by xhji $(persistantCartContainerId).css("z-index", zIndexOfCartShow); // 2012/03/21 fix bug 292, add by xhji $(persistantCartContainerId).show(); //added by haitao 2013/12/12 refreshQuickCart(); //added by haitao 2013/12/12 return true; }, error: function() { loading = false; hideloading(); return false; } }); }; function refreshQuickCart(){ $.getJSON( "/catalog/personalize3/universal_cart_include.jsp", function( json ) { $( "#quick_cart_item_amount_span" ).html( json.item_amount ); $( "#quick_cart_item_amount_input" ).val( json.item_amount ); $( "#quick_cart_sub_total_span" ).html( json.sub_total ); $( "#quick_cart_sub_total_input" ).val( json.sub_total ); }); } function hideBasket() { // 2012/03/21 fix bug 292, add by xhji $(persistantCartContainerId).css("z-index", zIndexOfCartHide); // 2012/03/21 fix bug 292, add by xhji $(persistantCartContainerId).hide(); $(persistantCartContainerId).remove(); }; function showloading() { $(persistantCartContainerId).remove(); //load, position, show new cart var loading = '
'; $("body").append(loading); positionPersistantCart(); $(persistantCartContainerId).show(); // add an event for close layer. //$(persistantCartCloseButClass).click(function() { hideBasket(); }); }; function hideloading() { $(persistantCartContainerId + " *").remove(); $(persistantCartContainerId).html(""); }; function addToCart() { params = "&productName=" + $("input[name=productName]").val() + "&productId=" + $("input[name=productId]").val() + "&categoryId=" + $("input[name=categoryId]").val() + "&parentCategoryId=" + $("input[name=parentCategoryId]").val() + "&subCategoryId=" + $("input[name=subCategoryId]").val() + "&quantity=" + $("input[name=quantity]").val() + "&productVariantId=" + $("input[name=productVariantId]").val(); showBasket('addProduct',params); }; function wishListAddToCart(params) { /* params = "&productId=" + $("input[name=productId]").eq(x).val() + "&productName=" + $("input[name=productName]").val() + "&categoryId=" + $("input[name=categoryId]").eq(x).val() + "&parentCategoryId=" + $("input[name=parentCategoryId]").eq(x).val() + "&subCategoryId=" + $("input[name=subCategoryId]").eq(x).val() + "&quantity=" + $("input[name=quantity]").eq(x).val() + "&productVariantId=" + $("input[name=productVariantId]").eq(x).val(); */ showBasket('addProduct',params); }; function addCatalogOrderItemsToCart() { var userAddressId = $("select[name=userAddressId]").val() if ($("select[name=userAddressId]").val() == "Someone Else" && $("input[name=nickname]").val()) { userAddressId = $("input[name=nickname]").val(); } params = "action=addCatalogItems" + "&userAddressId=" + userAddressId; if ($("input[name=catalogCode]").val()) { params += "&catalogCode=" + $("input[name=catalogCode]").val(); } $("input[name='itemNumber']").each( function() { params = params + "&itemNumber=" + this.value; }); $("input[name='quantity']").each( function() { params = params + "&quantity=" + this.value; }); params = params + "&itemCount=" + $("input[name='quantity']").length; showBasket('addCatalogItems',params); }; function addEnsembleToCart(type) { params = "&productName=" + $("input[name=productName]").val() + "&ensembleId=" + $("input[name=ensembleId]").val() + "&categoryId=" + $("input[name=categoryId]").val() + "&parentCategoryId=" + $("input[name=parentCategoryId]").val(); // iterate through products for productIds /* $(".the-product-ids").each(function() { params = params + "&" + $(this).attr("name") + "=" + $(this).val(); }); */ // iterate through products in the ensemble for variant id $(".the-variant-ids").each(function() { params = params + "&" + $(this).attr("name") + "=" + $(this).val(); }); // iterate through products for qty $(".the-variant-qtys").each(function() { if( type == 'all' ) { $(this).val("1"); params = params + "&" + $(this).attr("name") + "=1"; } else { params = params + "&" + $(this).attr("name") + "=" + $(this).val(); } }); params = params + "&productCount=" + $(".the-variant-ids").length; showBasket('addEnsemble',params); }; function updateHeader(amt) { if(amt == 1) { $("#widget-ucart-item-count").text(amt + " item(s)"); } else { $("#widget-ucart-item-count").text(amt + " item(s)");} }; function errorAppend(area,msg) { $(area).html(msg.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/'/g, "'")); $(area).show(); }; function resetErrorFields() { $(".glo-tex-error").hide(); $(".glo-tex-error").html(""); }; function messageAppend(area,msg) { $(area).html(msg); $(area).show(); }; function resetMessageFields() { $(".glo-tex-info").hide(); }; function clearAllTimeouts() { for(x = 0; x < hideTimeOuts.length; x++) { clearTimeout(hideTimeOuts[x]); } }; function timestamp() { return new Date().getTime(); } //edit this function to update the setup function setupPersistantCartButtons() { $(persistantCartCloseButClass).unbind("click").click(function() { hideBasket(); shoppingBagBut = $("#widget-header-active-link").eq(0); $(shoppingBagBut).attr("id","") $(shoppingBagBut).mouseout(); }); $(persistantCartCloseButClass).attr("href","javascript:void(0)"); clearAllTimeouts(); }; //edit this function to position cart. function positionPersistantCart() { // draw focus near this /*window.location += "#";*/ //turn on my account link, if not already on if(!($("#widget-ucart-but #widget-header-active-link").size() > 0)) { $("#widget-ucart-but img").attr("id", "widget-header-active-link").attr("src","/assets/images/tex/tex-header-shopping-bag-active.gif"); } };