').insertAfter('.quantity input'); jQuery('.quantity').each(function() { var productid = $("#productid" + indexNumber).val(); var stock = $("#stockproduct" + indexNumber).val(); var productincrement = $("#productincrement" + indexNumber).val(); var productMaxSale = $("#productMaxSale" + indexNumber).val(); var cartList = $(this).closest("li[id*='cartList']"); var spinner = jQuery(this), input = spinner.find('input[type="number"]'), btnUp = spinner.find('.quantity-up'), btnDown = spinner.find('.quantity-down'), min = input.attr('min'), max = input.attr('max'); btnUp.click(function() { var oldValue = parseFloat(input.val()); if (oldValue >= max) { var newVal = oldValue; } else { var newVal = oldValue + parseInt(productincrement); } if(newVal <= productMaxSale){ spinner.find("input").val(newVal); spinner.find("input").trigger("change"); pushGAAddRemove(cartList.attr('index'), Number(productincrement), 'add'); addremoveqty(productid, newVal); } }); btnDown.click(function() { var oldValue = parseFloat(input.val()); if (oldValue <= min) { var newVal = oldValue; } else { var newVal = oldValue - parseInt(productincrement); pushGAAddRemove(cartList.attr('index'), Number(productincrement), 'remove'); addremoveqty(productid, newVal); } spinner.find("input").val(newVal); spinner.find("input").trigger("change"); }); indexNumber++; }); animate(persentase, subtotal, freeongkir); if(getCookie("tbtcTotal") != null){ $("#totalcart").html(getCookie("tbtcTotal")); } jQuery('img[name="ajaxImage"]').each(function() { var imgUrl = $(this).attr('src'); $('img#ajaxImage' + ii).attr('src', imgUrl).load(function() { }).error(function() { $(this).attr('src', ctx + '/assets/desktop/img/alfacart_default.png'); }); ii++; }); } }); } function currencyFormat(x) { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."); } function deleteItemCart(tbtcdid, obj){ var pdpProductId = $("#prodId").val().trim(); var cartProductId = $("#productid" + $(obj).attr('index')).val().trim(); jQuery.ajax({ type : 'GET', url : ctx + "/delete/cart/ajax", data : 'tbtcdid='+tbtcdid, cache: 'false', beforeSend: function(){ jQuery("#ulCart").addClass("reload"); if (pdpProductId == cartProductId) { jQuery("#btnAddtocart").addClass("disabled"); } }, success: function(data){ if (pdpProductId == cartProductId) { jQuery("#btnAddtocart").html("ADD TO CART"); } pushRemoveFromCart($(obj).attr('index')); getViewCart(); } }); } function addremoveqty(productid, qty){ var tbtcId = getCookie("tbtcId"); jQuery.ajax({ type : 'POST', url : ctx + "/add/cart/ajax", data : 'productid='+productid+'&qty='+qty+'&type=true', cache: 'false', beforeSend: function(){ jQuery("#ulCart").addClass("reload"); }, success: function(data){ getViewCart(); /* APDE-483 PWP/GWP */ var pwpGwpList = data.listPwpGwp; //console.log("All PWP GWP =" +JSON.stringify(pwpGwpList)); if(pwpGwpList.length > 0){ constructPwpGwpList(pwpGwpList, 'pdp'); } } }); } function checkIsInCart() { var inCart = "false"; if ($('img[name="ajaxImage"]').size() > 0) { $('img[name="ajaxImage"]').each(function() { if ($(this).attr('pid')==$("#prodId").val().trim()) { inCart = "true"; return false; } }); } return inCart; } function addToCartPdp(productid, qty){ var tbtcId = getCookie("tbtcId"); jQuery.ajax({ type : 'POST', url : ctx + "/add/cart/ajax", data : 'productid='+productid+'&qty='+qty+'&type=true', cache: 'false', beforeSend: function(){ $('body').animate({ scrollTop: 0 }, 200); if (checkIsInCart()=="true") { if ($('img[name="ajaxImage"]').size() > 3) { var index = Number($('img[pid='+productid+']').closest('li').attr('index')); var pos = 0; if (index != 0) { $('li.cart-list:lt('+index+')').each(function() { pos += $(this).height(); }); pos = pos + index; } $('#ulCart').animate({ scrollTop: pos }, 300); setTimeout(function(){ flyToCart($('#imgProduct0'), $('img[pid='+productid+']')); }, 300); } else { setTimeout(function(){ flyToCart($('#imgProduct0'), $('img[pid='+productid+']')); }, 300); } } else { $('#ulCart').animate({ scrollTop: 0 }, 300); //flyToCart($('#imgProduct0'), $('#ulCart')); } //setTimeout(function(){ jQuery("#ulCart").addClass("reload"); //}, 1000); }, success: function(data){ getViewCart(); jQuery("#btnAddtocart").html("UPDATE CART"); // to show list pwp gwp promotion var pwpGwpList = data.listPwpGwp; //console.log("All PWP GWP =" +JSON.stringify(pwpGwpList)); if(pwpGwpList.length > 0){ constructPwpGwpList(pwpGwpList, 'pdp'); } //jQuery("#btnAddtocart").removeClass("disabled"); } }); } /* APDE-483 PWP/GWP */ function showPromotionList(){ jQuery.ajax({ type : 'POST', url : ctx + "/product/promotion", data : 'type=true', cache: 'false', success: function(data){ //console.log("JSON listDataPromo : " + JSON.stringify(data.listPromotion)); if(data.success == true){ costructAllPwpGwpList(data.listPromotion);	} } }); } /* APDE-483 PWP/GWP */ function costructAllPwpGwpList(listPromotion){ var strHtml = '