${function() {
const variantData = data.variant || {"id":"ea7d0a7b-7a3b-4d2e-b9a7-eb01e8cd6b0a","product_id":"9187ddce-ddaf-418e-b10d-d7aad21fcfec","title":"3 blades-1 pc-200mm(7.87\")","weight_unit":"g","inventory_quantity":99,"sku":"","barcode":"","position":1,"option1":"3 blades","option2":"1 pc","option3":"200mm(7.87\")","note":"","image":null,"wholesale_price":[{"price":25.99,"min_quantity":1}],"weight":"300","compare_at_price":"50.99","price":"25.99","retail_price":"50.99","available":true,"url":"\/products\/steel-wire-trimmer-head?variant=ea7d0a7b-7a3b-4d2e-b9a7-eb01e8cd6b0a","available_quantity":99,"options":[{"name":"Blades","value":"3 blades"},{"name":"Quantity","value":"1 pc"},{"name":"Size","value":"200mm(7.87\")"}],"off_ratio":49,"flashsale_info":[],"sales":0};
return `
`;
}()}
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);
${function(){
const quantityValue = data?.quantity || false;
return `
`
}()}
Please select product quantity
Buy now