templates/front/base/empathy_scripts.html.twig line 1

Open in your IDE?
  1. <script type="text/javascript">
  2. const script = document.createElement('script');
  3. script.src = 'https://x.empathy.co/x-bigbuy/app.js';
  4. script.type = 'module';
  5. document.head.append(script);
  6. </script>
  7. <script type="text/javascript" async>
  8. script.onload = async function () {
  9. typeUser = 'retail';
  10. customerLogged = false;
  11. didomiConsent = false;
  12. catalogs = [];
  13. {% if empathyData.customerId != null %}
  14. customerLogged = true;
  15. {% endif %}
  16. {% if empathyData.isWholesalePrice == true %}
  17. typeUser = 'wholesale';
  18. {% endif %}
  19. {% for catalog in empathyData.catalogs %}
  20. catalogs.push('{{ catalog }}')
  21. {% endfor %}
  22. {% if empathyData.languageIsoCode != null %}
  23. languageIsoCode = '{{empathyData.languageIsoCode}}';
  24. {% endif %}
  25. if (window.Didomi !== undefined && window.Didomi.getUserConsentStatusForVendor !== undefined) {
  26. didomiConsent = window.Didomi.getUserConsentStatusForVendor('c:empathyco-6JEwD2i4');
  27. }
  28. const addToCart = async (productId, quantity = 1) => {
  29. const data = new FormData();
  30. data.append('id_product', productId);
  31. data.append('ajax', 1);
  32. data.append('updateQty', 1);
  33. data.append('quantity', quantity);
  34. data.append('id_product_attribute', 0);
  35. const response = await fetch('/cart/addProductCart', {
  36. method: 'POST',
  37. body: data
  38. });
  39. const result = await response.json();
  40. return result;
  41. }
  42. const config = {
  43. instance: 'bigbuy',
  44. documentDirection: 'ltr',
  45. scope: 'desktop',
  46. currency: 'EUR',
  47. consent: didomiConsent,
  48. catalogs: catalogs,
  49. lang: languageIsoCode,
  50. uiLang: languageIsoCode,
  51. country: 'es',
  52. store: languageIsoCode,
  53. userType: typeUser,
  54. cart: $('.toolbar-notify').text(),
  55. callbacks: {
  56. async UserClickedResultAddToCart(result) {
  57. const fetchAddToCart = await addToCart(result.identifier.value);
  58. if (fetchAddToCart?.error !== true) {
  59. InterfaceX.setSnippetConfig({
  60. cart: fetchAddToCart?.products_in_cart
  61. });
  62. }
  63. },
  64. UserClickedAddToCartIcon() {
  65. window.location.assign(
  66. customerLogged ? '/cart/checkout' : `/${languageIsoCode}/login`
  67. );
  68. }
  69. }
  70. };
  71. window.InterfaceX.init(config);
  72. }
  73. </script>