var __fast_options = { with_product_attributes: true};
const VNEXT_FOR90_TAG_NAME = "2FOR90";
function getProductElements(element) {
return [...element.querySelectorAll(`.fs-results-product-card`)];
}
const NewBadges = {
set: (product, productElement) => {
var $badgewapper = `<div class="fs-badges-wrapper"></div>`;
if (productElement.querySelectorAll(`.fs-badges-wrapper`).length === 0) {
productElement.querySelector(".image-wrapper").insertAdjacentHTML('afterBegin', $badgewapper);
}
const tags = product.tags;
if(NewBadges.is2FOR90(tags)) {
NewBadges.addLabel(productElement,`<span class="fs_product_text_badge_flag seller2">2 For $90</span>`);
}
},
addLabel: (productElement, promolabel ) => {
const label = productElement.querySelector(`.fs_product_text_badge_flag`);
if (label) {
label.remove();
}
productElement.querySelector(".fs-badges-wrapper").insertAdjacentHTML('afterBegin', promolabel);
},
isSoldOut: (product) => {
return ("isSoldOut" in product && product.isSoldOut)
},
is2FOR90: (tags) => {
return tags.includes(VNEXT_FOR90_TAG_NAME);
},
isOnSale: (product) => {
const originalPrice = parseFloat(product.price);
const price = parseFloat(product.comparePrice);
return price && originalPrice && originalPrice > 0 && price > 0 && price > originalPrice;
}
};
function hooks()
{
SerpOptions.registerHook('serp-product-grid', ({products, element}) => {
for (const productElement of getProductElements(element)) {
const productID = productElement.dataset.productId;
const data = products[productID];
NewBadges.set(data, productElement);
}
});
}
if (window.SerpOptions) {
hooks();
} else {
window.addEventListener('fast-serp-ready', function () {
hooks();
});
}