/* Created by : Deepak Kumar Shyoran and Ashklekh Gera Date : 01_Nov_14 Description : This file contains all javascript and jquery fuction to add/remove product in cart. */ // Function to fetch cookie value function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i=0; i -1) return true ; else return false ; } /* Search Page Cookeis Handler Function */ function setCookiewithData(id, iscalledFromEmrl) { console.log('------setCookiewithData--------'); if(id != null && id !='') { console.log('id is not null>>>>>>', id); if(id.indexOf('btn_')>-1) { var className = document.getElementById(id).className; if(className == 'btnRemove btn btn-warning btn-xs cart-button-class' && iscalledFromEmrl == true) { alert('The item is already added to the cart'); //popup('The item is already added to the cart','warning'); } else { if(className.indexOf('btn-primary')>-1) { console.log('hiiiiiiiiiiiiii'); addCookiewithData(id); } else{ removecookiesSearchPage(id); } } } } } function removecookiesSearchPage(id) { var pid = id.replace('btn_',''); var cname = 'apex__cfbucket' ; var currentCokkie = getCookie('apex__cfbucket') ; if( currentCokkie.indexOf(pid)>-1) { var allProductArray = currentCokkie.split(','); var newFinal = '' for(var i=0;i-1) { } else{ newFinal += newFinal==''?l:','+l; } } document.getElementById(id).className = 'btn btn-primary btn-xs cart-button-class txtUpr'; document.getElementById(id).innerHTML = 'ADD TO CART'; document.cookie = cname + "=" + newFinal; //refreshCart() ; updateCartValue(); } } function addCookiewithData(id) { if(id != null && id !='') { console.log('id----------' , id); if(id.indexOf('btn_')>-1) { var pid = id.replace('btn_',''); var familyid = 'family_'+pid; var quantity = 1; var price = document.getElementById('price_'+pid).value; var family = document.getElementById(familyid).value; var unit = 1; var cname = 'apex__cfbucket'; var oldvalue = getCookie(cname) ; console.log('cookie dfdkfd---' , pid, familyid, price, family, oldvalue); if(oldvalue.indexOf(pid) == -1){ document.getElementById(id).className = 'btnRemove btn btn-warning btn-xs cart-button-class '; document.getElementById(id).innerHTML = 'REMOVE'; var newCartValue = pid +"$"+ unit + "$" + price + "$" + family ; newCartValue = (oldvalue != null && oldvalue !='' )? oldvalue + ','+ newCartValue: newCartValue; document.cookie = cname + "=" + newCartValue ; popup("This item has been added to your shopping cart", "success"); updateCartValue(); } } } } function clearCookies() { document.cookie = "apex__cfbucket=" + '' ; document.cookie = "apex__cforderId=" + '' ; document.getElementById('cart-total').innerHTML = '0'; } function clearMembershipCookies() { document.cookie = "apex__cfaccountid=" + '' ; document.cookie = "apex__cfmemberorderid=" + '' ; } function updateCartValue() { var cartSize =0; var cartValue = getCookie('apex__cfbucket'); if(cartValue !=null && cartValue !='') { cartSize = cartValue.split(',').length ; } var ele = document.getElementById('cartMessage'); if(ele != null && ele != undefined) { if(cartSize > 0){ ele.style.visibility = 'visible'; } else{ ele.style.visibility = 'hidden'; } } document.getElementById('cart-total').innerHTML = cartSize; if(screen.width < 768) { document.getElementById('cart-total-mobile').innerHTML = cartSize; } } function findProductinCartandSearchArea() { var clas = 'cart-button-class'; allele = document.getElementsByClassName(clas); var cname = 'apex__cfbucket'; var oldvalue = getCookie(cname) ; for(var i = 0 ; i-1) { var t = id.replace('btn_',''); if(oldvalue.indexOf(t)>-1) { //document.getElementById(id).setAttribute('data-original-title','This Product is already added in cart.'); allele[i].innerHTML = 'REMOVE'; //allele[i].style.backgroundColor = '#4D72B8 !important'; allele[i].style.color = 'rgb(243, 250, 252) !important'; allele[i].className = 'btnRemove btn btn-warning btn-xs cart-button-class'; } } } } // Function to change product quantity selected by user from cart page function updateProductQuantity(pId) { var cname = 'apex__cfbucket'; var oldvalue = getCookie(cname); var price = document.getElementById('price_'+pId).value; var family = document.getElementById('family_'+pId).value; var unit = document.getElementById('newQuantity_'+pId).value; unit = parseInt(unit) > 0 ? unit : 1 ; if(isProductInCart(pId)) { var prodToChange = oldvalue.substring(oldvalue.indexOf(pId) ,oldvalue.length ) ; if(prodToChange.indexOf(',') > -1 ) prodToChange = prodToChange.substring(0,prodToChange.indexOf(',') + 1) ; var newCartValue = pId +"$"+ unit + "$" + price + "$" + family ; oldvalue = oldvalue.replace(prodToChange ,""); newCartValue = (oldvalue != null && oldvalue !='' )? oldvalue + ','+ newCartValue: newCartValue; while(newCartValue.indexOf(',,') > -1 ) newCartValue = newCartValue.replace(',,' ,","); document.cookie = cname + "=" + newCartValue ; // document.getElementById('update_'+pId).style.display = "none" ; YUIHideLoading() ; } //refreshCart() ; } // Funtion to show save link when user change the quatity of Product function showSaveLink(pId) { document.getElementById('update_'+pId).style.display = "block" ; } // End Search page cookies function