$(document).ready(function(){ //增加 $('.combosBox').on('click','.button1',function(e) { try { var _this = $(this), group = _this.attr("group"), parent = _this.attr("parent"); parent_no = _this.attr("parent_no"); //媽媽餵需求須檢查尺寸 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.請先選擇規格三; } //檢查數量 var num = $(this).parents(".productBox").find(".num-select").val() || 0; if(num <= 0) { throw _jsLang.請選擇數量; } //檢查商品ID var id = $(this).attr("sid") || ''; if(!id) { throw _jsLang.無效商品; } $.ajax({ url:'/activities/ajax/ajax_act_chk_stock.php', type:"POST", cache:false, async:false, data:{Act:'8',SID:id,Amount:num}, error:function(d){ throw _jsLang.資料庫忙線中; }, success:function(d) { if(d == 'STOCK_ERR') { throw _jsLang.商品庫存不足; } $.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,parent_no:parent_no}, error:function(d){ throw _jsLang.資料庫忙線中; }, 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]); } } } }); } }); } catch(e) { alert(e); e.stopImmediatePropagation(); } }); //減少 $(".user-orderBox").on('click','.delete',function(){ var id = $(this).attr("sid"), group = $(this).attr("group"), parent = $(this).attr("parent"); parent_no = $(this).attr("parent_no"); $.ajax({ url:'/activities/ajax/act8/ajax_set_cart.php', type:"POST", cache:false, async:true, data:{type:'del',group:group,id:id,parent:parent,parent_no:parent_no}, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, 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")+","; }); } console.log("8-1") $.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_no:$(this).attr("prod_no"),Prod:Prod}, dataType: 'json', error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ if(d.Msg) { alert(d.Msg); } else { 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; }; } } }); }); }); 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 = '
'+product_title+'
'+product_price+'
'+_jsLang.刪除+'
'; var now = _this.parents('.contentBox').attr('class'); order_animate(product,html,'.'+_this.parents('.combos').attr("group"),product_num); } function order_animate(product,html,combos,num){ var choseImg = product.find('.productImg'), Img_html = choseImg.clone().addClass('moveImg'), choseImg_top = product.offset().top, choseImg_left = product.offset().left, choseImg_width = product.width(), choseImg_height = product.height(); if($('.user-orderBox').find(combos).length!=0){ var orderBox_change = $('.user-orderBox').find(combos).eq(0), changeBox_top = orderBox_change.offset().top, changeBox_left = orderBox_change.offset().left, changeBox_width = orderBox_change.width(), changeBox_height = orderBox_change.height(); $('body').append(Img_html); $('.moveImg').css({ 'top':choseImg_top, 'left':choseImg_left, 'width':choseImg_width, 'height':choseImg_height }).animate({ 'top':changeBox_top, 'left':changeBox_left, 'width':changeBox_width, 'height':changeBox_height },300,function(){ $(this).remove(); orderBox_change.after(html).remove(); num = num-1; if(num >0){ order_animate(product,html,combos,num); } }); } }