custom/plugins/clerkio64/src/Resources/views/storefront/layout/meta.html.twig line 1

Open in your IDE?
  1. {% sw_extends '@Storefront/storefront/layout/meta.html.twig' %}
  2. {% block layout_head_javascript_tracking %}
  3.     {{ parent() }}
  4.     {% set clerk_api_key = config('clerkio64.config.publicKey') %}
  5.     {% set clerk_language_id = page.header.activeLanguage.id %}
  6.     {% set clerk_js_custom_url = context.salesChannel.translated.name|lower|slug %}
  7.     {% set clerk_custom_api_keys = config('clerkio64.config.customKeyConfig') %}
  8.     {% set clerk_selected_languages = config('clerkio64.config.selectedLanguages') %}
  9.     {% if clerk_custom_api_keys|length and clerk_selected_languages|length %}
  10.         {% set clerk_custom_api_keys = clerk_custom_api_keys | split('\n') %}
  11.         {% if clerk_custom_api_keys|length == clerk_selected_languages|length %}
  12.             {% for lang in clerk_selected_languages %}
  13.                 {% if clerk_language_id == lang %}
  14.                     {% set clerk_api_key = clerk_custom_api_keys[loop.index0] %}
  15.                 {% endif %}
  16.             {% endfor %}
  17.         {% endif %}
  18.     {% endif %}
  19.     {% if config('clerkio64.config.enabled') == 'true' and clerk_api_key %}
  20.         {% if not app.getSession().getLocale() is null %}
  21.             {% set clerk_locale = app.getSession().getLocale() %}
  22.         {% else %}
  23.             {% set clerk_locale = app.getRequest().getLocale() %}
  24.         {% endif %}
  25.         {% set clerk_tax_state = context.taxState %}
  26.         {% set clerk_tax_rate = 0 %}
  27.         {% set clerk_sales_channel_tax_rates = context.taxRules.elements %}
  28.         {% if clerk_sales_channel_tax_rates is iterable %}
  29.             {% for tax_rate in clerk_sales_channel_tax_rates %}
  30.                 {% if tax_rate.position == 1 %}
  31.                     {% set clerk_tax_rate = tax_rate.taxRate %}
  32.                 {% endif %}
  33.             {% endfor %}
  34.         {% endif %}
  35.         {% if context.shippingLocation.country.customerTax.enabled %}
  36.             {% set clerk_customer_tax_rate = context.shippingLocation.country.customerTax.amount %}
  37.         {% else %}
  38.             {% set clerk_customer_tax_rate = clerk_tax_rate %}
  39.         {% endif %}
  40.         <!-- Start of Clerk.io E-commerce Personalisation tool - www.clerk.io -->
  41.         <script type="text/javascript">
  42.             function getCookie(name) {
  43.                 const value = `; ${document.cookie}`;
  44.                 const parts = value.split(`; ${name}=`);
  45.                 if (parts.length === 2) return parts.pop().split(';').shift();
  46.             }
  47.             (function (w, d) {
  48.                 var e = d.createElement('script');
  49.                 e.type = 'text/javascript';
  50.                 e.async = true;
  51.                 e.src = (d.location.protocol == 'https:' ? 'https' : 'http') + '://custom.clerk.io/{{ clerk_js_custom_url }}.js';
  52.                 var s = d.getElementsByTagName('script')[0];
  53.                 s.parentNode.insertBefore(e, s);
  54.                 w.__clerk_q = w.__clerk_q || [];
  55.                 w.Clerk = w.Clerk || function () {
  56.                     w.__clerk_q.push(arguments)
  57.                 };
  58.             })(window, document);
  59.             Clerk('config', {
  60.                 key: "{{ clerk_api_key }}",
  61.                 globals: {
  62.                     locale: "{{ clerk_locale }}",
  63.                     language_id: "{{ clerk_language_id }}",
  64.                     tax_state: "{{ clerk_tax_state }}",
  65.                     tax_rate: {{ clerk_tax_rate }},
  66.                     customer_tax_rate: {{ clerk_customer_tax_rate }},
  67.                     customer_group: (getCookie('customer_group_name')) ? getCookie('customer_group_name') : 'Shopkunden'
  68.                 },
  69.                 formatters: {
  70.                     add_tax: function (price) {
  71.                         const tax_rate = {{ clerk_tax_rate }};
  72.                         if (tax_rate > 0) {
  73.                             return price * (1 + (tax_rate / 100));
  74.                         } else {
  75.                             return price;
  76.                         }
  77.                     },
  78.                     remove_tax: function (price) {
  79.                         const tax_rate = {{ clerk_tax_rate }};
  80.                         if (tax_rate > 0) {
  81.                             return price / (1 + (tax_rate / 100));
  82.                         } else {
  83.                             return price;
  84.                         }
  85.                     }
  86.                 }
  87.             });
  88.             {% if context.customer and config('clerkio64.config.collectEmails') == 'true' %}
  89.             {% if context.customer.email %}
  90.             if (typeof window.Clerk == 'function') {
  91.                 Clerk('call', 'log/email', {
  92.                     email: "{{ context.customer.email }}"
  93.                 });
  94.             }
  95.             {% endif %}
  96.             {% endif %}
  97.             function initShortCodes() {
  98.                 const nodes = getElementsByText('[[clerk@');
  99.                 for (let i = 0; i < nodes.length; i++) {
  100.                     const node = nodes[i];
  101.                     const paramsRaw = node.innerText;
  102.                     if (!validateShortCode(paramsRaw)) {
  103.                         continue;
  104.                     }
  105.                     const el = document.createElement('span');
  106.                     el.className = "clerk_shortcode";
  107.                     let template = paramsRaw.split("clerk@")[1].replace("]]", "");
  108.                     if (!template.startsWith("@")) {
  109.                         template = `@${template}`;
  110.                     }
  111.                     el.dataset.template = template;
  112.                     node.innerText = "";
  113.                     node.append(el);
  114.                 }
  115.                 if (typeof window.Clerk == 'function') {
  116.                     Clerk('content', '.clerk_shortcode');
  117.                 }
  118.             }
  119.             function getElementsByText(str, tag = 'p') {
  120.                 return Array.prototype.slice.call(document.querySelectorAll(tag)).filter(el => el.textContent.trim().startsWith(str));
  121.             }
  122.             function validateShortCode(str) {
  123.                 if (!str.startsWith('[[') || !str.endsWith(']]') || !str.includes('clerk@')) {
  124.                     return false;
  125.                 }
  126.                 return true;
  127.             }
  128.             document.addEventListener("DOMContentLoaded", (e) => {
  129.                 initShortCodes();
  130.             });
  131.         </script>
  132.         <!-- End of Clerk.io E-commerce Personalisation tool - www.clerk.io -->
  133.     {% endif %}
  134.     {% if config('clerkio64.config.PowerstepRecommendationsEnabled') == 'true' %}
  135.         {% if config('clerkio64.config.PowerstepRecommendationsType') == 'popup' %}
  136.             <script src="{{ asset('bundles/clerkio64/js/powerstep-popup.js') }}"></script>
  137.         {% else %}
  138.             <script src="{{ asset('bundles/clerkio64/js/powerstep-page.js') }}"></script>
  139.         {% endif %}
  140.     {% endif %}
  141.     {% if config('clerkio64.config.instantSearchEnabled') == 'true' and config('clerkio64.config.instantSearchInjectionPosition') == 'meta' %}
  142.         <span
  143.                 class="clerk clerk-move-to-body"
  144.                 data-template="@{{ config('clerkio64.config.instantSearchContent') }}"
  145.                 data-instant-search-suggestions="{{ config('clerkio64.config.instantSearchNumberOfSuggestions') }}"
  146.                 data-instant-search-categories="{{ config('clerkio64.config.instantSearchNumberOfCategories') }}"
  147.                 data-instant-search-pages="{{ config('clerkio64.config.instantSearchNumberOfPages') }}"
  148.                 data-instant-search-positioning="{{ config('clerkio64.config.instantSearchDropdownPositioning') ? config('clerkio64.config.instantSearchDropdownPositioning') : 'left' }}"
  149.                 data-instant-search="{{ config('clerkio64.config.instantSearchInputSelector') ? config('clerkio64.config.instantSearchInputSelector') : '.header-search-input' }}"
  150.                 data-instant-search-pages-type="{{ config('clerkio64.config.instantSearchPageTypes') ? config('clerkio64.config.instantSearchPageTypes') : 'all' }}">
  151.         </span>
  152.     <script>
  153.       ((w, d) => {
  154.         const move = d.querySelectorAll(".clerk-move-to-body");
  155.         if(move){
  156.           move.forEach(el => {
  157.             document.body.appendChild(el);
  158.           })
  159.           if(typeof w.Clerk == 'function'){
  160.             w.Clerk("content", ".clerk-move-to-body");
  161.           }
  162.         }
  163.       })(window, document);
  164.     </script>
  165.     {% endif %}
  166. {% endblock %}