templates/order/index.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% block title %}Objednávka zprávy{% endblock %}
  3. {% block body %}
  4.     <section class="page-section" id="login">
  5.         <div class="container px-4 px-lg-5">
  6.             <div class="row gx-4 gx-lg-5 justify-content-center">
  7.                 <div class="col-lg-8 col-xl-6 text-center">
  8.                     <h2 class="mt-0">Objednávka Vaší zprávy</h2>
  9.                 </div>
  10.             </div>
  11.             <div class="row gx-4 gx-lg-5 justify-content-center mb-5">
  12.                 <div class="col-lg-6">
  13.                     {{ form_start(form) }}
  14.                     {{ form_errors(form) }}
  15.                         <h3 class="mt-0">Fakturační adresa</h3>
  16.                     {{ form_row(form.deliveryAddressCheckbox, { 'attr': { 'class': 'toggleDeliveryDetailsCheckbox', 'checked': 'checked' }}) }}
  17.                     {% if loggedUser %}
  18.                             {{ form_row(form.billingFirstname, { 'value': loggedUser.firstname}) }}
  19.                             {{ form_row(form.billingLastname, { 'value': loggedUser.lastname}) }}
  20.                             {{ form_row(form.billingCountry, { 'value': loggedUser.country}) }}
  21.                             {{ form_row(form.billingCity, { 'value': loggedUser.city}) }}
  22.                             {{ form_row(form.billingZipcode, { 'value': loggedUser.zipcode}) }}
  23.                             {{ form_row(form.billingStreet, { 'value': loggedUser.street}) }}
  24.                             {{ form_row(form.billingStreet2, { 'value': loggedUser.street2}) }}
  25.                             {{ form_row(form.billingEmail, { 'value': loggedUser.email}) }}
  26.                             {{ form_row(form.billingPhone, { 'value': loggedUser.phone}) }}
  27.                             <div class="deliveryDetails" style="display: none">
  28.                                 <hr class="solid" />
  29.                                 <h3 class="mt-0">Doručovací adresa</h3>
  30.                                 {{ form_row(form.deliveryFirstname) }}
  31.                                 {{ form_row(form.deliveryLastname) }}
  32.                                 {{ form_row(form.deliveryCountry) }}
  33.                                 {{ form_row(form.deliveryCity) }}
  34.                                 {{ form_row(form.deliveryZipcode) }}
  35.                                 {{ form_row(form.deliveryStreet) }}
  36.                                 {{ form_row(form.deliveryStreet2) }}
  37.                                 {{ form_row(form.deliveryEmail) }}
  38.                                 {{ form_row(form.deliveryPhone) }}
  39.                             </div>
  40.                         {% else %}
  41.                             {{ form_row(form.billingFirstname) }}
  42.                             {{ form_row(form.billingLastname) }}
  43.                             {{ form_row(form.billingCountry) }}
  44.                             {{ form_row(form.billingCity) }}
  45.                             {{ form_row(form.billingZipcode) }}
  46.                             {{ form_row(form.billingStreet) }}
  47.                             {{ form_row(form.billingStreet2) }}
  48.                             {{ form_row(form.billingEmail) }}
  49.                             {{ form_row(form.billingPhone) }}
  50.                         <div class="deliveryDetails" style="display: none">
  51.                             <hr class="solid" />
  52.                             <h3 class="mt-0">Doručovací adresa</h3>
  53.                             {{ form_row(form.deliveryFirstname) }}
  54.                             {{ form_row(form.deliveryLastname) }}
  55.                             {{ form_row(form.deliveryCountry) }}
  56.                             {{ form_row(form.deliveryCity) }}
  57.                             {{ form_row(form.deliveryZipcode) }}
  58.                             {{ form_row(form.deliveryStreet) }}
  59.                             {{ form_row(form.deliveryStreet2) }}
  60.                             {{ form_row(form.deliveryEmail) }}
  61.                             {{ form_row(form.deliveryPhone) }}
  62.                         </div>
  63.                         {% endif %}
  64.                         <hr class="solid" />
  65.                         <p>Text zprávy</p>
  66.                         {{ form_row(form.text) }}
  67.                         <hr class="solid" />
  68.                         {{ form_row(form.template) }}
  69.                         <div>
  70.                             <img width="70%" height="500" name="plugin" id="order_form_template_img" class="border border-1 mx-auto d-block">
  71.                         </div>
  72.                         <hr class="solid" />
  73.                         {{ form_row(form.deliveryDate) }}
  74.                         {{ form_row(form.code) }}
  75.                         <p id="coupon-code-text" hidden>Tady sem vložit slevu</p>
  76.                         {{ form_row(form.price, { 'value': messagePrice, 'attr': { 'class': 'disable'}} ) }}
  77.                     {{ form_widget(form) }}
  78.                     {{ form_end(form) }}
  79.                     <img id="barion_logo" class="mx-auto d-block" src="{{ asset('images/barion-smart-payment-banners-cz/barion-card-strip-cz__small.png') }}">
  80.                 </div>
  81.             </div>
  82.         </div>
  83.     </section>
  84. {% endblock %}
  85. {% block javascripts %}
  86.     <script>
  87.         $(document).ready(function () {
  88.             const template = document.getElementById('order_form_template');
  89.             document.getElementById('order_form_template_img').src = '/upload/templates/' + template.value;
  90.             const date = new Date();
  91.             $('.js-datepicker input').datepicker({
  92.                 format: "dd.mm.yyyy",
  93.                 language: "cs",
  94.                 daysOfWeekDisabled: "0,6",
  95.                 daysOfWeekHighlighted: "1,2,3,4,5",
  96.                 startDate: new Date(date.getFullYear(), date.getMonth(), date.getDay() + 14),
  97.                 todayHighlight: true
  98.             });
  99.             $('.toggleDeliveryDetailsCheckbox').change(function() {
  100.                 document.querySelector('.deliveryDetails').style.display = $(".toggleDeliveryDetailsCheckbox").is(':checked') ? 'none' : '';
  101.             });
  102.             $('#order_form_code').on('input', processChange);
  103.         });
  104.         function debounce(func, timeout = 500) {
  105.             let timer;
  106.             return (...args) => {
  107.                 clearTimeout(timer);
  108.                 timer = setTimeout(() => { func.apply(this, args); }, timeout);
  109.             };
  110.         }
  111.         function saveInput() {
  112.             const codeInput = document.getElementById('order_form_code').value;
  113.             if(codeInput) {
  114.                 $.ajax('{{ path('app_get_couponCode') }}', {
  115.                     data: {
  116.                         code: codeInput,
  117.                     },
  118.                     success: function(data) {
  119.                         if (data) {
  120.                             const codeData = JSON.parse(data);
  121.                             document.getElementById('coupon-code-text').hidden = false;
  122.                             document.getElementById('coupon-code-text').style = 'color: green;';
  123.                             const currentDate = new Date().getTime() / 1000;
  124.                             // if current date is between codeData.activeFrom and codeData.endsAt
  125.                             if (currentDate >= codeData.activeFrom.timestamp && currentDate <= codeData.endsAt.timestamp) {
  126.                                 document.getElementById('coupon-code-text').textContent = `Kupón ${codeData.code} se slevou ${codeData.value}${codeData.percentage ? '%' : ' Kč'}.`;
  127.                                 const currentPrice = document.getElementById('order_form_price').value;
  128.                                 if (codeData.percentage) {
  129.                                     document.getElementById('order_form_price').value = currentPrice - ((currentPrice / 100) * codeData.value);
  130.                                 } else {
  131.                                     document.getElementById('order_form_price').value = currentPrice - codeData.value;
  132.                                 }
  133.                             } else {
  134.                                 document.getElementById('coupon-code-text').textContent = `Kupón ${codeData.code} již není platný.`;
  135.                                 document.getElementById('coupon-code-text').style = 'color: red;';
  136.                             }
  137.                         } else {
  138.                             document.getElementById('coupon-code-text').textContent = `Kupón ${codeData.code} nebyl nalezen.`;
  139.                             document.getElementById('coupon-code-text').style = 'color: red;';
  140.                         }
  141.                     },
  142.                     error: function() {
  143.                         document.getElementById('coupon-code-text').hidden = false;
  144.                         document.getElementById('coupon-code-text').textContent = 'Kupón nebyl nalezen.';
  145.                         document.getElementById('coupon-code-text').style = 'color: red;';
  146.                     }
  147.                 });
  148.             } else {
  149.                 document.getElementById('coupon-code-text').hidden = true;
  150.             }
  151.         }
  152.         const processChange = debounce(() => saveInput());
  153.         window.addEventListener("DOMContentLoaded", (event) => {
  154.             document.getElementById('order_form_template').addEventListener('change', function() {
  155.                 document.getElementById('order_form_template_img').src = '/upload/templates/' + this.value;
  156.             });
  157.         });
  158.     </script>
  159. {% endblock %}