${function(){
var actual_rate = '0.145039';
var onepage_product_min_price = 2.9;
var onepage_actual_price = onepage_product_min_price ;
var product_options = '';
var product_options_1 = [];
var marketingInfo = {"marketing_rule":{"range":[{"uuid":"4be0e174-7bee-408c-9430-4463372d010a","title":"Buy {minimum_purchase_quantity} for {custom_total_price}","value":20,"images":null,"default":false,"price_color":"#91C500","title_color":"#222","hidden_price":false,"discount_text":"You save {discount_value}","compare_price_color":"#A9A9A9","discount_text_color":"#797979","greater_than_or_equal_to":1},{"uuid":"f7d0bb60-699f-4583-a37d-0942c533388a","title":"Buy {minimum_purchase_quantity} for {custom_total_price}","value":30,"images":null,"default":true,"price_color":"#91C500","title_color":"#222","hidden_price":false,"discount_text":"You save {discount_value}","compare_price_color":"#A9A9A9","discount_text_color":"#797979","greater_than_or_equal_to":2},{"uuid":"b50c8ad1-bb30-4e45-b20b-46711aed8104","title":"Buy {minimum_purchase_quantity} for {custom_total_price}","value":40,"images":null,"default":false,"price_color":"#91C500","title_color":"#222","hidden_price":false,"discount_text":"You save {discount_value}","compare_price_color":"#A9A9A9","discount_text_color":"#797979","greater_than_or_equal_to":3},{"uuid":"3d8c8099-9522-4adc-830f-32f405573e49","title":"Buy {minimum_purchase_quantity} for {custom_total_price}","value":20,"images":null,"default":false,"price_color":"#91C500","title_color":"#222","hidden_price":false,"discount_text":"You save {discount_value}","compare_price_color":"#A9A9A9","discount_text_color":"#797979","greater_than_or_equal_to":4}],"design":{"color":{"button_border_color":"#E6E6E6","button_background_color":"#FFF","fold_button_border_color":"#D8DFBE","selected_button_text_color":"#91C500","fold_button_background_color":"#FFFEF1","selected_button_background_color":"#FFF"},"style":{"attribute_border_rounded_corners":0},"attribute_show_type":1}},"marketing_rule_type":1,"marketing_activity_type":2,"marketing_rule_template_type":2};
var marketing_rule = {"range":[{"uuid":"4be0e174-7bee-408c-9430-4463372d010a","title":"Buy {minimum_purchase_quantity} for {custom_total_price}","value":20,"images":null,"default":false,"price_color":"#91C500","title_color":"#222","hidden_price":false,"discount_text":"You save {discount_value}","compare_price_color":"#A9A9A9","discount_text_color":"#797979","greater_than_or_equal_to":1},{"uuid":"f7d0bb60-699f-4583-a37d-0942c533388a","title":"Buy {minimum_purchase_quantity} for {custom_total_price}","value":30,"images":null,"default":true,"price_color":"#91C500","title_color":"#222","hidden_price":false,"discount_text":"You save {discount_value}","compare_price_color":"#A9A9A9","discount_text_color":"#797979","greater_than_or_equal_to":2},{"uuid":"b50c8ad1-bb30-4e45-b20b-46711aed8104","title":"Buy {minimum_purchase_quantity} for {custom_total_price}","value":40,"images":null,"default":false,"price_color":"#91C500","title_color":"#222","hidden_price":false,"discount_text":"You save {discount_value}","compare_price_color":"#A9A9A9","discount_text_color":"#797979","greater_than_or_equal_to":3},{"uuid":"3d8c8099-9522-4adc-830f-32f405573e49","title":"Buy {minimum_purchase_quantity} for {custom_total_price}","value":20,"images":null,"default":false,"price_color":"#91C500","title_color":"#222","hidden_price":false,"discount_text":"You save {discount_value}","compare_price_color":"#A9A9A9","discount_text_color":"#797979","greater_than_or_equal_to":4}],"design":{"color":{"button_border_color":"#E6E6E6","button_background_color":"#FFF","fold_button_border_color":"#D8DFBE","selected_button_text_color":"#91C500","fold_button_background_color":"#FFFEF1","selected_button_background_color":"#FFF"},"style":{"attribute_border_rounded_corners":0},"attribute_show_type":1}};
let selectedDataByOrder = data.originData.selectedDataByOrder || null;
const marketRuleId = data.ruleId;
marketing_rule.range = marketing_rule.range.map((item,index)=>{
let arr = [];
for (var i = 0; i < item.greater_than_or_equal_to; i++){
arr.push(item.uuid);
}
item['greater_than_or_equal_to_arr'] = arr;
return {
...item,
selected: !selectedDataByOrder && product_options?.length === 0 ? !!null : selectedDataByOrder ? item.uuid === marketRuleId : item.default,
greater_than_or_equal_to_arr: arr,
is_show_image: !!item.images
}
});
if(selectedDataByOrder){
selectedDataByOrder.forEach(selectedData => {
const selectedOptions = selectedData.options;
selectedData.selectedArr = [];
selectedOptions.forEach(sOption => {
const prdValues = product_options_1.find(option => option.name === sOption.name).values;
const selectedValueIndex = prdValues?.findIndex(value => value=== sOption.value);
if(selectedValueIndex>-1){
let obj = {};
obj.selectedValueIndex = selectedValueIndex;
obj.option_name = sOption.name;
selectedData.selectedArr.push(obj)
}
})
});
let temDataArr = JSON.parse(JSON.stringify(marketing_rule.range)).sort((a, b) => { return b?.greater_than_or_equal_to_arr?.length - a?.greater_than_or_equal_to_arr?.length })[0].greater_than_or_equal_to_arr;
const length = selectedDataByOrder?.length;
temDataArr?.forEach((data,index) => {
if(index+1>length){
selectedDataByOrder[index] = {};
selectedDataByOrder[index].selectedArr = [];
product_options_1.forEach(option => {
let obj = {};
obj.selectedValueIndex = undefined;
obj.option_name = option.name;
selectedDataByOrder[index].selectedArr.push(obj)
});
}
});
}else{
selectedDataByOrder = [];
let temDataArr = JSON.parse(JSON.stringify(marketing_rule.range)).sort((a, b) => { return b?.greater_than_or_equal_to_arr?.length - a?.greater_than_or_equal_to_arr?.length })[0].greater_than_or_equal_to_arr;
temDataArr?.forEach((rangeData,rangeIndex) => {
selectedDataByOrder[rangeIndex] = {};
selectedDataByOrder[rangeIndex].selectedArr = [];
product_options_1.forEach(option => {
let obj = {};
obj.selectedValueIndex = undefined;
obj.option_name = option.name;
selectedDataByOrder[rangeIndex].selectedArr.push(obj)
});
});
}
function computedPrice(price,num,value) {
if(marketingInfo.marketing_activity_type == 0 || !marketingInfo.marketing_activity_type){
return Number.parseFloat(price*num).toFixed(2);
}else if(marketingInfo.marketing_activity_type == 1){
return Math.max(0,Number.parseFloat((price*num) - value*actual_rate).toFixed(2)).toFixed(2);
}else {
return Math.max(0,Number.parseFloat(price* ((100-value)/100) * num).toFixed(2)).toFixed(2);
};
}
function repetDiscountText(discount_text, value){
if(!discount_text) return;
let discount_text_str = discount_text;
if(marketingInfo.marketing_activity_type == 1){
let discount_amount ='$'+ Number(value*actual_rate).toFixed(2);
discount_text_str = discount_text_str.replace(new RegExp("{discount_amount}","gm"), discount_amount)
}else if(marketingInfo.marketing_activity_type == 2){
let discount_percent = value + '%';
discount_text_str = discount_text_str.replace(new RegExp("{discount_value}","gm"), discount_percent)
}
return discount_text_str
};
function repetPrice(titlePrice, price,num,value,uuid) {
var custom_total_price = '$'+ computedPrice( price,num,value);
var custom_price ='$'+ Number.parseFloat(computedPrice( price,num,value)/num).toFixed(2);
var custom_total_price_dom = `
${custom_total_price} `;
var custom_price_dom = `
${custom_price} `;
var cur_tab_count = num;
return titlePrice.replace(new RegExp("{custom_price}","gm"), custom_price_dom).replace(new RegExp("{custom_total_price}","gm"), custom_total_price_dom).replace(new RegExp("{minimum_purchase_quantity}","gm"), cur_tab_count);
}
function return_custom_total_price(titlePrice, price,num,value,uuid) {
var custom_total_price = '$'+ computedPrice( price,num,value);
var custom_total_price_dom = custom_total_price;
return custom_total_price_dom;
}
function return_custom_price(titlePrice, price,num,value,uuid) {
var custom_price ='$'+ computedPrice( price,num,value);
var custom_price_dom = Number.parseFloat(computedPrice( price,num,value)/num).toFixed(2);
return custom_price_dom;
}
return `
${repetPrice(second_value.title,onepage_actual_price,second_value.greater_than_or_equal_to,second_value.value,second_value.uuid)}
${repetDiscountText(second_value.discount_text, second_value.value)}
$ ${ computedPrice(onepage_actual_price,second_value.greater_than_or_equal_to,second_value.value)}
$ ${Number.parseFloat(onepage_actual_price * second_value.greater_than_or_equal_to).toFixed(2)}
Item ${greater_than_or_equal_to_arr_index+1}
(Please select specifications)
class SpzCustomComponent extends SPZ.BaseElement {
constructor(element) {
super(element);
}
buildCallback() {
this.setupAction_();
}
mountCallback() {
window.addEventListener('onepage.trigger.select.change',(data)=>{
const _data = data.detail;
this.updateFn(_data)
});
}
updateFn(invocation){
var actual_rate = '0.145039';
var marketingInfo =window.onepage_marketingInfo;
var price_symbol = "$" ;
window.onepage_marketingInfo = marketingInfo;
var onepageMarketingTabIndex = window.onepageMarketingTabIndex;
if (marketingInfo.marketing_rule.design.attribute_show_type == 1) {
var realValueName = '';
window.onepage_product.options.map((item, index) => {
if (index + 1 == invocation.args.name) {
realValueName = item.name;
}
});
var name = realValueName;
} else {
var name = invocation.args.name;
}
var index = invocation.args.index;
var onePage_variants_marketing_object = window.onePage_variants_marketing_object;
if (marketingInfo.marketing_rule.design.attribute_show_type == 1) {
var realValueText = '';
window.onepage_product.options.map(item => {
if (item.name == name) {
realValueText = item.values[invocation.args.value - 1];
}
});
window.onePage_variants_marketing_object[onepageMarketingTabIndex][index][name] = realValueText;
} else {
window.onePage_variants_marketing_object[onepageMarketingTabIndex][index][name] = invocation.args.value;
};
try{
if(window.need_create_order){
this.setSlideFn(onepageMarketingTabIndex,index,name)
}
}catch(e){
};
var allKeysHaveValue = window.onePage_variants_marketing_object[onepageMarketingTabIndex].every(obj => {
return Object.values(obj).every(value => value !== "");
});
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;
}
window.allKeysHaveValue = allKeysHaveValue;
if (allKeysHaveValue ) {
var product_variant_price_list = [];
var onepage_select_tab_id = 'onepageVariantsMarketingSecontTemplate' + window.onepageMarketingTabIndex;
var product_variant_id_list = [];
const selectedVariants = [];
window.onepage_product.variants.map(item => {
window.onePage_variants_marketing_object[onepageMarketingTabIndex].map(variants_item => {
let isMatched = item.options.every(newItem => variants_item[newItem.name] == newItem.value);
if (isMatched) {
selectedVariants.push(item);
product_variant_price_list.push(item.price);
product_variant_id_list.push(item.id);
}
});
});
if (window.onePage_variants_marketing_object[onepageMarketingTabIndex].length == selectedVariants.length) {
if (selectedVariants?.length) {
const currentProduct = window.onepage_product;
var triggerViewContent = ({ product, selected, qty }) => {
triggerEvent('dj.viewContent', { product: product || {}, selected: selected || {}, qty: qty || 1, source: 'pageview' });
};
var triggerEvent = (eventName, params) => {
var event = new CustomEvent(eventName, { detail: params || null, bubbles: true });
document.body?.dispatchEvent(event);
};
var holdonFun = (time) => {
return new Promise((resolve) => setTimeout(resolve, time))
};
var reduceNoRepeat = (originArr) => {
let obj = {};
let reduce = [];
reduce = originArr.reduce(function (item, next) {
if (!obj[next.id]) {
obj[next.id] = true;
next.qty = 1;
item.push(next)
} else {
let oldData = item?.find(data => data.id === next.id);
if (oldData) {
oldData.qty += 1
}
}
return item;
}, []);
return reduce;
};
const selectedVariantsArr = reduceNoRepeat(selectedVariants?.reverse());
const triggerViewContentFn = async (arr) => {
for (let i = 0; selectedVariantsArr.length > i; i++) {
const varientData = selectedVariantsArr[i];
setTimeout(() => {
triggerViewContent({ product: currentProduct, selected: varientData, qty: varientData?.qty || 1 });
}, 1000 * (i + 1))
}
};
triggerViewContentFn(selectedVariantsArr);
};
var price_sum = product_variant_price_list.reduce((a, b) => Number(a) + Number(b), 0);
var average = price_sum / product_variant_price_list.length;
if (marketingInfo.marketing_rule_template_type == 1) {
if (marketingInfo.marketing_activity_type == 0 || !marketingInfo.marketing_activity_type) {
average = average;
} else if (marketingInfo.marketing_activity_type == 1) {
average = (average - window.onepageMarketingTabIndexValue * actual_rate);
} else {
average = average * ((100 - window.onepageMarketingTabIndexValue) / 100);
};
average = Math.max(0,Number.parseFloat(average)).toFixed(2);
if (document.getElementsByClassName(onepage_select_tab_id)[0].getElementsByClassName('onepage_template1_price').length) {
document.getElementsByClassName(onepage_select_tab_id)[0].getElementsByClassName('onepage_template1_price')[0].innerHTML = price_symbol + ' ' + average;
document.getElementsByClassName(onepage_select_tab_id)[1].getElementsByClassName('onepage_template1_price')[0].innerHTML = price_symbol + ' ' + average;
}
}
if (marketingInfo.marketing_rule_template_type == 2) {
if (marketingInfo.marketing_activity_type == 0 || !marketingInfo.marketing_activity_type) {
average = average * product_variant_price_list.length;
} else if (marketingInfo.marketing_activity_type == 1) {
average = (average * product_variant_price_list.length) - window.onepageMarketingTabIndexValue * actual_rate;
} else {
average = average * ((100 - window.onepageMarketingTabIndexValue) / 100) * product_variant_price_list.length;
};
average = Math.max(0,Number.parseFloat(average)).toFixed(2);
if (document.getElementById(onepage_select_tab_id).getElementsByClassName('onepage_one_price_inner_item').length) {
document.getElementById(onepage_select_tab_id).getElementsByClassName('onepage_one_price_inner_item')[0].innerHTML = price_symbol + Math.max(0,Number.parseFloat(average)).toFixed(2);
if (document.getElementById(onepage_select_tab_id).getElementsByClassName('line-through onepage_all_price_inner').length) {
document.getElementById(onepage_select_tab_id).getElementsByClassName('line-through onepage_all_price_inner')[0].innerHTML = price_symbol + Math.max(0,Number.parseFloat(price_sum)).toFixed(2);
if (document.getElementById(onepage_select_tab_id).getElementsByClassName('custom_price_span').length) {
document.getElementById(onepage_select_tab_id).getElementsByClassName('custom_price_span')[0].innerHTML = price_symbol + Math.max(0,Number.parseFloat((average / product_variant_price_list.length))).toFixed(2);
}
if (document.getElementById(onepage_select_tab_id).getElementsByClassName('custom_total_price_dom_span').length) {
document.getElementById(onepage_select_tab_id).getElementsByClassName('custom_total_price_dom_span')[0].innerHTML = price_symbol + Math.max(0,Number.parseFloat(average)).toFixed(2);
}
}
}
}
var onepage_line_items = product_variant_id_list.reduce(function (acc, curr) {
var obj = acc.find(obj => obj.variant_id == curr);
if (obj) {
obj.quantity += 1;
} else {
acc.push({ variant_id: curr, quantity: 1 });
}
return acc;
}, []);
window.onepage_line_items = onepage_line_items;
window.all_onepage_line_items[window.onepageMarketingTabIndex] = onepage_line_items;
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'
}
};
window.renderOnepageSourceCookie();
if(!window.need_create_order) return;
var loadingEl = document.getElementById('loadingMaskOnePage');
if (loadingEl) {
loadingEl.style.display = 'block';
}
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: '12264001',
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 marketing_template_type_map = {
0: '',
1: 'template_one',
2: 'template_two',
};
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": window?.onepage_product?.id,
"marketing_type": marketing_type_map[marketingInfo.marketing_rule_type],
"marketing_template": marketing_template_type_map[marketingInfo.marketing_rule_template_type],
"discount_id": window?.onepage_discount_id,
"discount_type": discount_type[marketingInfo.marketing_activity_type],
"discount_quantity": order_quantity_sum,
"discount_value": (marketingInfo.marketing_activity_type == 0 || !marketingInfo.marketing_activity_type) ? 0 : window?.onepageMarketingTabIndexValue,
"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)
}
})
} else {
window.onepageSatisfiedCreatedOrder = false;
document.getElementById('please_select_quantity').innerHTML = 'Product is unavailable.';
window.onepage_create_order_tip = 'Product is unavailable.';
window.all_onepage_line_items[window.onepageMarketingTabIndex] = undefined;
}
}
}
setupAction_() {
this.registerAction('update', (invocation)=>{
this.updateFn(invocation)
})
}
setSlideFn(onepageMarketingTabIndex,skuIndex,optName){
var slide_ = 'onepage_product-detail-images';
var slideEle = document.getElementById(slide_);
var switchSlide='null';
console.log('switchSlide',switchSlide, typeof switchSlide);
const hasSwitchSlide = switchSlide && switchSlide !== '[]' && switchSlide !== 'null';
var _selectedVariants = [];
var _switch = [];
var currentSkuData = window.onePage_variants_marketing_object[onepageMarketingTabIndex][skuIndex];
window.onepage_product.variants.map(item => {
let isMatched = item.options.every(newItem => currentSkuData[newItem.name] == newItem.value);
if (isMatched) {
_selectedVariants.push(item);
}
});
console.log(_selectedVariants);
var leastVariant = _selectedVariants[0];
if(!leastVariant) return;
if(hasSwitchSlide){
_switch = (!switchSlide.startsWith('[') ? switchSlide.split(';') : JSON.parse(switchSlide)).map((name) => name.toLowerCase());
console.log(_switch);
};
if (
_switch.length && !_switch.includes(optName.toLowerCase())
) {
return;
}
const path = leastVariant?.image?.path?.split('.')?.[0];
SPZ.whenApiDefined(slideEle).then((api) => {
const idx = window?.onepage_product?.images?.findIndex(
(item) => item?.path?.lastIndexOf(path) !== -1
);
console.log('-选中了当前变体图片idx',idx,leastVariant);
api.goToSlide(idx || 0);
});
}
isLayoutSupported(layout) {
return layout == SPZCore.Layout.CONTAINER;;
}
}
SPZ.defineElement('spz-custom-component', SpzCustomComponent);
Item ${greater_than_or_equal_to_arr_index+1}
class SpzCustomComponent extends SPZ.BaseElement {
constructor(element) {
super(element);
}
buildCallback() {
this.setupAction_();
}
mountCallback() {
window.addEventListener('onepage.trigger.select.change',(data)=>{
const _data = data.detail;
this.updateFn(_data)
});
}
updateFn(invocation){
var actual_rate = '0.145039';
var marketingInfo =window.onepage_marketingInfo;
var price_symbol = "$" ;
window.onepage_marketingInfo = marketingInfo;
var onepageMarketingTabIndex = window.onepageMarketingTabIndex;
if (marketingInfo.marketing_rule.design.attribute_show_type == 1) {
var realValueName = '';
window.onepage_product.options.map((item, index) => {
if (index + 1 == invocation.args.name) {
realValueName = item.name;
}
});
var name = realValueName;
} else {
var name = invocation.args.name;
}
var index = invocation.args.index;
var onePage_variants_marketing_object = window.onePage_variants_marketing_object;
if (marketingInfo.marketing_rule.design.attribute_show_type == 1) {
var realValueText = '';
window.onepage_product.options.map(item => {
if (item.name == name) {
realValueText = item.values[invocation.args.value - 1];
}
});
window.onePage_variants_marketing_object[onepageMarketingTabIndex][index][name] = realValueText;
} else {
window.onePage_variants_marketing_object[onepageMarketingTabIndex][index][name] = invocation.args.value;
};
try{
if(window.need_create_order){
this.setSlideFn(onepageMarketingTabIndex,index,name)
}
}catch(e){
};
var allKeysHaveValue = window.onePage_variants_marketing_object[onepageMarketingTabIndex].every(obj => {
return Object.values(obj).every(value => value !== "");
});
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;
}
window.allKeysHaveValue = allKeysHaveValue;
if (allKeysHaveValue ) {
var product_variant_price_list = [];
var onepage_select_tab_id = 'onepageVariantsMarketingSecontTemplate' + window.onepageMarketingTabIndex;
var product_variant_id_list = [];
const selectedVariants = [];
window.onepage_product.variants.map(item => {
window.onePage_variants_marketing_object[onepageMarketingTabIndex].map(variants_item => {
let isMatched = item.options.every(newItem => variants_item[newItem.name] == newItem.value);
if (isMatched) {
selectedVariants.push(item);
product_variant_price_list.push(item.price);
product_variant_id_list.push(item.id);
}
});
});
if (window.onePage_variants_marketing_object[onepageMarketingTabIndex].length == selectedVariants.length) {
if (selectedVariants?.length) {
const currentProduct = window.onepage_product;
var triggerViewContent = ({ product, selected, qty }) => {
triggerEvent('dj.viewContent', { product: product || {}, selected: selected || {}, qty: qty || 1, source: 'pageview' });
};
var triggerEvent = (eventName, params) => {
var event = new CustomEvent(eventName, { detail: params || null, bubbles: true });
document.body?.dispatchEvent(event);
};
var holdonFun = (time) => {
return new Promise((resolve) => setTimeout(resolve, time))
};
var reduceNoRepeat = (originArr) => {
let obj = {};
let reduce = [];
reduce = originArr.reduce(function (item, next) {
if (!obj[next.id]) {
obj[next.id] = true;
next.qty = 1;
item.push(next)
} else {
let oldData = item?.find(data => data.id === next.id);
if (oldData) {
oldData.qty += 1
}
}
return item;
}, []);
return reduce;
};
const selectedVariantsArr = reduceNoRepeat(selectedVariants?.reverse());
const triggerViewContentFn = async (arr) => {
for (let i = 0; selectedVariantsArr.length > i; i++) {
const varientData = selectedVariantsArr[i];
setTimeout(() => {
triggerViewContent({ product: currentProduct, selected: varientData, qty: varientData?.qty || 1 });
}, 1000 * (i + 1))
}
};
triggerViewContentFn(selectedVariantsArr);
};
var price_sum = product_variant_price_list.reduce((a, b) => Number(a) + Number(b), 0);
var average = price_sum / product_variant_price_list.length;
if (marketingInfo.marketing_rule_template_type == 1) {
if (marketingInfo.marketing_activity_type == 0 || !marketingInfo.marketing_activity_type) {
average = average;
} else if (marketingInfo.marketing_activity_type == 1) {
average = (average - window.onepageMarketingTabIndexValue * actual_rate);
} else {
average = average * ((100 - window.onepageMarketingTabIndexValue) / 100);
};
average = Math.max(0,Number.parseFloat(average)).toFixed(2);
if (document.getElementsByClassName(onepage_select_tab_id)[0].getElementsByClassName('onepage_template1_price').length) {
document.getElementsByClassName(onepage_select_tab_id)[0].getElementsByClassName('onepage_template1_price')[0].innerHTML = price_symbol + ' ' + average;
document.getElementsByClassName(onepage_select_tab_id)[1].getElementsByClassName('onepage_template1_price')[0].innerHTML = price_symbol + ' ' + average;
}
}
if (marketingInfo.marketing_rule_template_type == 2) {
if (marketingInfo.marketing_activity_type == 0 || !marketingInfo.marketing_activity_type) {
average = average * product_variant_price_list.length;
} else if (marketingInfo.marketing_activity_type == 1) {
average = (average * product_variant_price_list.length) - window.onepageMarketingTabIndexValue * actual_rate;
} else {
average = average * ((100 - window.onepageMarketingTabIndexValue) / 100) * product_variant_price_list.length;
};
average = Math.max(0,Number.parseFloat(average)).toFixed(2);
if (document.getElementById(onepage_select_tab_id).getElementsByClassName('onepage_one_price_inner_item').length) {
document.getElementById(onepage_select_tab_id).getElementsByClassName('onepage_one_price_inner_item')[0].innerHTML = price_symbol + Math.max(0,Number.parseFloat(average)).toFixed(2);
if (document.getElementById(onepage_select_tab_id).getElementsByClassName('line-through onepage_all_price_inner').length) {
document.getElementById(onepage_select_tab_id).getElementsByClassName('line-through onepage_all_price_inner')[0].innerHTML = price_symbol + Math.max(0,Number.parseFloat(price_sum)).toFixed(2);
if (document.getElementById(onepage_select_tab_id).getElementsByClassName('custom_price_span').length) {
document.getElementById(onepage_select_tab_id).getElementsByClassName('custom_price_span')[0].innerHTML = price_symbol + Math.max(0,Number.parseFloat((average / product_variant_price_list.length))).toFixed(2);
}
if (document.getElementById(onepage_select_tab_id).getElementsByClassName('custom_total_price_dom_span').length) {
document.getElementById(onepage_select_tab_id).getElementsByClassName('custom_total_price_dom_span')[0].innerHTML = price_symbol + Math.max(0,Number.parseFloat(average)).toFixed(2);
}
}
}
}
var onepage_line_items = product_variant_id_list.reduce(function (acc, curr) {
var obj = acc.find(obj => obj.variant_id == curr);
if (obj) {
obj.quantity += 1;
} else {
acc.push({ variant_id: curr, quantity: 1 });
}
return acc;
}, []);
window.onepage_line_items = onepage_line_items;
window.all_onepage_line_items[window.onepageMarketingTabIndex] = onepage_line_items;
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'
}
};
window.renderOnepageSourceCookie();
if(!window.need_create_order) return;
var loadingEl = document.getElementById('loadingMaskOnePage');
if (loadingEl) {
loadingEl.style.display = 'block';
}
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: '12264001',
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 marketing_template_type_map = {
0: '',
1: 'template_one',
2: 'template_two',
};
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": window?.onepage_product?.id,
"marketing_type": marketing_type_map[marketingInfo.marketing_rule_type],
"marketing_template": marketing_template_type_map[marketingInfo.marketing_rule_template_type],
"discount_id": window?.onepage_discount_id,
"discount_type": discount_type[marketingInfo.marketing_activity_type],
"discount_quantity": order_quantity_sum,
"discount_value": (marketingInfo.marketing_activity_type == 0 || !marketingInfo.marketing_activity_type) ? 0 : window?.onepageMarketingTabIndexValue,
"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)
}
})
} else {
window.onepageSatisfiedCreatedOrder = false;
document.getElementById('please_select_quantity').innerHTML = 'Product is unavailable.';
window.onepage_create_order_tip = 'Product is unavailable.';
window.all_onepage_line_items[window.onepageMarketingTabIndex] = undefined;
}
}
}
setupAction_() {
this.registerAction('update', (invocation)=>{
this.updateFn(invocation)
})
}
setSlideFn(onepageMarketingTabIndex,skuIndex,optName){
var slide_ = 'onepage_product-detail-images';
var slideEle = document.getElementById(slide_);
var switchSlide='null';
console.log('switchSlide',switchSlide, typeof switchSlide);
const hasSwitchSlide = switchSlide && switchSlide !== '[]' && switchSlide !== 'null';
var _selectedVariants = [];
var _switch = [];
var currentSkuData = window.onePage_variants_marketing_object[onepageMarketingTabIndex][skuIndex];
window.onepage_product.variants.map(item => {
let isMatched = item.options.every(newItem => currentSkuData[newItem.name] == newItem.value);
if (isMatched) {
_selectedVariants.push(item);
}
});
console.log(_selectedVariants);
var leastVariant = _selectedVariants[0];
if(!leastVariant) return;
if(hasSwitchSlide){
_switch = (!switchSlide.startsWith('[') ? switchSlide.split(';') : JSON.parse(switchSlide)).map((name) => name.toLowerCase());
console.log(_switch);
};
if (
_switch.length && !_switch.includes(optName.toLowerCase())
) {
return;
}
const path = leastVariant?.image?.path?.split('.')?.[0];
SPZ.whenApiDefined(slideEle).then((api) => {
const idx = window?.onepage_product?.images?.findIndex(
(item) => item?.path?.lastIndexOf(path) !== -1
);
console.log('-选中了当前变体图片idx',idx,leastVariant);
api.goToSlide(idx || 0);
});
}
isLayoutSupported(layout) {
return layout == SPZCore.Layout.CONTAINER;;
}
}
SPZ.defineElement('spz-custom-component', SpzCustomComponent);
Item ${greater_than_or_equal_to_arr_index+1}
(Please select specifications)
class SpzCustomComponent extends SPZ.BaseElement {
constructor(element) {
super(element);
}
buildCallback() {
this.setupAction_();
}
mountCallback() {
window.addEventListener('onepage.trigger.select.change',(data)=>{
const _data = data.detail;
this.updateFn(_data)
});
}
updateFn(invocation){
var actual_rate = '0.145039';
var marketingInfo =window.onepage_marketingInfo;
var price_symbol = "$" ;
window.onepage_marketingInfo = marketingInfo;
var onepageMarketingTabIndex = window.onepageMarketingTabIndex;
if (marketingInfo.marketing_rule.design.attribute_show_type == 1) {
var realValueName = '';
window.onepage_product.options.map((item, index) => {
if (index + 1 == invocation.args.name) {
realValueName = item.name;
}
});
var name = realValueName;
} else {
var name = invocation.args.name;
}
var index = invocation.args.index;
var onePage_variants_marketing_object = window.onePage_variants_marketing_object;
if (marketingInfo.marketing_rule.design.attribute_show_type == 1) {
var realValueText = '';
window.onepage_product.options.map(item => {
if (item.name == name) {
realValueText = item.values[invocation.args.value - 1];
}
});
window.onePage_variants_marketing_object[onepageMarketingTabIndex][index][name] = realValueText;
} else {
window.onePage_variants_marketing_object[onepageMarketingTabIndex][index][name] = invocation.args.value;
};
try{
if(window.need_create_order){
this.setSlideFn(onepageMarketingTabIndex,index,name)
}
}catch(e){
};
var allKeysHaveValue = window.onePage_variants_marketing_object[onepageMarketingTabIndex].every(obj => {
return Object.values(obj).every(value => value !== "");
});
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;
}
window.allKeysHaveValue = allKeysHaveValue;
if (allKeysHaveValue ) {
var product_variant_price_list = [];
var onepage_select_tab_id = 'onepageVariantsMarketingSecontTemplate' + window.onepageMarketingTabIndex;
var product_variant_id_list = [];
const selectedVariants = [];
window.onepage_product.variants.map(item => {
window.onePage_variants_marketing_object[onepageMarketingTabIndex].map(variants_item => {
let isMatched = item.options.every(newItem => variants_item[newItem.name] == newItem.value);
if (isMatched) {
selectedVariants.push(item);
product_variant_price_list.push(item.price);
product_variant_id_list.push(item.id);
}
});
});
if (window.onePage_variants_marketing_object[onepageMarketingTabIndex].length == selectedVariants.length) {
if (selectedVariants?.length) {
const currentProduct = window.onepage_product;
var triggerViewContent = ({ product, selected, qty }) => {
triggerEvent('dj.viewContent', { product: product || {}, selected: selected || {}, qty: qty || 1, source: 'pageview' });
};
var triggerEvent = (eventName, params) => {
var event = new CustomEvent(eventName, { detail: params || null, bubbles: true });
document.body?.dispatchEvent(event);
};
var holdonFun = (time) => {
return new Promise((resolve) => setTimeout(resolve, time))
};
var reduceNoRepeat = (originArr) => {
let obj = {};
let reduce = [];
reduce = originArr.reduce(function (item, next) {
if (!obj[next.id]) {
obj[next.id] = true;
next.qty = 1;
item.push(next)
} else {
let oldData = item?.find(data => data.id === next.id);
if (oldData) {
oldData.qty += 1
}
}
return item;
}, []);
return reduce;
};
const selectedVariantsArr = reduceNoRepeat(selectedVariants?.reverse());
const triggerViewContentFn = async (arr) => {
for (let i = 0; selectedVariantsArr.length > i; i++) {
const varientData = selectedVariantsArr[i];
setTimeout(() => {
triggerViewContent({ product: currentProduct, selected: varientData, qty: varientData?.qty || 1 });
}, 1000 * (i + 1))
}
};
triggerViewContentFn(selectedVariantsArr);
};
var price_sum = product_variant_price_list.reduce((a, b) => Number(a) + Number(b), 0);
var average = price_sum / product_variant_price_list.length;
if (marketingInfo.marketing_rule_template_type == 1) {
if (marketingInfo.marketing_activity_type == 0 || !marketingInfo.marketing_activity_type) {
average = average;
} else if (marketingInfo.marketing_activity_type == 1) {
average = (average - window.onepageMarketingTabIndexValue * actual_rate);
} else {
average = average * ((100 - window.onepageMarketingTabIndexValue) / 100);
};
average = Math.max(0,Number.parseFloat(average)).toFixed(2);
if (document.getElementsByClassName(onepage_select_tab_id)[0].getElementsByClassName('onepage_template1_price').length) {
document.getElementsByClassName(onepage_select_tab_id)[0].getElementsByClassName('onepage_template1_price')[0].innerHTML = price_symbol + ' ' + average;
document.getElementsByClassName(onepage_select_tab_id)[1].getElementsByClassName('onepage_template1_price')[0].innerHTML = price_symbol + ' ' + average;
}
}
if (marketingInfo.marketing_rule_template_type == 2) {
if (marketingInfo.marketing_activity_type == 0 || !marketingInfo.marketing_activity_type) {
average = average * product_variant_price_list.length;
} else if (marketingInfo.marketing_activity_type == 1) {
average = (average * product_variant_price_list.length) - window.onepageMarketingTabIndexValue * actual_rate;
} else {
average = average * ((100 - window.onepageMarketingTabIndexValue) / 100) * product_variant_price_list.length;
};
average = Math.max(0,Number.parseFloat(average)).toFixed(2);
if (document.getElementById(onepage_select_tab_id).getElementsByClassName('onepage_one_price_inner_item').length) {
document.getElementById(onepage_select_tab_id).getElementsByClassName('onepage_one_price_inner_item')[0].innerHTML = price_symbol + Math.max(0,Number.parseFloat(average)).toFixed(2);
if (document.getElementById(onepage_select_tab_id).getElementsByClassName('line-through onepage_all_price_inner').length) {
document.getElementById(onepage_select_tab_id).getElementsByClassName('line-through onepage_all_price_inner')[0].innerHTML = price_symbol + Math.max(0,Number.parseFloat(price_sum)).toFixed(2);
if (document.getElementById(onepage_select_tab_id).getElementsByClassName('custom_price_span').length) {
document.getElementById(onepage_select_tab_id).getElementsByClassName('custom_price_span')[0].innerHTML = price_symbol + Math.max(0,Number.parseFloat((average / product_variant_price_list.length))).toFixed(2);
}
if (document.getElementById(onepage_select_tab_id).getElementsByClassName('custom_total_price_dom_span').length) {
document.getElementById(onepage_select_tab_id).getElementsByClassName('custom_total_price_dom_span')[0].innerHTML = price_symbol + Math.max(0,Number.parseFloat(average)).toFixed(2);
}
}
}
}
var onepage_line_items = product_variant_id_list.reduce(function (acc, curr) {
var obj = acc.find(obj => obj.variant_id == curr);
if (obj) {
obj.quantity += 1;
} else {
acc.push({ variant_id: curr, quantity: 1 });
}
return acc;
}, []);
window.onepage_line_items = onepage_line_items;
window.all_onepage_line_items[window.onepageMarketingTabIndex] = onepage_line_items;
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'
}
};
window.renderOnepageSourceCookie();
if(!window.need_create_order) return;
var loadingEl = document.getElementById('loadingMaskOnePage');
if (loadingEl) {
loadingEl.style.display = 'block';
}
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: '12264001',
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 marketing_template_type_map = {
0: '',
1: 'template_one',
2: 'template_two',
};
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": window?.onepage_product?.id,
"marketing_type": marketing_type_map[marketingInfo.marketing_rule_type],
"marketing_template": marketing_template_type_map[marketingInfo.marketing_rule_template_type],
"discount_id": window?.onepage_discount_id,
"discount_type": discount_type[marketingInfo.marketing_activity_type],
"discount_quantity": order_quantity_sum,
"discount_value": (marketingInfo.marketing_activity_type == 0 || !marketingInfo.marketing_activity_type) ? 0 : window?.onepageMarketingTabIndexValue,
"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)
}
})
} else {
window.onepageSatisfiedCreatedOrder = false;
document.getElementById('please_select_quantity').innerHTML = 'Product is unavailable.';
window.onepage_create_order_tip = 'Product is unavailable.';
window.all_onepage_line_items[window.onepageMarketingTabIndex] = undefined;
}
}
}
setupAction_() {
this.registerAction('update', (invocation)=>{
this.updateFn(invocation)
})
}
setSlideFn(onepageMarketingTabIndex,skuIndex,optName){
var slide_ = 'onepage_product-detail-images';
var slideEle = document.getElementById(slide_);
var switchSlide='null';
console.log('switchSlide',switchSlide, typeof switchSlide);
const hasSwitchSlide = switchSlide && switchSlide !== '[]' && switchSlide !== 'null';
var _selectedVariants = [];
var _switch = [];
var currentSkuData = window.onePage_variants_marketing_object[onepageMarketingTabIndex][skuIndex];
window.onepage_product.variants.map(item => {
let isMatched = item.options.every(newItem => currentSkuData[newItem.name] == newItem.value);
if (isMatched) {
_selectedVariants.push(item);
}
});
console.log(_selectedVariants);
var leastVariant = _selectedVariants[0];
if(!leastVariant) return;
if(hasSwitchSlide){
_switch = (!switchSlide.startsWith('[') ? switchSlide.split(';') : JSON.parse(switchSlide)).map((name) => name.toLowerCase());
console.log(_switch);
};
if (
_switch.length && !_switch.includes(optName.toLowerCase())
) {
return;
}
const path = leastVariant?.image?.path?.split('.')?.[0];
SPZ.whenApiDefined(slideEle).then((api) => {
const idx = window?.onepage_product?.images?.findIndex(
(item) => item?.path?.lastIndexOf(path) !== -1
);
console.log('-选中了当前变体图片idx',idx,leastVariant);
api.goToSlide(idx || 0);
});
}
isLayoutSupported(layout) {
return layout == SPZCore.Layout.CONTAINER;;
}
}
SPZ.defineElement('spz-custom-component', SpzCustomComponent);
${repetPrice(second_value.title,onepage_actual_price,second_value.greater_than_or_equal_to,second_value.value,second_value.uuid)}
${repetDiscountText(second_value.discount_text, second_value.value)}
$ ${ computedPrice(onepage_actual_price,second_value.greater_than_or_equal_to,second_value.value)}
$ ${Number.parseFloat(onepage_actual_price * second_value.greater_than_or_equal_to).toFixed(2)}
`
}()}