$(document).ready(function(){ //增加 $('.combosBox').on('click','.button1',function(e){ var _this = $(this), id = _this.attr("sid"), group = _this.attr("group"), num = _this.parents(".productBox").find(".num-select").val(), parent = _this.attr("parent"); if(id && num){ $.ajax({ url:'/activities/ajax/act8/ajax_set_cart.php', type:"POST", cache:false, async:true, data:{type:'add',group:group,id:id,Amount:num,parent:parent}, error:function(d){ alert(d.responseText); }, success:function(d){ $("#Act_Title_Box").html(d); if($("#Alert_Msg").val()){ alert($("#Alert_Msg").val()); }else{ order_add(_this); var $update = $("#Update_Num").val().split(','); for(var $i=0;$i<$update.length;$i++){ var $arr = $update[$i].split(':'); $("#Update_Num"+$arr[0]).html($arr[1]); } } } }); }else{ if(!id){ alert('請選擇尺寸與規格'); }else if(!num){ alert('請選擇數量'); } return false; } }); //減少 $(".user-orderBox").on('click','.delete',function(){ var id = $(this).attr("sid"), group = $(this).attr("group"), parent = $(this).attr("parent"); $.ajax({ url:'/activities/ajax/act8/ajax_set_cart.php', type:"POST", cache:false, async:true, data:{type:'del',group:group,id:id,parent:parent}, error:function(d){ alert(d.responseText); }, success:function(d){ $("#Act_Title_Box").html(d); var $update = $("#Update_Num").val().split(','); for(var $i=0;$i<$update.length;$i++){ var $arr = $update[$i].split(':'); $("#Update_Num"+$arr[0]).html($arr[1]); } } }); }); //加入購物車 $("#Act_Title_Box").on('click','.Add_Tmp_To_Cart',function(){ //固定模式 if($(this).attr("type") == "Stable"){ var Prod = ""; $(".orderProduct .button1").each(function(){ Prod += $(this).attr("group")+"="+$(this).attr("sid")+","; }); } $.ajax({ url:'/activities/ajax/ajax_add_to_cart.php', type:"POST", cache:false, async:true, data:{Act_Type:$(this).attr("act_type"),ID:$(this).attr("prod_id"),Prod:Prod}, dataType:'json', error:function(d){ alert(d.responseText); }, success:function(d){ var msg = d.split(","); if(msg[0] == "Msg"){ alert(msg[1]); }else{ switch(d.Status){ case "RET_SUCCESS": if(d.GA4 && typeof gtag == 'function') { for(var key in d.GA4) { gtag("event","add_to_cart",{ "items":d.GA4 }); } } alert("加入購物車成功"); window.location.reload(); break; case "RET_NO_MEMBER_NO": alert("欲購買紅利兌換商品請先登入會員並完成會員認證"); break; case "RET_RBONUS_OUT": alert("紅利不足"); break; case "RET_ERROR": alert("資料庫忙線中"); break; case "RET_PROD_ERROR": alert("商品已下架"); break; case "RET_NO_PROD": alert("請選擇商品"); break; case "RET_STOCK_ERROR": alert("商品庫存不足"); break; default: alert("資料庫忙線中"); break; }; } } }); }); }); function order_add(_this){ var product = _this.parents('.productBox'), product_title = product.find('.title').html(), product_img = product.find('img').attr('src'), product_price = product.find('.font-delete').html(), product_num = product.find('.num-select').val(), product_group = _this.attr("group"), product_id = _this.attr("sid"), product_parent = _this.attr("parent"); var n = _this.parents('.combos').index(); var html = '