error code: 1015AddCart") return false} if(moi.isEvent("cancelBuynow")&&type==='buy'){moi.onEvent("cancelBuynow") return false}} if(this.product.available===0){moi.alertInfo({content:lang.checkout.quantity_empty});return false;} if(this.product.status===0&&moi.getUrlParam("preview")){moi.alertInfo({content:"当前为预览链接不可操作"});return false;} if(type==="cart"&&!this.cartShake){return false;} if(type==="buy"&&!this.buyShake){return false;} if(this.productOptionType!=="all"){for(let i=0;iitem.add_quantity).length){moi.alertInfo({content:lang.checkout.quantity_empty});return;} if(this.productOptionType==="all"&&!this.params.sku_value&&this.optionLength){$("html, body").animate({scrollTop:this.skuNode.find(".sku_option-template_all").eq(0).offset().top-200});moi.alertInfo({content:lang.product.please_select_sku.replace("{sku}",this.product.options[0].name)});return;} return true;};omesaasProduct.prototype.getEcData=function(){const self=this;return{ec_data_id:self.product.id,ec_data_from:self.data_from,ec_data_name:encodeURIComponent(self.product.title),ec_data_price:self.params.price,ec_data_discount_price:self.params.price,ec_data_spu:self.product.spu,ec_data_image:self.product.src,ec_data_category:self.product.product_type,ec_data_uniq_id:self.product.id,ec_data_sku:self.params.sku,ec_data_sku_code:self.params.sku_code,ec_data_quantity:self.params.quantity,ec_data_sku_name:self.params.sku_value||"",ec_currency_code:self.ec_currency_code,ec_data_action_type:""};};omesaasProduct.prototype.share=function(platform){const self=this;const ec_data={ec_data_id:self.product.id,ec_data_from:self.data_from,ec_data_name:encodeURIComponent(self.product.title),ec_data_price:self.product.variant.price,ec_data_discount_price:self.product.variant.price,ec_data_spu:self.product.spu,ec_data_image:self.product.src,ec_data_category:self.product.product_type,ec_data_uniq_id:self.product.id,ec_data_sku:self.product.variant.sku,ec_data_sku_code:self.product.variant.sku_code,ec_data_quantity:1,ec_data_sku_name:self.product.variant.sku_value,ec_currency_code:self.ec_currency_code,ec_data_action_type:""};ec_data.ec_data_action_type="share_product";callback_share_product(ec_data,platform);};omesaasProduct.prototype.callbackAddToCart=function(){const self=this;const ec_data=self.getEcData();ec_data.ec_data_action_type="add_to_cart";callback_add_to_cart(ec_data);};omesaasProduct.prototype.getCustomAttr=function(attr){return attr.filter((el)=>el.params).map((el)=>{let params=el.params;let value="";if(["checkbox","image_group","block_text","image"].includes(el.type)){value=params.map((param)=>{const current=el.rule.selected.find((select)=>select.name==param.value);return{value:current.name,price:current.price||0,urls:param.url||current.other||""};});}else{value=params.value;} return{type:el.type,value:value,name:el.title,price:el.price,urls:el.type==="file"?params.url:""};});};omesaasProduct.prototype.callbackMultipleAddToCart=function(){const self=this;this.multiple.forEach((item)=>{const ec_data={ec_data_id:this.product.id,ec_data_from:this.data_from,ec_data_name:encodeURIComponent(this.product.title),ec_data_price:item.price,ec_data_discount_price:item.price,ec_data_spu:this.product.spu,ec_data_image:this.product.src,ec_data_category:this.product.product_type,ec_data_uniq_id:this.product.id,ec_data_sku:item.sku,ec_data_sku_code:item.sku_code,ec_data_quantity:item.add_quantity,ec_data_sku_name:item.sku_value||"",ec_currency_code:this.ec_currency_code,ec_data_action_type:"add_to_cart"};callback_add_to_cart(ec_data);});};omesaasProduct.prototype.multipleAddCart=function(complete,success){const self=this;self.cartShake=false;var addMultiple=this.multiple.filter((item)=>item.add_quantity);var params=addMultiple.map((item)=>{return{product_id:this.product.id,sku_code:item.sku_code,quantity:item.add_quantity,data_from:self.data_from,property:[]};});moi.ajax({url:"/cart/batched",type:"post",data:JSON.stringify(params),complete(){self.cartShake=true;},success:function(data){complete&&complete.call(this);if(!data.code){moi.onEvent("cartChange",data.data);moi.changeCartNumber(data.data.item_count);miniCart();if(window.callback_add_to_cart){self.callbackMultipleAddToCart();} self.setSelectedVal({subtotalPrice:data.data.items_subtotal_price});} success&&success.call(self,data);}});};omesaasProduct.prototype.addCart=function(complete,success,isMiniCart=true){const self=this;if(this.isMultiple()){this.multipleAddCart(complete,success);return;} self.cartShake=false;let ret=moi.onEvent("payVerified",{property:[],custom_attr:[],product:this.params,code:200});if(ret.params.code===200){self.params["property"]=ret.params.property;moi.ajax({url:"/cart/add",type:"post",data:JSON.stringify({product_id:this.product.id,sku_code:this.params.sku_code,quantity:this.params.quantity,data_from:self.data_from,property:ret.params.property}),complete(){self.cartShake=true;},success:function(data){complete&&complete.call(this);if(ret.params.original&&data.data){self.params["custom_attr"]=data.data.items[data.data.items.length-1].property.filter(el=>el.type!=="app_minmaxoffer");} if(!data.code){moi.onEvent("cartChange",data.data);self.product["cart"]=data.data;moi.onEvent("addToCart",self.product);if(window.callback_add_to_cart){self.callbackAddToCart();} moi.changeCartNumber(data.data.item_count);isMiniCart&&miniCart();self.setSelectedVal({subtotalPrice:data.data.items_subtotal_price});} success&&success.call(self,data);}});}else{self.cartShake=true;complete&&complete.call(this);}};omesaasProduct.prototype.multipleBuynow=function(complete,success){const self=this;self.cartShake=false;var addMultiple=this.multiple.filter((item)=>item.add_quantity);var params=addMultiple.map((item)=>{return{product_id:this.product.id,sku_code:item.sku_code,quantity:item.add_quantity,data_from:self.data_from,property:[]};});moi.ajax({url:"/cart/batchbuynow",type:"post",data:JSON.stringify({data:params}),complete(){self.cartShake=true;},success:function(ret){complete&&complete.call(this);if(ret.data&&ret.data.code==-1000){alert(ret.data.msg);return;} if(!ret.code){if(window.callback_add_to_cart){self.callbackMultipleAddToCart();} if(ret.data.checkout_url&&moi){ret.data.checkout_url=moi.setUrlParams(ret.data.checkout_url,{_ref:location.href});}} success&&success.call(self,ret);}});};omesaasProduct.prototype.buynow=function(complete,success){const self=this;if(this.isMultiple()){this.multipleBuynow(complete,success);return;} self.buyShake=false;let ret=moi.onEvent("payVerified",{property:[],product:this.params,code:200});if(ret.params.code===200){self.params["property"]=ret.params.property;moi.ajax({url:"/cart/buynow",type:"post",data:JSON.stringify({product_id:this.product.id,sku_code:this.params.sku_code,quantity:this.params.quantity,data_from:self.data_from,property:ret.params.property}),complete(){self.buyShake=true;},success:function(ret){complete&&complete.call(this);if(ret.data&&ret.data.code==-1000){alert(ret.data.msg);return;} if(!ret.code){moi.onEvent("buynow",self.product);if(!ret.code&&window.callback_add_to_cart){self.callbackAddToCart();} if(ret.data.checkout_url&&moi){ret.data.checkout_url=moi.setUrlParams(ret.data.checkout_url,{_ref:location.href});}} success&&success.call(self,ret);}});}else{self.buyShake=true;complete&&complete.call(this);}};omesaasProduct.prototype.cartLayer=function(){if(storeConfig.purchase_style==2){moi.alertInfo({content:lang.product.add_cart_succeed,placement:"top",type:"success"});return;} if(storeConfig.purchase_style==3){showMiniCart();return;} if(storeConfig.purchase_style==4){location.href="/cart";return;} if(this.isMultiple()){showMiniCart();return;} const option=JSON.parse(JSON.stringify(this.params));let isProperty=false;if(option.property&&option.property.length){isProperty=option.property.some((el)=>typeof el.params!=="string");} const subtotalPrice=formatMoney(parseFloat(option.subtotalPrice||0),oemcart_currency);const popupLayer=moi.popup();var html=$("#id-popup-addPurchase-success").length?$("#id-popup-addPurchase-success").html():$("#omesaas-popup-addPurchase-success").html();engine.parseAndRender(html,{option:option,subtotalPrice:subtotalPrice,isProperty:isProperty,storeConfig:storeConfig,lang:window.lang}).then(function(html){popupLayer.addContent(html);const temp=popupLayer.temp;const submitNodes=temp.find(".cart-buyNow");submitNodes.on("click",function(){temp.find(".cart_form").submit();popupLayer.close();});});};omesaasProduct.prototype.renderProductImgList=function(params={}){let config={isUpdate:false,parentsClass:".collection_item",defaultImgClass:".default_img",...params};function renderImgList(){$(".block_product_img_list.noRender").each((index,elem)=>{let width=$(elem).width()-$(elem).width()*0.26;let renderMaxLength=Math.floor(width/28);let listDom=$(elem).find(".img_list .img_list_item");let listDomLen=listDom.length>renderMaxLength?"+"+(listDom.length-renderMaxLength):"";$(elem).find(".img_list .morNumber").text(listDomLen);listDom.each((itemIndex,listItem)=>{if(itemIndex>=renderMaxLength){$(listItem).remove();}});$(elem).removeClass("noRender");listDom.on("mouseenter",function(){let src=$(this).find("img").attr("src").split("?")[0];var defaultImgNode=config.isUpdate?$(this).parents(config.parentsClass).find(config.defaultImgClass):$(this).parent().parent().parent().find(".default_img");defaultImgNode.attr("data-src",src);window.lazyLoadImage(defaultImgNode);$(this).addClass("active").siblings().removeClass("active");});});} renderImgList() moi.addEvent("updateBlock",function(e){renderImgList()})};omesaasProduct.prototype.wishlistParams=function(value,hit_type_category){var ec_data=this.getEcData();ec_data.ec_data_action_type="view_content";ec_data.ec_data_from="wishlist";function getMetaContent(metaName){const metas=document.getElementsByTagName("meta");for(let i=0;i{$(this).find(".wishlist-animated").removeClass("animated tada");},700);if(!oemcart_user_id){location.href="/account/login?checkout_url="+encodeURIComponent(location.href);return;} if(that.product.in_wishlist==1){that.product.in_wishlist=0;wishlistNode.removeClass("product-wishlist-active");moi.ajax({url:"/wishlist",type:"DELETE",data:JSON.stringify({product_id:that.product.id,event:that.wishlistParams(0,"remove_from_wishlist")}),complete(){that.wishlistShake=true;},success:function(ret){if(!ret.code){moi.alertInfo({content:lang.product.remove_from_wishlist,type:"success",placement:"top"});}else{moi.alert({title:ret.msg});}}});}else{that.product.in_wishlist=1;wishlistNode.addClass("product-wishlist-active ");moi.ajax({url:"/wishlist",type:"POST",data:JSON.stringify({product_id:that.product.id,event:that.wishlistParams(1,"add_to_wishlist")}),complete(){that.wishlistShake=true;},success:function(ret){if(!ret.code){moi.alertInfo({content:lang.product.add_to_wishlist,type:"success",placement:"top"});callback_add_to_wishlist&&callback_add_to_wishlist(that.getEcData());}else{moi.alert({title:ret.msg});}}});}});}};window.omesaasProduct=omesaasProduct;window.shopProduct=omesaasProduct;function handleBuyNow(event){console.warn('handleBuyNow',event);var eventData=event.data.data;moi.ecBuyNow(eventData,true,event)} function handleIframeResize(event){console.warn('handleIframeResize',event);const iframe=document.getElementById('ec-payment-div-'+window['ec_action_from']);if(event.data.data.fullscreen){if(window['ec_action_from']==="product_detail"){$(".product-right").css("z-index","999999999");} iframe.style.width='100vw';iframe.style.height='100vh';iframe.style.position='fixed';iframe.style.top='0';iframe.style.zIndex='1000';iframe.style.left='0';iframe.style.marginTop='0';}else{if(window['ec_action_from']==="product_detail"){$(".product-right").css("z-index","1");} iframe.style.position='relative';iframe.style.width='100%';iframe.style.height='80px';iframe.style.marginTop='10px';}} function handleRequest(event){handleIframeResize({data:{data:{fullscreen:false}}}) const retData=event.data;createAjaxLoading() fetch(retData.data.url,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({...retData.data.data,capture_url:retData.data.capture_url})}).then(function(res){removeAjaxLoading() return res.json();}).then(function(ret){if(ret.code==0){location.href=ret.data.redirect_url;}else{moi.alertInfo({content:ret.data.msg});return false;}});} window.addEventListener('message',function(e){try{const message=typeof e.data==='string'?JSON.parse(e.data):e.data;if(!message.type){return;} switch(message.type){case'shop_buynow':handleBuyNow(e);break;case'shop_iframeResize':handleIframeResize(e);break;case'shop_ecData':handleRequest(e);break;default:}}catch(error){}});})();