<script type="text/javascript">
const script = document.createElement('script');
script.src = 'https://x.empathy.co/x-bigbuy/app.js';
script.type = 'module';
document.head.append(script);
</script>
<script type="text/javascript" async>
script.onload = async function () {
typeUser = 'retail';
customerLogged = false;
didomiConsent = false;
catalogs = [];
{% if empathyData.customerId != null %}
customerLogged = true;
{% endif %}
{% if empathyData.isWholesalePrice == true %}
typeUser = 'wholesale';
{% endif %}
{% for catalog in empathyData.catalogs %}
catalogs.push('{{ catalog }}')
{% endfor %}
{% if empathyData.languageIsoCode != null %}
languageIsoCode = '{{empathyData.languageIsoCode}}';
{% endif %}
if (window.Didomi !== undefined && window.Didomi.getUserConsentStatusForVendor !== undefined) {
didomiConsent = window.Didomi.getUserConsentStatusForVendor('c:empathyco-6JEwD2i4');
}
const addToCart = async (productId, quantity = 1) => {
const data = new FormData();
data.append('id_product', productId);
data.append('ajax', 1);
data.append('updateQty', 1);
data.append('quantity', quantity);
data.append('id_product_attribute', 0);
const response = await fetch('/cart/addProductCart', {
method: 'POST',
body: data
});
const result = await response.json();
return result;
}
const config = {
instance: 'bigbuy',
documentDirection: 'ltr',
scope: 'desktop',
currency: 'EUR',
consent: didomiConsent,
catalogs: catalogs,
lang: languageIsoCode,
uiLang: languageIsoCode,
country: 'es',
store: languageIsoCode,
userType: typeUser,
cart: $('.toolbar-notify').text(),
callbacks: {
async UserClickedResultAddToCart(result) {
const fetchAddToCart = await addToCart(result.identifier.value);
if (fetchAddToCart?.error !== true) {
InterfaceX.setSnippetConfig({
cart: fetchAddToCart?.products_in_cart
});
cart.refreshExpressCart();
}
},
UserClickedAddToCartIcon() {
window.location.assign(
customerLogged ? '/cart/checkout' : `/${languageIsoCode}/login`
);
}
}
};
window.InterfaceX.init(config);
}
</script>