$(document).ready(function(){ //增加 $('article > .content ').on('click','.button1',function(e) { try { var type = $(this).attr("add_type"); //媽媽餵需求須檢查尺寸 var size = $(this).parents('.productBox').find('.size-select'); if(size.length > 0 && !size.val()) { throw _jsLang.請先選擇尺寸; } //媽媽餵需求須檢查規格三 var sp3 = $(this).parents('.productBox').find('.sp3-select'); if(sp3.length > 0 && !sp3.val()) { throw _jsLang.請先選擇規格三; } //檢查商品ID var id = $(this).attr("sid") || ''; if(!id) { throw _jsLang.無效商品; } //檢查數量 var num = $(this).parents(".productBox").find(".num-select").val() || 0; var tmp_num = $('#add'+type+'_'+id).attr('tmp_num') || 0; num = parseInt(num) + parseInt(tmp_num); if(num <= 0) { throw _jsLang.請選擇數量; } $.ajax({ url:'/activities/ajax/ajax_act_chk_stock.php', type:"POST", cache:false, async:false, data:{Act:'20',SID:id,Amount:num}, error:function(d){ throw _jsLang.資料庫忙線中; }, success:function(d) { if(d == 'STOCK_ERR') { throw _jsLang.商品庫存不足; } $.ajax({ url:'/activities/ajax/act20/ajax_set_cart.php', type:"POST", cache:false, async:true, data:{type:'add',add_type:type,Prod_Sell_ID:id,Amount:num}, dataType: 'json', error:function(d){ throw _jsLang.資料庫忙線中; }, success:function(d){ $("#Act_Title_Box").html(d.Act_Title_Box); $("#Act_Gift_Box").html(d.Act_Gift_Box); $(".Add_Num").html(d.Act_Add_Num); $('#add'+type+'_'+id).attr('tmp_num',num); } }); } }); } catch(e) { alert(e); e.stopImmediatePropagation(); } }); //減少 $(".orderSlide,.addBox").on('click','.delete',function(){ var _this = $(this).parents(".orderSlide"); var _this1 = $(this).parents(".addBox"); $.ajax({ url:'/activities/ajax/act20/ajax_set_cart.php', type:"POST", cache:false, async:true, data:{type:'del',add_type:$(this).attr("add_type"),Prod_Sell_ID:$(this).attr("sid")}, dataType: 'json', error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ $("#Act_Title_Box").html(d.Act_Title_Box); $("#Act_Gift_Box").html(d.Act_Gift_Box); $(".Add_Num").html(d.Act_Add_Num); setTimeout(function(){ _this.find('.pic-bg').text(_jsLang.尚未選購); _this1.find('.pic-bg').text(_jsLang.尚未選購); },650) } }); }); //加入購物車 $("#Act_Title_Box").on('click','.Add_Tmp_To_Cart',function(){ var Diff_Money = $('#Diff_Money').val(); var Add_Num = $('#Add_Num').val(); var Diff_Add_Num = $('#Diff_Add_Num').val(); if(Diff_Money > 0){ //尚未符合活動,確認是否加入購物車 if(confirm(_jsLang.尚未符合滿額贈品加入購物車)){ act20_add_to_cart(); } }else{ if(Diff_Add_Num > 0){ alert(_jsLang.尚有+Diff_Add_Num+_jsLang.件贈品尚未選購) document.getElementById("plusBox").scrollIntoView({ behavior:"smooth", block:"center", inline: "nearest" }) }else{ act20_add_to_cart(); } } }); }); //加入購物車 function act20_add_to_cart(){ $.ajax({ url:'/activities/ajax/ajax_add_to_cart.php', type:"POST", cache:false, async:true, data:{Act_Type:20}, dataType: 'json', error:function(d){ throw _jsLang.資料庫忙線中; }, 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','購物車','加入購物車'); } if(d.GA_conversion && typeof gtag == 'function') { gtag('event', 'conversion', {'send_to':d.GA_conversion}); } if(d.FBQ){eval(d.FBQ)} if(d.GA4 && typeof gtag == 'function') { for(var key in d.GA4) { gtag("event","add_to_cart",{ "items":d.GA4 }); } } window.sy_dataLayer = window.sy_dataLayer || []; sy_dataLayer.push({ 'product': [d.datalayer] }); 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; }; } }); }