12:""
class SpzCustomDatalib extends SPZ.BaseElement { constructor(element) { super(element); this.selectedDataByOrder = undefined; } buildCallback() { this.setupAction_(); } mountCallback() { window.need_create_order = true; const orderId = this.getUrlParam('order_id'); if(!orderId){ this.removeUrlParamKey() }else{ window.onepageCurrentOrderId = orderId; } window.addEventListener('onepage.order.change',()=>{ localStorage.onePageMarketInfo = JSON.stringify(window.marketingInfo); if(window?.onepage_marketingInfo?.marketing_rule){ let href = this.addUrlParam("rule_id",window.onepageMarketingTabIndex); history.pushState({}, 0, href); } // url添加埋点标识 let href_track = this.addUrlParam("sales_platform",'sales_funnel'); history.pushState({}, 0, href_track); let href1 = this.delUrlParam("order_id",window.onepageMarketingTabIndex); history.pushState({}, 0, href1); }); this.updateQuantityData('init'); } setupAction_() { this.registerAction('saveSelectedDataByOrder',(invocation) => { this.saveSelectedDataByOrderFn(invocation) }); } isLayoutSupported(layout) { return layout == SPZCore.Layout.CONTAINER; } removeUrlParamKey(){ localStorage.removeItem('onePageMarketInfo'); let arr = ['rule_id','variant','order_id','sales_platform']; while(arr?.length){ let href = this.delUrlParam(arr.pop()); history.pushState({}, 0, href); } if(!window?.onepage_marketingInfo?.marketing_rule){ let varantsDom = document.getElementById('onepage_product-info-variants'); varantsDom?.querySelectorAll(`input[type=radio]`).forEach(dom => { dom.checked = false; }) } window.onepageCurrentOrderId = ''; } flatObj(data){ window.all_onepage_line_items = {}; window.all_onepage_line_items[this.getUrlParam('rule_id')] = data?.line_items?.map(_data => { return { variant_id: _data.variant_id, quantity: _data.quantity } }); const result = []; data?.line_items?.forEach(lineItemData => { if(lineItemData?.quantity > 1){ for(let i = lineItemData?.quantity;i>0;i--){ result.push({ ...lineItemData, quantity:1 }) } }else{ result.push({...lineItemData}) } }); data.line_items = result; return result } eventQueen(dataSource,cb,timeGap){ dataSource?.reduce((pre, cur) => { return pre.then(() => { return new Promise(r => { setTimeout(() => { r(cb(cur)); }, timeGap || 200); }) }) }, Promise.resolve()) } renderMarketContent(){ setTimeout(()=>{ const render = document.getElementById('onepage_productMarketing_render'); SPZ.whenApiDefined(render).then((api) => { api.render({ selectedDataByOrder:this.flatObj(this.selectedDataByOrder), ruleId: this.getUrlParam('rule_id') },true).then(()=>{ window.need_create_order = false; window.onepageSatisfiedCreatedOrder = true; window.allKeysHaveValue = true; window.onepageMarketingTabIndex = this.getUrlParam('rule_id'); window.dispatchEvent(new CustomEvent('addTabChangeEvent')); if(window.marketingInfo.marketing_rule.design.attribute_show_type==1){ const inputs = document.querySelectorAll('input[type=radio]'); inputs?.forEach(inputdom => { if(!inputdom.getAttribute('data-rule-id') || inputdom.getAttribute('data-rule-id') != this.getUrlParam('rule_id')){ inputdom.setAttribute('data-click-init',false); } }) const inputs1 = document.querySelectorAll('input[type=radio][data-click-init=true]'); let num = 0; this.eventQueen(Array.from(inputs1),(cur)=>{ num++; cur.click(); setTimeout(()=>{ if(num === inputs1?.length){ window.need_create_order = true; window?.salesFunnelslideImageByTabChange?.() } },1000) }) } if(window.marketingInfo.marketing_rule.design.attribute_show_type==2){ const selectVariants = document.querySelectorAll('.select-type-variants'); selectVariants?.forEach(selectDom => { if(!selectDom.getAttribute('data-rule-id') || selectDom.getAttribute('data-rule-id') != this.getUrlParam('rule_id')){ selectDom.setAttribute('data-value-init',undefined); } }); let num = 0; this.eventQueen(Array.from(selectVariants),(cur)=>{ num++; let valueIndex = cur.getAttribute('data-value-init'); if(valueIndex !== 'undefined'){ cur?.querySelectorAll('.onepage_product-info__variants_value')?.[valueIndex].setAttribute('selected','selected'); cur.classList.remove('defaultSelectColor'); const value = cur?.value; const name = cur?.name; const _index = cur?.getAttribute('greater_than_or_equal_to_arr_index'); window.onePage_variants_marketing_object[window.onepageMarketingTabIndex][_index][name] = value; let onePageSelectChange = new CustomEvent("onepage.trigger.select.change", { detail: { args: { value: cur?.value, name: cur?.name, index:_index, }, }, }); window.dispatchEvent(onePageSelectChange); }; setTimeout(()=>{ if(num === selectVariants?.length){ window.need_create_order = true; window?.salesFunnelslideImageByTabChange?.() } },1000) }) } }) }); },1800) } updateQuantityData(type){ const quantityRenderIdRender = document.getElementById('quantity-render-id'); if(!quantityRenderIdRender) return; SPZ.whenApiDefined(quantityRenderIdRender).then((api) => { api.render({ quantity: window.quantityValue }).then(()=>{ if(type !== 'init'){ setTimeout(()=>{ window.need_create_order = true; },1000) } }) }).catch(e => { window.need_create_order = true; }); } renderProductContent(){ window.need_create_order = false; setTimeout(()=>{ try{ window.onepageSatisfiedCreatedOrder = true; window.allKeysHaveValue = true; window.quantityValue = this.selectedDataByOrder?.line_items[0].quantity; if(this.getUrlParam('variant')){ let interval = setInterval(()=>{ if (window?.onepage_product?.options?.length > 0) { clearInterval(interval); let onePage_variants_marketing_object = {}; window.onepage_product.options.forEach(item => { let realValueText = this?.selectedDataByOrder?.line_items[0]?.options?.find(variantName => variantName.name === item.name)?.value; onePage_variants_marketing_object[item.name] = realValueText; }); window.onePage_variants_marketing_object = onePage_variants_marketing_object; let inputArr = []; let num = 0; for(let key in window.onePage_variants_marketing_object){ let val = window.onePage_variants_marketing_object[key]; document.querySelectorAll(`input[type=radio]`).forEach(dom => { if(dom.value === val){ inputArr.push(dom); } }) } this.eventQueen(inputArr,(cur)=>{ num++; cur.click(); setTimeout(()=>{ if(num === inputArr?.length){ this.updateQuantityData(); } },1000) }) } },300); }else{ this.updateQuantityData(); } }catch(e){ window.need_create_order = true; }finally{ } },1800) } getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) {return decodeURIComponent(r[2]); } ; return null; } delUrlParam(param){ let obj = new window.URL(window.location.href); obj.searchParams.delete(param); return obj.href; } addUrlParam(key, value){ let obj = new window.URL(window.location.href); obj.searchParams.set(key, value); return obj.href; } saveSelectedDataByOrderFn(invocation){ const order_url = invocation.event.detail.order_url; const order_id = invocation.event.detail.order_id; fetch('/api/checkout/order/'+order_id,{ method: 'get', headers: { 'Content-Type': 'application/json', } }).then(response => response.json()) .then(data => { this.selectedDataByOrder = data?.data; const nowMarketingInfo = window.marketingInfo; if(localStorage.onePageMarketInfo && localStorage.onePageMarketInfo != 'undefined' && JSON.stringify(nowMarketingInfo) !== localStorage.onePageMarketInfo){ this.removeUrlParamKey(); window.location.reload(); }else{ if(!localStorage.onePageMarketInfo){ localStorage.onePageMarketInfo = JSON.stringify(nowMarketingInfo); } if(!window?.onepage_marketingInfo?.marketing_rule){ this.renderProductContent() }else{ this.renderMarketContent() } } }) } } SPZ.defineElement('spz-custom-datalib', SpzCustomDatalib);
12""
$25.99
$50.99
- $25.00
class SpzCustomComponent extends SPZ.BaseElement { constructor(element) { super(element); } buildCallback() { this.setupAction_(); } setupAction_() { this.registerAction('update', function (invocation) { function hasValueForAllKeys(obj) { return Object.values(obj).every(value => value !== undefined && value !== null && value !== ''); } var quantityValue = invocation.args.quantityValue; var name = invocation.args.name; var value = invocation.args.value; if (quantityValue) { window.quantityValue = quantityValue; } if (quantityValue == 0) { window.quantityValue = 0; } var onePage_variants_marketing_object = window.onePage_variants_marketing_object; function _getCookieByCard(name) { var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); if (arr = document.cookie.match(reg)) { return unescape(arr[2]); } else { return ''; } }; function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) {return decodeURIComponent(r[2]); } ; return null; } if (window.onepage_product.options.length > 0) { var realValueText = ''; window.onepage_product.options.map(item => { if (item.name == name) { realValueText = item.values[invocation.args.value - 1]; } }); window.onePage_variants_marketing_object[name] = realValueText; }; var allKeysHaveValue = false; var checkedProductVariants = {}; if (window.onepage_product.options.length > 0) { window.onepage_product.variants.map(item => { let isMatched = item.options.every(newItem => onePage_variants_marketing_object[newItem.name] == newItem.value); if (isMatched) { allKeysHaveValue = true; checkedProductVariants = item; } }); } else if (window.onepage_product.options.length == 0) { allKeysHaveValue = true; } if (hasValueForAllKeys(window.onePage_variants_marketing_object) && !allKeysHaveValue) { allKeysHaveValue = false; window.onepageSatisfiedCreatedOrder = false; document.getElementById('please_select_quantity').innerHTML = 'Product is unavailable.'; window.onepage_create_order_tip = 'Product is unavailable.'; }; window.allKeysHaveValue = allKeysHaveValue; if (allKeysHaveValue && window.need_create_order) { if (checkedProductVariants.available_quantity) { if (checkedProductVariants.available_quantity > 0) { if (document.getElementsByClassName('onepage_check_btn').length) { document.getElementsByClassName('onepage_check_btn')[0].style.display = "block"; }; if (document.getElementsByClassName('onepage_un_checkout_btn').length) { }; } } else { if (window.quantityValue > 0) { if (document.getElementsByClassName('onepage_check_btn').length) { document.getElementsByClassName('onepage_check_btn')[0].style.display = "block"; }; if (document.getElementsByClassName('onepage_un_checkout_btn').length) { }; } else { if (document.getElementsByClassName('onepage_check_btn').length) { }; if (document.getElementsByClassName('onepage_un_checkout_btn').length) { document.getElementsByClassName('onepage_un_checkout_btn')[0].style.display = "block"; }; }; }; var onepage_line_items = [{ variant_id: window.onepage_product.options.length > 0 ? checkedProductVariants.id : window.onepage_product.variants[0].id, quantity: window.quantityValue ? window.quantityValue : 1 }]; let onepage_marketing_variants_list = { sales_platform:'sales_funnel_shop', identifier_extra: window.C_SETTINGS.meta.page.resource_id + _getCookieByCard('client_id'), line_items:onepage_line_items, refer_info:{ source:'one_page' } }; var loadingEl = document.getElementById('loadingMaskOnePage'); if (loadingEl) { loadingEl.style.display = 'block'; } window.renderOnepageSourceCookie(); fetch('/api/checkout/order', { method: 'POST', body: JSON.stringify(onepage_marketing_variants_list), headers: { 'Content-Type': 'application/json', } }).then((response) => response.json()).then(res => { if (loadingEl) { loadingEl.style.display = 'none'; } if (res.data) { var order_quantity_sum = res.data.items.reduce((accumulator, currentValue) => { return accumulator + currentValue.quantity; }, 0); var check_quantity_sum = onepage_line_items.reduce((accumulator, currentValue) => { return accumulator + currentValue.quantity; }, 0); if (order_quantity_sum != check_quantity_sum) { window.onepageSatisfiedCreatedOrder = false; document.getElementById('please_select_quantity').style.display = 'block'; document.getElementById('please_select_quantity').innerHTML = 'The product is already sold out.'; window.onepage_create_order_tip = 'The product is already sold out.'; setTimeout(() => { document.getElementById('please_select_quantity').style.display = 'none'; }, 3000) } else { fetch('/api/front/pelican/v1/cache_place_order', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ funnel_id:window.window.commonFunnelId, page_id: '12713489', order_id: res.data.order_token, landing_url: window.location.href, funnel_page_ids: window?.commonEventInfo?.funnel_page_ids || getUrlParam('funnel_page_ids') || '', testing_ids: window?.commonEventInfo?.testing_ids || getUrlParam('testing_ids') || '' }) }) .then(response => response.json()) .then(data => { }) .catch(error => { console.error(error); }); var marketing_type_map = { 1: 'single_spu_multiple_sku', 2: 'multi_spu_combination', 0: 'no_marketing_activities', }; var discount_type = { 1: 'fixed_amount', 2: 'percentage', 0: 'no_discount', }; window?.sa?.track("function_click", { function_name: "sales_funnel", plugin_name: "sales_funnel", template_name: "page", template_type: "3", module: "apps", module_type: "sales_funnel", business_type:"product_plugin", tab_name: "", card_name: "product_detail", event_developer: "ccbfeyoungberg", event_name: "function_click", event_type: "click", event_desc: "商品详情选择商品属性", event_info: JSON.stringify({ "page_id": window?.C_SETTINGS?.meta?.page?.resource_id ? window?.C_SETTINGS?.meta?.page?.resource_id + '' : '', "current_language": document.documentElement.lang || window?.C_SETTINGS.market.market_lang, "product_id": "01270490-00b4-4635-b23b-271ac28a4bd0", "marketing_type": marketing_type_map[0], "marketing_template": '', "discount_id": window?.onepage_discount_id, "discount_type": discount_type[0], "discount_quantity": order_quantity_sum, "discount_value": 0, "action_type": "select_product_option", "element_type": "card", "element_name": "product_variant", ...window.commonEventInfo, }) }); window.onepageSatisfiedCreatedOrder = true; let onePageCheckoutOrderChange = new CustomEvent("onepage.order.change", { detail: { order_token: res.data.order_token, }, }); window.dispatchEvent(onePageCheckoutOrderChange); } } else { window.onepageSatisfiedCreatedOrder = false; document.getElementById('please_select_quantity').style.display = 'block'; document.getElementById('please_select_quantity').innerHTML = res.message || 'Product is unavailable.'; window.onepage_create_order_tip = res.message || 'Product is unavailable.'; setTimeout(() => { document.getElementById('please_select_quantity').style.display = 'none'; }, 3000) } }) } }); } isLayoutSupported(layout) { return layout == SPZCore.Layout.CONTAINER;; } } SPZ.defineElement('spz-custom-component', SpzCustomComponent);
Blades: 
Quantity: 
Size: 
Please select product quantity
Buy now