$(document).ready(function(){ //選購 $('.addButton').on('click',function(e){ const scrollOffset = $('.userBox').offset().top - $('.header-01').height() var id = '', msg = '', num = parseInt($('.select_num').val())+ parseInt($('#Left_Total').val()); if(num > 5){ num = 5; } if($('.select_num').prev(".sp3-select").length > 0){ id = $('.select_num').prev(".sp3-select").val(); msg = _jsLang.請選擇規格三; }else if($('.select_num').prev(".select_size").length > 0){ id = $('.select_num').prev(".select_size").val(); msg = _jsLang.請選擇尺寸; }else{ id = $('.select_num').attr("sid"); } if(id && num !== 0){ $.ajax({ url:'/tw/activities/ajax/act5/ajax_set_cart.php', type:"POST", cache:false, async:true, data:{type:'add',add_type:'1',id:id,num:num}, error:function(d){ alert(d.responseText); }, success:function(d){ $("#Act_Title_Box").html(d); $("#Left_Total_Box").html($("#Left_Total").val()); $('html, body').animate({ scrollTop: scrollOffset }, 750) } }); }else if(num == 0){ }else{ alert(msg); return false; } }); //減少 $(".orderSlide").on('click','.delete',function(){ $.ajax({ url:'/tw/activities/ajax/act5/ajax_set_cart.php', type:"POST", cache:false, async:true, data:{type:'del',add_type:$(this).attr("add_type"),id:$(this).attr("del_id")}, error:function(d){ alert(d.responseText); }, success:function(d){ $("#Act_Title_Box").html(d); $("#Left_Total_Box").html($("#Left_Total").val()); $("#Right_Total_Box").html($("#Right_Total").val()); var $color = $("#Color_Arr").val().split('-'); for($i=0;$i<$color.length;$i++){ var _color = $color[$i].split(','); $(".colorbox[group='"+_color[0]+"']").find(".select_num").val(_color[1]); } } }); }); //加購 $('article > .content-add ').on('click','.button1',function(){ var id = $(this).attr("SID"); var num = $(this).parents(".productBox").find(".num-select").val(); if(id && num >0){ $.ajax({ url:'/tw/activities/ajax/act5/ajax_set_cart.php', type:"POST", cache:false, async:true, data:{type:'add',add_type:'2',id:id,num:num}, error:function(d){ alert(d.responseText); }, success:function(d){ $("#Act_Title_Box").html(d); $("#Right_Total_Box").html($("#Right_Total").val()); } }); }else{ if(!id){ alert(_jsLang.請選擇尺寸與規格); }else if(num <=0){ alert(_jsLang.請選擇數量); } return false; } }); //加入購物車 $(".inner").on('click','.Add_Tmp_To_Cart',function(){ $.ajax({ url:'/tw/activities/ajax/ajax_add_to_cart.php', type:"POST", cache:false, async:false, dataType: 'json', data:{Act_Type:$(this).attr("act_type")}, error:function(d){ alert(d.responseText); }, success:function(d){ 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 }); } } gtag('event', 'conversion', {'send_to': 'AW-740646101/68PRCLqeiJ8BENW5leEC'}); alert(_jsLang.加入購物車成功); window.location.reload(); break; case "RET_NO_MEMBER_NO": alert(_jsLang.欲購買紅利兌換商品請先登入會員並完成會員認證); break; case "RET_RBONUS_OUT": alert(_jsLang.紅利不足); break; case "RET_ERROR": alert(_jsLang.資料庫忙線中); break; case "RET_PROD_ERROR": alert(_jsLang.商品已下架); break; case "RET_NO_PROD": alert(_jsLang.請選擇商品); break; case "RET_STOCK_ERROR": alert(_jsLang.商品庫存不足); break; case "RET_LIMIT_ERROR": alert(_jsLang.數量超過限購量) break; default: alert(_jsLang.資料庫忙線中); break; }; } }); }); });