//----------------------------------------------------------------- // Licensed Materials - Property of IBM // // WebSphere Commerce // // (C) Copyright IBM Corp. 2011, 2019 All Rights Reserved. // // US Government Users Restricted Rights - Use, duplication or // disclosure restricted by GSA ADP Schedule Contract with // IBM Corp. //----------------------------------------------------------------- /** * @fileOverview This file provides the common functions which are specific to the Mini Shopping cart */ /** * map order_updated to all the services that result in changes to an order * @static */ var order_updated = { 'AjaxAddOrderItem':'AjaxAddOrderItem', 'AddOrderItem':'AddOrderItem', 'AjaxAddOrderItemWithShipingInfo':'AjaxAddOrderItemWithShipingInfo', 'AjaxDeleteOrderItem':'AjaxDeleteOrderItem', 'AjaxUpdateOrderItem':'AjaxUpdateOrderItem', 'AjaxUpdateOrderShippingInfo':'AjaxUpdateOrderShippingInfo', 'AjaxOrderCalculate':'AjaxOrderCalculate', 'AjaxLogoff':'AjaxLogoff', 'AjaxSetPendingOrder':'AjaxSetPendingOrder', 'AjaxUpdatePendingOrder':'AjaxUpdatePendingOrder', 'AjaxSingleOrderCancel':'AjaxSingleOrderCancel', 'AjaxUpdateRewardOption':'AjaxUpdateRewardOption', 'AjaxAddOrderItem1':'AjaxAddOrderItem1', 'AjaxPromotionCodeManage':'AjaxPromotionCodeManage', 'TGGOrderItemAddressShipMethodUpdate':'TGGOrderItemAddressShipMethodUpdate', 'TGGOrderItemDeliveryShipModeUpdateFinal':'TGGOrderItemDeliveryShipModeUpdateFinal', 'AjaxTGGFindDelivery':'AjaxTGGFindDelivery', 'TGGDeliveryChangeMethod':'TGGDeliveryChangeMethod', 'TGGOrderItemDeliveryAddressUpdate':'TGGOrderItemDeliveryAddressUpdate', 'AjaxTGGServicesOnlineOrderUpdate':'AjaxTGGServicesOnlineOrderUpdate' }; var duplicate_update = {'AjaxPromotionCodeManage':'AjaxPromotionCodeManage', 'TGGOrderItemDeliveryAddressUpdate':'TGGOrderItemDeliveryAddressUpdate' }; /** This variable indicates whether the mini cart drop down is updated or not. */ var dropdownUpdated = false; /** This is variable indicates wether the mini cart drop down is being initialized. */ var dropdownInit = false; /** This variable keeps track of the mouseover on the mini cart. */ var timer; /** This variable is used for checking cookies update when item is add in cart */ var isUpdateCookie = false; var productAddedList = new Object(); var cartHeight = 0; var cartTimeOut =0 ; /** * Declares a new render context for the Mini Shopping Cart. */ //wc.render.declareContext("MiniShoppingCartContext",{status:"init"},""); /** * Declares a new render context for the Mini Shopping Cart contents. */ wc.render.declareContext("MiniShopCartContentsContext",{status:"init", relativeId:"", contentId:"" ,contentType:""},""); /** * Declares a new render context for the Mini Shopping Cart dropdown contents. */ wc.render.declareContext("MiniShopCartDropDownContext",null,""); /** * * Displays the dropdown content of the mini shopping cart when keyboard keys are used to expand/collapse the dropdown. * * @param {object} event The event to retrieve the input keyboard key * @param {string} relativeId The id of a placeholder element to position the dropdown relatively * @param {string} contentId The id of the content pane containing the mini shopping cart dropdown contents * @param {string} contentType The content that will be shown in the expanded mini shopping cart dropdown. */ function showMiniShopCartDropDownEvent(event,relativeId,contentId,contentType){ console.debug(event.keyCode); if(event.keyCode == dojo.keys.DOWN_ARROW || event.keyCode == dojo.keys.ENTER){ showMiniShopCartDropDown(relativeId,contentId,contentType,''); dojo.stopEvent(event); } } function toggleMiniShopCartDropDownEvent(event,relativeId,contentId,contentType){ console.debug(event.keyCode); if(event.keyCode == dojo.keys.DOWN_ARROW || event.keyCode == dojo.keys.ENTER){ toggleMiniShopCartDropDown(relativeId,contentId,contentType); dojo.stopEvent(event); } } /** * Displays the dropdown content of the mini shopping cart when the user hovers over the * mini shopping cart if the contents are up-to-date or retrieve the latest contents from server. * * @param {string} relativeId The id of a placeholder element to position the dropdown relatively * @param {string} contentId The id of the content pane containing the mini shopping cart dropdown contents * @param {string} contentType The content that will be shown in the expanded mini shopping cart dropdown. */ function showMiniShopCartDropDown(relativeId,contentId,contentType,actionId){ //console.log('showMiniShopCartDropDown'); if (document.querySelector('body').classList.contains('minicart-modal-open')){ closeMiniShopCartModal(); } if(!dropdownInit && wc.render.getRefreshControllerById("MiniShopCartContentsController") != null && wc.render.getRefreshControllerById("MiniShopCartContentsController").url != ""){ dropdownInit = true; if(!dropdownUpdated){ showMiniShopCartModal(); destroyDialog(); var params = {}; params["status"] = 'load'; params["relativeId"] = relativeId; params["contentId"] = contentId; params["contentType"] = contentType; params["page_view"] = 'dropdown'; wc.render.updateContext("MiniShopCartContentsContext", params); } } if (dropdownInit == true && !document.querySelector('body').classList.contains('minicart-modal-open') ) { showMiniShopCartModal(); } } function showMiniShopCartModal(){ document.querySelector('body').classList.add('minicart-modal-open'); } function closeMiniShopCartModal(){ document.querySelector('body').classList.remove('minicart-modal-open'); if(null != document.getElementById('new_item_container')) document.getElementById('new_item_container').style.display='none'; } function toggleMiniShopCartDropDown(relativeId,contentId,contentType){ console.log('toggleMiniShopCartDropDown'); if (dojo.hasClass(relativeId, "selected")) { var content = dijit.byId(contentId); if (content) { content.hide(); } } else { showMiniShopCartDropDown(relativeId,contentId,contentType,""); } } /** * Declares a new refresh controller for the Mini Shopping Cart contents. */ wc.render.declareRefreshController({ id: "MiniShopCartContentsController", renderContext: wc.render.getContextById("MiniShopCartContentsContext"), url: "", formId: "" /** * Indicate that the mini cart contents are out of date upon an order change action. * This function is called when a modelChanged event is detected. * * @param {string} message The model changed event message * @param {object} widget The registered refresh area */ ,modelChangedHandler: function(message, widget) { var controller = this; var renderContext = this.renderContext; if(message.actionId in order_updated || message.actionId == 'AjaxDeleteOrderItemForShippingBillingPage'){ if(message.actionId == 'AddOrderItem' || message.actionId == 'AjaxAddOrderItem' || message.actionId=='AjaxDeleteOrderItem') { renderContext.properties.status = "load"; renderContext.properties.relativeId = "minicartSection"; renderContext.properties.contentId = "quick_cart_container"; renderContext.properties.contentType = "orderItemsList"; renderContext.properties.page_view = "dropdown"; renderContext.properties.flag = "true" renderContext.properties.deleteCartCookie = true; renderContext.properties.fetchCartContents = true; renderContext.properties.serviceId = message.serviceId; widget.refresh(renderContext.properties); isUpdateCookie = true; dropdownUpdated = true; } if(renderContext.properties.refreshCart == 'true') { delete renderContext.properties['load']; delete renderContext.properties['relativeId']; delete renderContext.properties['contentId']; delete renderContext.properties['contentType']; delete renderContext.properties['page_view']; delete renderContext.properties['flag']; delete renderContext.properties['fetchCartContents']; renderContext.properties.deleteCartCookie = true; widget.refresh(renderContext.properties); } } } /** * Refreshes the mini shopping cart contents since it is out of date. * This function is called when a render context changed event is detected. * * @param {string} message The model changed event message * @param {object} widget The registered refresh area */ ,renderContextChangedHandler: function(message, widget) { var controller = this; var renderContext = this.renderContext; if(renderContext.properties.refreshCart == 'true') { if(controller.testForChangedRC(["status"])){ renderContext.properties.deleteCartCookie = true; widget.refresh(renderContext.properties); } } else { if(!dropdownUpdated){ renderContext.properties.fetchCartContents = true; dropdownUpdated = true; widget.refresh(renderContext.properties); } } } /** * Displays and positions the mini shop cart contents. * This function is called after a successful refresh. * * @param {object} widget The registered refresh area */ ,postRefreshHandler: function(message, widget) { dropdownInit = false; var controller = this; var renderContext = this.renderContext; destroyDialog("quick_cart_container"); if(renderContext.properties.refreshCart == 'true') { if (!multiSessionEnabled) { updateCartCookie(); resetDeleteCartCookie(); delete renderContext.properties['refreshCart']; dropdownUpdated = false; } } else { if(isUpdateCookie) { if (!multiSessionEnabled) { updateCartCookie(); } if (!multiSessionEnabled) { resetDeleteCartCookie(); } isUpdateCookie = false; showMiniShopCartDropDown(renderContext.properties.relativeId, renderContext.properties.contentId, renderContext.properties.contentType,renderContext.properties.serviceId); if(null != document.getElementById("ProdNameAddedToMC_"+shoppingActionsJS.productIdAdded)){ document.getElementById("new_item_container").style.display="block"; var prodNameFromMC= document.getElementById("ProdNameAddedToMC_"+shoppingActionsJS.productIdAdded).value; document.getElementById("new_item_name_container").innerHTML = prodNameFromMC.replace('%22', '"'); } } else if(!isUpdateCookie) { loadMiniCart(tggCurrencyId, tggLangId); } } // Closing top else statement } // closing post refresh }) /** * Store the current mini cart information in the mini cart cookie. */ function updateCartCookie(){ //Save current order information into cookie if(document.getElementById("currentOrderQuantity") != null && document.getElementById("currentOrderAmount") != null && document.getElementById("currentOrderCurrency") != null && document.getElementById("currentOrderId") != null && document.getElementById("currentOrderLanguage") != null) { var cartQuantity = document.getElementById("currentOrderQuantity").value; var cartAmount = document.getElementById("currentOrderAmount").value; var cartCurrency = document.getElementById("currentOrderCurrency").value; var cartLanguage = document.getElementById("currentOrderLanguage").value; var cartOrderId = document.getElementById("currentOrderId").value; //Clear out previous cookies var orderIdCookie = getCookie("WC_CartOrderId_"+WCParamJS.storeId); if(orderIdCookie != null){ dojo.cookie("WC_CartOrderId_"+WCParamJS.storeId, null, {expires:-1,path:'/'}); var cartTotalCookie = getCookie("WC_CartTotal_"+orderIdCookie); if(cartTotalCookie != null){ dojo.cookie("WC_CartTotal_"+orderIdCookie, null, {expires:-1,path:'/'}); } } dojo.cookie("WC_CartOrderId_"+WCParamJS.storeId, cartOrderId, {path:'/'}); if(cartOrderId != ""){ dojo.cookie("WC_CartTotal_"+cartOrderId, cartQuantity + ";" + cartAmount + ";" + cartCurrency + ";" + cartLanguage, {path:'/'}); } } } function setProductAddedList(newProductAddedList) { productAddedList = newProductAddedList; } /** * Populates the Product Added dropdown upon an add to cart action. */ function populateProductAddedDropdown(){ var search = '"'; var replaceStr = '\\\\"'; for(productId in productAddedList){ var productDetails = productAddedList[productId]; if(document.getElementById('MiniShopCartAddedProdName_'+productId) != null && productDetails[0] != null){ document.getElementById('MiniShopCartAddedProdName_'+productId).innerHTML = productDetails[0]; } if(document.getElementById('MiniShopCartAddedProdImgSrc_'+productId) != null && productDetails[1] != null){ document.getElementById('MiniShopCartAddedProdImgSrc_'+productId).src = productDetails[1]; document.getElementById('MiniShopCartAddedProdImgSrc_'+productId).alt = productDetails[0]; } if(document.getElementById('MiniShopCartAddedProdPrice_'+productId) != null && productDetails[2] != null){ document.getElementById('MiniShopCartAddedProdPrice_'+productId).innerHTML = productDetails[2]; } if(document.getElementById('MiniShopCartAddedProdQty_'+productId) != null && productDetails[3] != null){ document.getElementById('MiniShopCartAddedProdQty_'+productId).innerHTML = productDetails[3]; } if(document.getElementById('MiniShopCartAddedProdAttr_'+productId) != null && productDetails[4] != null){ document.getElementById('MiniShopCartAddedProdAttr_'+productId).innerHTML = ""; for(attrName in productDetails[4]){ attrValue = productDetails[4][attrName] if (attrValue != null && attrValue !='undefined'){ attrValue = attrValue.replace(replaceStr, search).replace(/&/g,"&").replace(/'/g,"'").replace(/"/g,'"'); } document.getElementById('MiniShopCartAddedProdAttr_'+productId).innerHTML += '