Skip to content
All Discs except Consignment items
3216 products
';
function toggleWidget() {
loadAppstleLoyaltyWidget();
if (_ALConfig?.widget_setting?.widgetType?.toUpperCase() === 'LAUNCHER' && _ALConfig?.widget_setting?.forceRedirectDedicatedPage === true) {
window.open(`/${_ALConfig?.proxy_path_prefix}`);
} else {
document.querySelector('#appstle_loyalty_iframe')?.classList?.toggle('open');
showAppstleLoyaltyWidget();
setTimeout(function() {
document.querySelector('#appstle_loyalty_iframe')?.classList?.toggle('show-close-icon');
}, 900);
}
}
const loadAppstleLoyaltyWidget = () => {
var iframe = document.querySelectorAll('#appstle_loyalty_iframe');
iframe.forEach(function(item) {
item.contentWindow._ALConfig = _ALConfig;
item.contentWindow.document.open('text/html', 'replace');
item.contentWindow.document.write(alIframeSrc);
item.contentWindow.document.close();
});
};
if (_ALConfig?.customerLoyalty && _ALConfig?.customerLoyalty?.availablePoints) {
document.querySelector('#appstle-loyalty-button')?.classList?.add('appstle_show_points');
document.querySelector('.loyalty_widget_available_points').innerHTML = _ALConfig?.customerLoyalty?.availablePoints?.toLocaleString();
}
if (_ALConfig.widget_setting.showTierName && _ALConfig?.customerLoyalty && _ALConfig?.customerLoyalty?.currentVipTier) {
document.querySelector('.loyalty_widget_available_points').innerHTML = _ALConfig?.customerLoyalty?.currentVipTier?.toLocaleString();
}
if (_ALConfig.widget_setting.showWidget && location?.hash?.indexOf('#appstle-loyalty') !== -1) {
handleDeepLink();
}
if (window?.location?.hash?.indexOf('#appstle-refer') !== -1) {
handleDeepLink();
}
function handleDeepLink() {
loadAppstleLoyaltyWidget();
document.querySelector('#appstle_loyalty_iframe')?.classList?.toggle('open');
showAppstleLoyaltyWidget();
setTimeout(function() {
document.querySelector('#appstle_loyalty_iframe')?.classList?.toggle('show-close-icon');
}, 900);
}
const widgetReferralUrl = new URL(window.location.href);
if (widgetReferralUrl?.searchParams.get('appstle_referral') && _ALConfig?.widget_setting?.widgetType === 'LAUNCHER') {
let redirectURL = _ALConfig?.widget_setting?.referralRedirectUrl + window.location.search;
if (redirectURL && !window.location.pathname.includes(_ALConfig.widget_setting.referralRedirectUrl)) {
window.open(redirectURL, '_self');
}
setTimeout(() => {
loadAppstleLoyaltyWidget();
enableWidget();
}, 200);
}
const alDOMObserver = new MutationObserver(function(mutations_list) {
mutations_list.forEach(function(mutation) {
mutation.addedNodes.forEach(function(added_node) {
if (added_node.id == 'appstle_loyalty_iframe') {
var iframe = document.querySelectorAll('#appstle_loyalty_iframe');
iframe.forEach(function(item) {
item.contentWindow._ALConfig = _ALConfig;
item.contentWindow.document.open('text/html', 'replace');
item.contentWindow.document.write(alIframeSrc);
item.contentWindow.document.close();
});
alDOMObserver.disconnect();
}
});
});
});
alDOMObserver.observe(document.querySelector('body'), { subtree: true, childList: true });
const dedicatedPageURL = new URL(window.location.href);
if (dedicatedPageURL?.searchParams?.get('appstle_referral') && _ALConfig?.widget_setting?.widgetType === 'DEDICATED_PAGE' && !window.location.href.includes(_ALConfig?.proxy_path_prefix)) {
window.open(`/${_ALConfig?.proxy_path_prefix}${window.location.search}`, '_self');
}
const dedicatedPageEventListener = (event) => {
if (event?.data && typeof event?.data.indexOf === 'function' && event?.data?.indexOf('refresh_appstle_loyalty_page') !== -1) {
initiateAppstleLoyaltyPage()
console.log("REFRESH PAGE");
}
}
window.addEventListener('message', dedicatedPageEventListener, false);
function initiateAppstleLoyaltyPage() {
if (document.querySelector('#appstleLoyaltyPage')) {
const appstleLoyaltyPageElement = document.getElementById('appstleLoyaltyPage');
while (appstleLoyaltyPageElement.firstChild) {
appstleLoyaltyPageElement.firstChild.remove();
}
var s = document.createElement('script');
s.setAttribute('src', "https://loyalty-admin.appstle.com/app/loyalty-widget.bundle.js?v=1713817872014");
s.setAttribute('defer', 'defer');
document.body.appendChild(s);
var head = document.head;
var link = document.createElement('link');
link.type = 'text/css';
link.rel = 'stylesheet';
link.href = "https://loyalty-admin.appstle.com/content/loyalty-widget.css?v=1713817872014";
head.appendChild(link);
} else {
setTimeout(() => {
initiateAppstleLoyaltyPage();
}, 2000);
}
}
const dedicatedPageReferralUrl = new URL(window.location.href)?.searchParams.get('appstle_referral');
const checkDedicatedPageForRestrictions = () => {
const { widget_setting, customerTags, customerLoyalty, customerId } = _ALConfig || {};
const { allowedCustomersTag, restrictedCustomersTag } = widget_setting || {};
const { customerStatus } = customerLoyalty || {};
if (customerStatus === 'EXCLUDED') {
return false;
}
if (!dedicatedPageReferralUrl && !customerId) {
return !(allowedCustomersTag || restrictedCustomersTag);
}
if (allowedCustomersTag?.length) {
const allowedTags = allowedCustomersTag.split(',');
if (!allowedTags.some(tag => customerTags?.includes(tag))) {
return false;
}
}
if (restrictedCustomersTag?.length) {
const restrictedTags = restrictedCustomersTag.split(',');
if (restrictedTags.some(tag => customerTags?.includes(tag))) {
return false;
}
}
return true;
};
if (_ALConfig?.widget_setting?.showWidget === true && checkDedicatedPageForRestrictions()) {
initiateAppstleLoyaltyPage();
}
(async function() {
const isAvailableVisitShop = _ALConfig?.pointEarnRules?.length > 0 && _ALConfig?.pointEarnRules?.find((rule) => rule?.type === 'VISIT_SHOP' && rule?.status === 'ACTIVE');
if (!sessionStorage.getItem('syncVisitStore') && ((_ALConfig?.customerId && isAvailableVisitShop && isAvailableVisitShop?.id) || (_ALConfig?.referralEnabled && _ALConfig?.referralLoyalty?.referralType === 'VISIT_SHOP'))) {
try {
const response = await fetch(`/${_ALConfig?.proxy_path_prefix || 'apps/loyalty'}/cp/api/customer-visit-store`, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ customerId: _ALConfig?.customerId })
});
if (response?.ok) {
sessionStorage.setItem('syncVisitStore', 'true');
}
} catch (error) {
console.error('Error:', error);
}
}
})();
const loyaltyCustomStyles = ``;
document.querySelector('body').insertAdjacentHTML('beforeend', loyaltyCustomStyles);