Posse hat
people are viewing this right now
${function() {
const variantData = data.variant || {"id":"f5a515ac-5f3a-42c9-a42f-daa6e8915b4b","product_id":"b285a672-f0a3-496a-b4ca-8e23cbc8ec71","title":"S","weight_unit":"kg","inventory_quantity":999,"sku":"TF42301179TDHL","barcode":"","position":1,"option1":"S","option2":"","option3":"","note":"","image":{"src":"\/\/img.staticdj.com\/802dfef4824d17fd5f5aea584a006d7e.png","path":"802dfef4824d17fd5f5aea584a006d7e.png","width":720,"height":720,"alt":"Posse hat","aspect_ratio":1},"wholesale_price":[{"price":69.98,"min_quantity":1}],"weight":"0","compare_at_price":"142.57","price":"69.98","retail_price":"142.57","available":true,"url":"\/products\/posse-hat?variant=f5a515ac-5f3a-42c9-a42f-daa6e8915b4b","available_quantity":999999999,"options":[{"name":"Size","value":"S"}],"off_ratio":"51","flashsale_info":{"variant_id":"f5a515ac-5f3a-42c9-a42f-daa6e8915b4b","product_id":"","quantity":0,"discount_id":"","limit_time":0,"limit_buy":0,"user_limit_buy":0,"discount_sales":0,"discount_sales_rate":"","discount_stock":0,"ends_at":0,"starts_at":0,"allow_oversold":"","allocation_method":"","price":"69.98","compare_at_price":"","discount_price":"69.98","customary_saved_price":"","customary_off_ratio":"","discount_saved_price":"","discount_off_ratio":"51","use_before_price":false,"before_price":"","title":"","properties":"","color_setting_promotional_copy":"","discount_quantity":0,"is_need_split":false},"sales":2};
const saveType = "percentage";
const productLabelDiscountOn = true;
return `
-
${saveType == 'percentage'
? `-${variantData.off_ratio}% `
: `- `
}
`;
}()}
${function(){
const dd = data.dd; const hh = data.hh; const mm = data.mm; const ss = data.ss; const sss = data.SSS;
const hours = data.d * 24 + data.h;
return `
${dd}D
·
${hours}
${hh}
:
${mm}
:
${ss}
.
${sss}
`
}()}
class SpzCustomDiscountFlashsale extends SPZ.BaseElement {
constructor(element) {
super(element);
this.xhr_ = SPZServices.xhrFor(this.win);
this.getFlashSaleApi = "\/api\/storefront\/promotion\/flashsale\/display_setting\/product_setting";
this.timer = null;
this.variantId = "f5a515ac-5f3a-42c9-a42f-daa6e8915b4b";
// 促销活动数据
this.flashsaleData = {}
}
isLayoutSupported(layout) {
return layout == SPZCore.Layout.CONTAINER;
}
buildCallback() {
this.templates_ = SPZServices.templatesForDoc();
this.viewport_ = this.getViewport();
// 挂载bind函数 解决this指向问题
this.render = this.render.bind(this);
this.resize = this.resize.bind(this);
this.switchVariant = this.switchVariant.bind(this);
}
mountCallback() {
// 获取数据
this.getData();
this.element.onclick = (e) => {
const cur = this.win.document.querySelector(".app_discount_flashsale_desc");
const setting = this.flashsaleData.product_setting;
const landingUrl = `/promotions/discount-default/${this.flashsaleData.discount_info.id}`;
const finalUrl = appDiscountUtils.resolveDiscountHref(setting, landingUrl);
if (finalUrl && appDiscountUtils.inProductBody(this.element) && e.target !== cur) {
this.win.open(finalUrl, '_blank', 'noopener');
}
}
// 绑定
this.viewport_.onResize(this.resize);
// 监听子款式切换,重新渲染
this.win.document.addEventListener('dj.variantChange', this.switchVariant);
}
unmountCallback() {
// 解绑
this.viewport_.removeResize(this.resize);
this.win.document.removeEventListener('dj.variantChange', this.switchVariant);
// 清除定时器
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
}
}
resize() {
if (this.timer) {
clearTimeout(this.timer)
this.timer = null;
}
this.timer = setTimeout(() => {
this.render();
}, 200)
}
switchVariant(event) {
const variant = event.detail.selected;
if (variant.product_id == 'b285a672-f0a3-496a-b4ca-8e23cbc8ec71' && variant.id != this.variantId) {
this.variantId = variant.id;
this.getData();
}
}
getData() {
const reqBody = {
product_id: "b285a672-f0a3-496a-b4ca-8e23cbc8ec71",
product_type: "default",
variant_id: this.variantId
}
this.flashsaleData = {};
this.win.fetch(this.getFlashSaleApi, {
method: "POST",
body: JSON.stringify(reqBody),
headers: {
"Content-Type": "application/json"
}
}).then(async (response) => {
if (response.ok) {
this.flashsaleData = await response.json();
this.render();
} else {
this.clearDom();
}
}).catch(err => {
this.clearDom();
});
}
clearDom() {
const children = this.element.querySelector('*:not(template)');
children && SPZCore.Dom.removeElement(children);
}
render() {
this.templates_
.findAndRenderTemplate(this.element, {
isMobile: appDiscountUtils.judgeMobile(),
isRTL: appDiscountUtils.judgeRTL(),
inProductDetail: appDiscountUtils.inProductBody(this.element),
flashsaleData: this.flashsaleData,
image_domain: this.win.SHOPLAZZA.image_domain,
})
.then((el) => {
this.clearDom();
this.element.appendChild(el);
})
}
}
SPZ.defineElement('spz-custom-discount-flashsale', SpzCustomDiscountFlashsale);
Size:
S
${function(){
const optName = "Size";
const optionValue = data.originData.selectData ? data.originData.selectData[optName].value : data.originData.value;
const optionValueText = optionValue ? (optionValue) : '';
return `${optionValueText} `;
}()}
${function(){
const tipText = "Please select a {{ name }}".replace(/\{\{\s+name\s+\}\}/g, data);
return `${tipText}
`
}()}
Add to cart
$69.98
${function(){
const wholesale_enabled = false;
const qty = data.quantity || 1;
const currentSelectVariant = data.variant;
const defaultVariant = (data.product && data.product.variants && data.product.variants[0]);
const productVariant = {"id":"f5a515ac-5f3a-42c9-a42f-daa6e8915b4b","product_id":"b285a672-f0a3-496a-b4ca-8e23cbc8ec71","title":"S","weight_unit":"kg","inventory_quantity":999,"sku":"TF42301179TDHL","barcode":"","position":1,"option1":"S","option2":"","option3":"","note":"","image":{"src":"\/\/img.staticdj.com\/802dfef4824d17fd5f5aea584a006d7e.png","path":"802dfef4824d17fd5f5aea584a006d7e.png","width":720,"height":720,"alt":"Posse hat","aspect_ratio":1},"wholesale_price":[{"price":69.98,"min_quantity":1}],"weight":"0","compare_at_price":"142.57","price":"69.98","retail_price":"142.57","available":true,"url":"\/products\/posse-hat?variant=f5a515ac-5f3a-42c9-a42f-daa6e8915b4b","available_quantity":999999999,"options":[{"name":"Size","value":"S"}],"off_ratio":"51","flashsale_info":{"variant_id":"f5a515ac-5f3a-42c9-a42f-daa6e8915b4b","product_id":"","quantity":0,"discount_id":"","limit_time":0,"limit_buy":0,"user_limit_buy":0,"discount_sales":0,"discount_sales_rate":"","discount_stock":0,"ends_at":0,"starts_at":0,"allow_oversold":"","allocation_method":"","price":"69.98","compare_at_price":"","discount_price":"69.98","customary_saved_price":"","customary_off_ratio":"","discount_saved_price":"","discount_off_ratio":"51","use_before_price":false,"before_price":"","title":"","properties":"","color_setting_promotional_copy":"","discount_quantity":0,"is_need_split":false},"sales":2};
const variantData = currentSelectVariant || defaultVariant || productVariant;
const wholesale_price = variantData.wholesale_price || [];
if(wholesale_enabled && wholesale_price.length > 0) {
let wholesaleIndex = wholesale_price.findIndex(item => {
return item.min_quantity > qty;
});
if(wholesaleIndex < 0){
wholesaleIndex = wholesale_price.length - 1;
}else if(wholesaleIndex > 0){
wholesaleIndex = wholesaleIndex - 1;
}
const wholesalePrice = wholesale_price[wholesaleIndex] || '';
return `
`
}else {
const price = variantData && variantData.price;
return price != undefined ? `
` : ' ';
}
}()}
Buy now
Product was out of stock.
Product is unavailable.
BUY 2 GET 1 FREE SHIPPING
7-15 Days Delivery with Tracking
Secure Checkout & 30-Day Money Back
${function() {
const minDays = parseInt('7');
const maxDays = parseInt('15');
const customText = "Estimated Delivery\uff1a{min_date} - {max_date}\n( Includes a tracking number \u2013 dispatched within 48 hours of dispatch )";
const minDate = new Date(Date.now() + (minDays * 86400000));
const maxDate = new Date(Date.now() + (maxDays * 86400000));
const formatDate = (minDate.getFullYear() == maxDate.getFullYear() && minDate.getFullYear() == new Date().getFullYear())
? new Intl.DateTimeFormat('en', { month: 'short', day: '2-digit' })
: new Intl.DateTimeFormat('en', { month: 'short', day: '2-digit', year: 'numeric' });
const tipText = customText.replace(/\{min_date\}/g, '' + formatDate.format(minDate) + ' ')
.replace(/\{max_date\}/g, '' + formatDate.format(maxDate) + ' ');
return `
${tipText}
`;
}()}
${function() {
const postageFreeAmount = 59;
const custom_text = "\ud83c\udf81 Buy $59.00 more to enjoy FREE Shipping";
const totalPrice = +data.total_price;
const diffPrice = postageFreeAmount - totalPrice;
const percentDiff = (diffPrice > 0 ? (totalPrice / postageFreeAmount * 100) : 100) + '%';
let tipText = "Your order is free delivery";
if (diffPrice > 0) {
tipText = custom_text.replace('{amount}', `
`);
}
return `
`;
}()}