SKU: QT39
The current produc does not participate any Rebate. Switch the participating product to check the design.
(This prompt will not be displayed on the client-side.)
${function() {
const show = rebate.format_rules.length > data.maxShowCount;
return `
${rule}
${function() {
if(!show) return "";
return `
`;
}()}
`;
}()}
${originData.rebate.format_rules.join(", ")}
if(window.self === window.top) {
(window.disabled_exts ||=[]).push('product_detail_rebate');
}
class SpzRebateComponent extends SPZ.BaseElement {
constructor(element) {
super(element);
}
xhr_ = SPZServices.xhrFor(this.win);
viewport_ = this.getViewport();
action_ = null;
lang = document.documentElement.lang || 'en-US';
i18n = {"ar-SA":{"special_offer":"ุนุฑุถ ุฎุงุต","close":"ุฅุบูุงู"},"de-DE":{"special_offer":"Sonderangebot","close":"Schlieรen"},"en-US":{"special_offer":"SPECIAL OFFER","close":"CLOSE"},"es-ES":{"special_offer":"Oferta especial","close":"Cerrar"},"fr-FR":{"special_offer":"Offre spรฉciale","close":"Fermer"},"id-ID":{"special_offer":"Penawaran istimewa","close":"Tutup"},"it-IT":{"special_offer":"Offerta speciale","close":"Chiudi"},"ja-JP":{"special_offer":"็นๅฅใชใชใใกใผ","close":"้ใใ"},"ko-KR":{"special_offer":"ํน๋ณ ๋ฉ๋ด","close":"๋ซ๊ธฐ"},"nl-NL":{"special_offer":"Speciale aanbieding","close":"sluiten"},"pl-PL":{"special_offer":"Oferta specjalna","close":"blisko"},"pt-PT":{"special_offer":"Oferta especial","close":"Fechar"},"ru-RU":{"special_offer":"ะกะฟะตัะธะฐะปัะฝะพะต ะฟัะตะดะปะพะถะตะฝะธะต","close":"ะะฐะบัััั"},"th-TH":{"special_offer":"เธเนเธญเนเธชเธเธญเธเธดเนเธจเธฉ","close":"เธเธดเธ"},"zh-CN":{"special_offer":"็นไปท","close":"ๅ
ณ้ญ"},"zh-TW":{"special_offer":"็นๅน","close":"้้"}};
landPage = "\/promotions\/rebate\/";
pageType = 1;
cart = {"line_items":[{"id":"1236409045_d41d8cd98f00b204e9800998ecf8427e","properties":"[]","note":null,"cart_id":"1236409045","store_id":"279806","user_id":"","user_sign":"abd4558d-7d9f-422f-868b-a25c348e8143","product_id":"29efb683-bb41-42bb-968e-87e7e78918be","variant_id":"5562f80b-4f9c-441f-9174-0cb7b1dfc7b7","quantity":"1","created_at":"2023-10-02 11:02:17","updated_at":"2023-10-02 11:02:17","custom":false,"price":"6.99","trunk_price":"0","parts_price":null,"variant_title":"","product_title":"Temperature Color Changing Purple Diamond Glitter Poly Nail Gel","product_handle":"morovan-temperature-color-changing-purple-diamond-glitter-poly-nail-gel-p246","product_tags":["Beginner Set","Beginner","Single poly nail gel","polygel","poly nail gel","Polygel colors","Poly gel","poly gel kit","Extension Nail Gel","Extension Gel","Temperature Color Changing Poly Gel","black poly nail gel"],"published":true,"published_at":"2023-01-14T07:38:41Z","product_url":"\/products\/morovan-temperature-color-changing-purple-diamond-glitter-poly-nail-gel-p246","inventory_quantity":695,"inventory_policy":"deny","inventory_tracking":true,"available":true,"available_quantity":695,"compare_at_price":"6.99","cost_price":"3.60","weight":"0.03","weight_unit":"kg","sku":"PS50-P246","spu":"","vendor":"MOROVAN","vendor_url":"","taxable":false,"requires_shipping":true,"barcode":"","mixed_wholesale":false,"tax_code":"","retail_price":"0.00","product_type":"","image":{"src":"\/\/img.fantaskycdn.com\/a8c6762ab80a905432b8aa5f5fdf8ebc.jpg","path":"a8c6762ab80a905432b8aa5f5fdf8ebc.jpg","width":800,"height":800,"alt":""},"options":[],"wholesale_price":[{"min_quantity":1,"price":"6.99"}],"total_price":"0","discount_applications":[],"saved_price":0,"line_price":"6.99","original_line_price":6.99,"customary_off_ratio":0,"flashsale_tip":false,"item_id":"1236409045","can_buy":true,"fixed_discount_total":"0.00","discount_total":"0.00","final_line_price":"6.99","final_price":"6.99"},{"id":"1236408817_d41d8cd98f00b204e9800998ecf8427e","properties":"","note":null,"cart_id":"1236408817","store_id":"279806","user_id":"","user_sign":"abd4558d-7d9f-422f-868b-a25c348e8143","product_id":"247296cf-392d-4783-a578-5db45a759948","variant_id":"52245823-df7a-4ea5-863b-9a8a2d755e28","quantity":"1","created_at":"2023-10-02 11:01:54","updated_at":"2023-10-02 11:01:54","custom":false,"price":"9","trunk_price":"0","parts_price":null,"variant_title":"P027,P074,P156,P168,P198","product_title":"Stage Star - 5 Colors 15ml Poly Nail Gel Set","product_handle":"morovan-clear-poly-nail-gel-dlzd9p4","product_tags":["Poly gel","Polygel","Poly nail gel","Poly","polygel","poly gel","Poly nail","poly nail gel","poly","Poly gel nail","Poly gel colors","Polygel colors","Polyge","poly gel nail","morovan poly nail gel","Poly gel nails","Poly Nail gel","Poly Nail Gel","Single poly nail gel","Single Poly Nail Gel","Gel","gel","Hard gel","hard gel"],"published":true,"published_at":"2023-09-11T06:17:47Z","product_url":"\/products\/morovan-clear-poly-nail-gel-dlzd9p4","inventory_quantity":956,"inventory_policy":"deny","inventory_tracking":true,"available":true,"available_quantity":956,"compare_at_price":"34.95","cost_price":"22.50","weight":"150.00","weight_unit":"g","sku":"DLZD9P4","spu":"","vendor":"MOROVAN","vendor_url":"","taxable":false,"requires_shipping":true,"barcode":"","mixed_wholesale":false,"tax_code":"","retail_price":"0.00","product_type":"","image":{"src":"\/\/img.fantaskycdn.com\/022dda6eeca7302fffd8f30d96fe546a.jpg","path":"022dda6eeca7302fffd8f30d96fe546a.jpg","width":1000,"height":1000,"alt":""},"options":[{"name":"Color","value":"P027,P074,P156,P168,P198"}],"wholesale_price":[{"min_quantity":1,"price":"9.00"}],"total_price":"0","discount_applications":[],"saved_price":25.95,"line_price":"9.00","original_line_price":34.95,"customary_off_ratio":74,"flashsale_tip":false,"item_id":"1236408817","can_buy":true,"fixed_discount_total":"0.00","discount_total":"0.00","final_line_price":"9.00","final_price":"9.00"}],"ineffectives":[],"invalid_msg":"","currency":null,"note":"","created_at":"2023-10-02T03:01:54Z","updated_at":"2023-10-02T03:02:17Z","item_count":2,"original_line_price":"41.94","original_total_price":"41.94","line_price":"15.99","total_price":"15.99","total_discount":"0.00","total_weight":150.03,"discount_line_item_price":"0.00","discount_applications":[]};
initData = null;
rebateInfo = null;
renderData = null;
footerImage = `${this.win.SHOPLAZZA["image_domain"]}oss/operation/e8ebb03dbb710457ca3b4b6a70898ab2.svg`;
isLayoutSupported(layout) {
return layout == SPZCore.Layout.LOGIC;
}
buildCallback() {
this.initData = this.getProduct();
this.action_ = SPZServices.actionServiceForDoc(this.element);
this.registerAction("triggerGetRenderData", () => {
const event = SPZUtils.Event.create(this.win, "triggerGetRenderData", this.renderData);
this.action_.trigger(this.element, "getRenderData", event);
});
this.registerAction("bindPropagation", () => {
document.querySelector(".product_detail_rebate_list").addEventListener("click", e => {
e.stopPropagation();
this.win.sa &&
this.win.sa.track("plugin_rebate_promotion_click", {
plugin_timestamp: Date.now(),
plugin_location: "info",
product_id: this.initData.product.id,
discount_id: this.rebateInfo.discount_list.map((item) => item.discount_id)[0],
});
});
});
}
async mountCallback() {
document.addEventListener("dj.variantChange", e => {
const data = e.detail;
if (document.querySelector("#product-select-modal.show")) return;
if (this.initData && this.initData.product && data.product && this.initData.product.id === data.product.id) {
this.initData = data;
this.initRebate(this.initData, true);
} else {
this.initData = data;
this.getRebateInfo();
}
});
document.addEventListener("dj.addToCart", e => {
const v = e.detail;
this.rebateInfo &&
this.win.sa &&
this.win.sa.track("plugin_rebate_atc", {
variant_discount_id: this.getVariantDiscountId(v.variant_id).map(item => item.discount_id),
discount_ids: this.rebateInfo.discount_list.map(item => item.discount_id),
variant_id: v.variant_id,
product_id: v.product_id,
price: v.item_price,
number: v.number,
});
});
await this.getRebateInfo();
if (document.querySelector(".plugin-container__bottom-fixed")) {
this.showDiscountPopupsInfoBar();
} else {
this.win.addEventListener("extloaded", () => {
this.showDiscountPopupsInfoBar();
});
}
}
getProduct = (() => {
document.addEventListener("dj.variantChange", e => {
if (!e.detail || !e.detail.product) return;
const productJson = document.querySelector("#product-json");
if (productJson && productJson.textContent && JSON.parse(productJson.textContent)) {
productJson.textContent = JSON.stringify(e.detail);
}
if (this.win.jQuery && this.win.jQuery.fn && this.win.jQuery(document).data("djproduct")) {
this.win.jQuery(document).data("djproduct", e.detail);
}
});
return () => {
let productData = null;
if (this.win.jQuery && this.win.jQuery.fn) {
try {
let product = this.win.jQuery(document).data("djproduct");
if (product) {
productData = JSON.parse(JSON.stringify(product));
} else {
productData = null;
}
} catch (error) {
productData = null;
}
}
if (!productData) {
const productJson = document.querySelector("#product-json");
productData = (productJson && productJson.textContent && JSON.parse(productJson.textContent)) || null;
}
return productData;
};
})();
initRebate = this.win.SPZCore.Types.debounce(
this.win,
((data, variantChange) => {
let discount_list = Object.assign([], this.rebateInfo.discount_list);
/* ๆๅญๅๅ็ๅคๅฐๅฏนไผๆ ไฟกๆฏ่ฟ่กๆๅบ */
discount_list &&
discount_list.sort((a, b) => {
return b.variant_ids.length - a.variant_ids.length;
});
/* ้ไธญๅญๅๅๆถ ็ญ้ๅญๅๅ็ไผๆ ไฟกๆฏ */
if (data.selected && data.selected.id) {
discount_list = this.getVariantDiscountId(data.selected.id);
}
/* ๆ ๆปกๅไฟกๆฏ */
if (!(discount_list && discount_list.length)) {
return;
}
const isSection = !!document.querySelector(
`div[data-section-type^="shoplazza://apps/publicapp/blocks/rebate"] #rebate_custom_component`
);
if (
(this.rebateInfo.rebate_type == "sku" && data && data.selected && data.selected.id) ||
this.rebateInfo.rebate_type == "spu"
) {
if (discount_list[0]) {
this.landPage += discount_list[0].discount_id || "";
}
const info = {
rebate: discount_list[0],
maxShowCount: this.win.innerWidth > 768 ? 3 : 1,
landPage: this.landPage,
modalFooterImg: `url(${`${this.win.SHOPLAZZA["image_domain"]}oss/operation/e8ebb03dbb710457ca3b4b6a70898ab2.svg`})`,
i18n: this.i18n[this.lang]
};
this.renderData = info;
SPZ.whenApiDefined(
document.getElementById(isSection ? "app_rebate_section" : "app_rebate_block")
).then(apis => {
apis.render(info, true);
});
}
this.insertSlideTag(this.rebateInfo.tag, variantChange);
var pluginCurrencyEvent = new CustomEvent("plugin_currency_update");
document.dispatchEvent(pluginCurrencyEvent);
}).bind(this),
10
);
getRebateInfo = async () => {
if (this.initData && this.initData.product && this.initData.product.id) {
var variant_ids = this.initData.product.variants.map(variant => variant.id);
const res = await this.xhr_.fetchJson(
"\/api\/discount-rebate\/product-discount",
{
method: "POST",
body: {
product_id: this.initData.product.id,
product_type: this.initData.product.product_type,
variant_ids: variant_ids,
},
}
);
if (!SPZCore.Types.isEmptyObject(res.rebate_info)) {
res.rebate_info.tag = res.tag;
res.rebate_info.rebate_type = res.rebate_type;
this.rebateInfo = res.rebate_info;
this.initRebate(this.initData);
} else {
if (this.win.top !== this.win.self) {
const noActivity = document.getElementById("no-rebate-activity");
noActivity && (noActivity["style"].display = "block");
}
}
}
};
getVariantDiscountId = (variant_id) => {
if (!variant_id || !this.rebateInfo) return [];
var rebateId = this.rebateInfo.variant_discount_map[variant_id];
return this.rebateInfo.discount_list.filter(item => item.discount_id == rebateId) || [];
};
insertSlideTag = (tag, variantChange) => {
setTimeout(() => {
if (tag) {
var tag_container;
var modal = document.getElementById("product-select-modal");
if (modal && modal.classList.contains("show")) {
if (!variantChange && modal.querySelector(".slider-discount-tag")) return;
if (
variantChange &&
modal.querySelector(".slider-discount-tag:not(.rebate-tag)")
)
return;
tag_container = modal;
} else {
var product_detail_card = document.querySelector(
'.page_container > [data-section-type="product_detail"], .page_container > [data-section-type="product-template"]'
);
if(!product_detail_card) return;
if (!variantChange && product_detail_card.querySelector(".slider-discount-tag")) return;
if (variantChange && product_detail_card.querySelector(".slider-discount-tag:not(.rebate-tag)"))
return;
tag_container = product_detail_card;
}
if (tag_container.matches("#product-select-modal") && this.pageType === 13 && document.documentElement.clientWidth < 768)
return;
const tagDom = `<div class="slider-discount-tag dj_skin_product_title rebate-tag">${tag}</div>`
if (document.querySelector(".sep-loaded-slider")) {
var loadedSlider = tag_container.querySelector(".sep-loaded-slider");
loadedSlider.querySelectorAll(".slider-discount-tag").forEach(function(element) {
element.remove();
});
loadedSlider.insertAdjacentHTML("beforeend", tagDom);
} else {
if (tag_container.querySelector(".support-slick")) {
var supportSlick = tag_container.querySelectorAll(".support-slick, .sep-slider");
supportSlick.forEach((element) => {
element.querySelectorAll(".slider-discount-tag").forEach((element) => {
element.remove();
});
element.insertAdjacentHTML("beforeend",tagDom);
});
} else {
var sepSlider = tag_container.querySelector(".sep-slider");
sepSlider.querySelectorAll(".slider-discount-tag").forEach(function(element) {
element.remove();
});
sepSlider.insertAdjacentHTML("beforeend",tagDom);
}
}
if (document.documentElement.clientWidth < 768) {
const sliderDiscountTagHeight = tag_container.querySelector(".slider-discount-tag").offsetHeight || 0;
document.querySelector(".product-image__swiper_bullets").style.bottom = `${sliderDiscountTagHeight + 15}px`;
}
}
}, 1000);
};
fetchInfoBar = () => {
let discount_ids = [];
if (this.pageType === 1) {
discount_ids = this.rebateInfo && this.rebateInfo.discount_list.map(item => item.discount_id);
} else if (this.pageType === 38) {
discount_ids = [this.win.rebateObj.rebateCollection_id] || [];
}
const productObj = this.getProduct();
return this.xhr_.fetchJson("\/api\/discount-rebate\/global-text", {
method: "POST",
body: {
product_type: productObj && productObj.product && productObj.product.product_type,
line_items: (this.cart.line_items || []).map(item => ({
variant_id: item.variant_id,
product_id: item.product_id,
quantity: item.quantity,
price: item.price,
selected: !item.unchecked,
})),
discount_ids: discount_ids,
},
});
};
renderBottomBanner = res => {
if (!res.tips) return;
if (document.querySelector(".discount__info-bar")) return;
var bar_style = `background:linear-gradient(90deg,${res.config.background_color_start},${res.config.background_color_end}); color:${res.config.color};`;
let data = { tips: res.tips, landPage: this.landPage + res.id, bar_style };
const html = SPZCore.Dom.htmlFor(this.element);
const banner = html([
`<a impr="1" imprevt="1" id="rebate_bottom_bar" href=${data.landPage} class="discount__info-bar text-truncate" data-activity-type="rebate" style="${data.bar_style}">${data.tips}</a>`,
]);
document.querySelector(".plugin-container__bottom-fixed").appendChild(banner);
const pluginCurrencyEvent = new CustomEvent("plugin_currency_update");
document.dispatchEvent(pluginCurrencyEvent);
if (res.id) {
var trackParams = {
page: this.pageType,
discount_id: res.id,
product_id: this.getProduct()?.product.id,
};
banner.addEventListener("click", () => {
this.win.sa &&
this.win.sa.track("plugin_rebate_promotion_click", {
plugin_timestamp: Date.now(),
plugin_location: "bottom_bar",
product_id: trackParams.product_id,
discount_id: trackParams.discount_id,
});
});
this.win.sa && this.win.sa.track("plugin_rebate_banner_pv", trackParams);
}
};
showDiscountPopupsInfoBar = () => {
if ([13, 14, 19, 30, 31].includes(this.pageType)) return;
if (document.querySelector(".plugin-container__bottom-fixed .discount__info-bar")) return;
this.fetchInfoBar().then(this.renderBottomBanner);
document.addEventListener("dj.cartChange", () => {
this.fetchInfoBar().then(this.renderBottomBanner);
});
};
}
SPZ.defineElement("spz-custom-rebate", SpzRebateComponent);