$(document).ready(function(){ /*上方banner廣告圖*/ $(".top_productbox").owlCarousel({ loop : false, responsive:{ 0:{ items : 2 }, 320:{ items : 3 }, 480:{ items : 6 }, 660:{ items : 8 }, 768:{ items : 9 }, 960:{ items : 10 }, 1023:{ items : 12 } }, nav : true, }); //增加商品 $(".col-60").on("click",".add_to_tmp",function(){ var _this = $(this); _item = _this.parents(".prodbox"); $.ajax({ url:"/activities/ajax/act14/ajax_set_cart.php", type:"POST", data:{type:'add',Prod_Sell_ID:_this.attr("SID"),Amount:_item.find(".amountBox").val()}, success:function(d){ $("#Total_Div").html(d); _item.addClass("click"); _this.removeClass("add_to_tmp").addClass("del_from_tmp"); _this.html('取消選購'); } }); }); //取消商品 $(".col-60").on("click",".del_from_tmp",function(){ var _this = $(this); _item = _this.parents(".prodbox"); $.ajax({ url:"/activities/ajax/act14/ajax_set_cart.php", type:"POST", data:{type:'del',Prod_Sell_ID:_this.attr("SID")}, success:function(d){ $("#Total_Div").html(d); _item.removeClass("click"); _this.removeClass("del_from_tmp").addClass("add_to_tmp"); _this.html('選購'); } }); }); //加入購物車 $("#Total_Div").on('click','#Add_Tmp_To_Cart',function(){ var Prod = ""; $(".prodbox").each(function(){ Prod += $(this).find(".amountBox").val()+","+$(this).find(".add_to_cart").attr("SID")+"-"; }); $.ajax({ url:'/activities/ajax/ajax_add_to_cart.php', type:"POST", cache:false, async:true, dataType: 'json', data:{Act_Type:$(this).attr("act_type"),Prod:Prod}, error:function(d){ alert(d.responseText); }, success:function(d){ switch(d.Status){ case "RET_SUCCESS": if(d.GA && typeof ga == 'function') { for(var key in d.GA) { ga('ec:addProduct',d.GA[key]); } ga('ec:setAction','add'); ga('send','event','購物車','加入購物車'); } 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; }; } }); }); });