templates/AtechNetCoreBundle/Product/compare.html.twig line 1

Open in your IDE?
  1. {% extends 'AtechNetCoreBundle/base.html.twig' %}
  2. {% block content %}
  3.     <div class="main-content">
  4.         <div class="container">
  5.             <div class="mt-5 mb-4 d-flex align-items-center justify-content-between">
  6.                 <h1 class="mb-0">{{ 'Comparison' |trans }}</h1>
  7.                 <a class="text-decoration-underline text-secondary small" href="javascript:history.back()">{{ 'Back to shopping' |trans }}</a>
  8.             </div>
  9.             <div class="table-responsive mb-5">
  10.                 <table class="table table-bordered small">
  11.                     <tbody>
  12.                         <tr>
  13.                             <th class="border-start-0"></th>
  14.                             {% for product in products %}
  15.                                 {% if loop.first and loop.last %}
  16.                                     <th class="text-center border-start-0 border-end-0" style="height: 0">
  17.                                 {% elseif loop.first %}
  18.                                     <th class="text-center border-start-0" style="height: 0">
  19.                                 {% elseif loop.last %}
  20.                                     <th class="text-center border-end-0" style="height: 0">
  21.                                 {% else %}
  22.                                     <th class="text-center" style="height: 0">
  23.                                 {% endif %}
  24.                                     <div class="d-flex flex-column align-items-center h-100">
  25.                                         <img decoding="async" src="{{ product.image }}" alt="{{ product.name }}" width="120">
  26.                                         <strong>{{ product.name }}</strong>
  27.                                         <small class="text-muted fw-normal">{{ 'Product code' |trans }}: {{ product.code }}</small>
  28.                                         <strong class="mb-3">{{ product.price |price(currency, precision) }}</strong>
  29.                                         <a href="{{ product.href }}" class="btn btn-primary btn-sm mt-auto px-0 py-2 w-50">
  30.                                             <small class="lh-lg d-md-block d-none">{{ 'View' |trans }}</small>
  31.                                             <span class="d-md-none">
  32.                                                 <svg xmlns="http://www.w3.org/2000/svg" height="16" width="18" viewBox="0 0 576 512" style="margin-top: -2px;" fill="#ffffff"><path d="M288 80c-65.2 0-118.8 29.6-159.9 67.7C89.6 183.5 63 226 49.4 256c13.6 30 40.2 72.5 78.6 108.3C169.2 402.4 222.8 432 288 432s118.8-29.6 159.9-67.7C486.4 328.5 513 286 526.6 256c-13.6-30-40.2-72.5-78.6-108.3C406.8 109.6 353.2 80 288 80zM95.4 112.6C142.5 68.8 207.2 32 288 32s145.5 36.8 192.6 80.6c46.8 43.5 78.1 95.4 93 131.1c3.3 7.9 3.3 16.7 0 24.6c-14.9 35.7-46.2 87.7-93 131.1C433.5 443.2 368.8 480 288 480s-145.5-36.8-192.6-80.6C48.6 356 17.3 304 2.5 268.3c-3.3-7.9-3.3-16.7 0-24.6C17.3 208 48.6 156 95.4 112.6zM288 336c44.2 0 80-35.8 80-80s-35.8-80-80-80c-.7 0-1.3 0-2 0c1.3 5.1 2 10.5 2 16c0 35.3-28.7 64-64 64c-5.5 0-10.9-.7-16-2c0 .7 0 1.3 0 2c0 44.2 35.8 80 80 80zm0-208a128 128 0 1 1 0 256 128 128 0 1 1 0-256z"/></svg>
  33.                                             </span>
  34.                                         </a>
  35.                                     </div>
  36.                                 </th>
  37.                             {% endfor %}
  38.                         </tr>
  39.                         {% for key, label in { brand: 'Brand', model: 'Model', code: 'Product code', available: 'Availability', quality: 'Quality grading' } %}
  40.                             <tr>
  41.                                 <th class="border-start-0 text-start">{{ label |trans }}:</th>
  42.                                 {% for product in products %}
  43.                                     {% if loop.last %}
  44.                                         <td class="text-start border-end-0">
  45.                                     {% else %}
  46.                                         <td class="text-start">
  47.                                     {% endif %}
  48.                                         {% if key == 'available' and product[key] is defined %}
  49.                                             {% if product[key] > 10 %}
  50.                                                 <span class="in-stock text-success">{{ '10+ in stock' | trans }}</span>
  51.                                             {% elseif product[key] >= 5 %}
  52.                                                 <span class="in-stock text-success">{{ '5-10 in stock' | trans }}</span>
  53.                                             {% elseif product[key] > 1 %}
  54.                                                 <span class="in-stock text-success">{{ '2-4 in stock'|trans }}</span>
  55.                                             {% elseif product[key] == 1 %}
  56.                                                 <span class="in-stock text-danger">{{ 'Only one left'|trans }}!</span>
  57.                                             {% elseif product.orderWaitingDays is defined and product.orderWaitingDays > 0 %}
  58.                                                 <span class="in-stock text-grey">{{ 'On order within %d working days' |trans |format(product.orderWaitingDays) }}</span>
  59.                                             {% else %}
  60.                                                 <span class="in-stock text-grey">{{ 'Out of stock'|trans }}</span>
  61.                                             {% endif %}
  62.                                         {% elseif product[key] is defined %}
  63.                                             {{ product[key] }}
  64.                                         {% endif %}
  65.                                     </td>
  66.                                 {% endfor %}
  67.                             </tr>
  68.                         {% endfor %}
  69.                         {% for attribute in attributes %}
  70.                             <tr class="compare" data-attribute-id="{{ attribute.id }}">
  71.                                 <th class="border-start-0 text-start">{{ attribute.title |trans }}:</th>
  72.                                 {% for product in products %}
  73.                                     {% if loop.last %}
  74.                                         <td class="text-start border-end-0">
  75.                                     {% else %}
  76.                                         <td class="text-start">
  77.                                     {% endif %}
  78.                                         {% if product.specification[attribute.id] is defined %}
  79.                                             {% if product.specification[attribute.id] |length > 1 %}
  80.                                                 {% for option in product.specification[attribute.id] %}
  81.                                                     <span class="d-block" data-option-id="{{ option.attributeOptionId }}">{{- ( option.multiplier > 0 ? option.multiplier ~ ' x ' : '' ) ~ option.title -}}</span>
  82.                                                 {% endfor %}
  83.                                             {% else %}
  84.                                                 {% for option in product.specification[attribute.id] %}
  85.                                                     {{- option.title -}}
  86.                                                 {% endfor %}
  87.                                             {% endif %}
  88.                                         {% else %}
  89.                                             -
  90.                                         {% endif %}
  91.                                     </td>
  92.                                 {% endfor %}
  93.                             </tr>
  94.                         {% endfor %}
  95.                         {% for key, label in { weight: 'Weight', dimensions: 'Dimensions' } %}
  96.                             <tr class="compare">
  97.                                 <th class="border-start-0 text-start">{{ label |trans }}:</th>
  98.                                 {% for product in products %}
  99.                                     {% if loop.last %}
  100.                                         <td class="text-start border-end-0">
  101.                                     {% else %}
  102.                                         <td class="text-start">
  103.                                     {% endif %}
  104.                                         {% if product[key] is defined %}
  105.                                             {{ product[key] }}
  106.                                         {% else %}
  107.                                             -
  108.                                         {% endif %}
  109.                                     </td>
  110.                                 {% endfor %}
  111.                             </tr>
  112.                         {% endfor %}
  113.                     </tbody>
  114.                 </table>
  115.             </div>
  116.         </div>
  117.     </div>
  118. {% endblock %}
  119. {% block javascripts %}
  120.     {{ parent() }}
  121.     <script type="text/javascript">
  122.         let rows = document.querySelectorAll('table tr.compare');
  123.         if ( rows.length > 0 ) {
  124.             rows.forEach(( row ) => {
  125.                 let columns = row.querySelectorAll('td');
  126.                 let options = [];
  127.                 let similar = true;
  128.                 let value = null;
  129.                 for ( let i = 0; i < columns.length; i++ ) {
  130.                     if ( columns[i].querySelectorAll('span').length > 0 ) {
  131.                         options[i] = columns[i].querySelectorAll('span');
  132.                         continue;
  133.                     }
  134.                     if ( value == null ) {
  135.                         value = columns[i].innerHTML;
  136.                     }
  137.                     if ( value != columns[i].innerHTML ) {
  138.                         similar = false;
  139.                     }
  140.                 }
  141.                 if ( similar == true ) {
  142.                     columns.forEach(( column ) => {
  143.                         if ( column.querySelectorAll('span').length == 0 ) {
  144.                             column.classList.add('text-muted');
  145.                         }
  146.                     });
  147.                 } else {
  148.                     columns.forEach(( column ) => {
  149.                         if ( column.querySelectorAll('span').length == 0 ) {
  150.                             column.classList.add('fw-bold');
  151.                         }
  152.                     });
  153.                 }
  154.                 if ( options.length > 0 ) {
  155.                     let checked = [];
  156.                     for ( let i = 0; i < options.length; i++ ) {
  157.                         let column = options[i];
  158.                         for ( let j = 0; j < column.length; j++ ) {
  159.                             let option = column[j];
  160.                             if ( option.dataset.optionId in checked ) {
  161.                                 continue;
  162.                             }
  163.                             let similar = true;
  164.                             let hit = 0;
  165.                             let value = null;
  166.                             for ( let k = 0; k < options.length; k++ ) {
  167.                                 for ( let l = 0; l < options[k].length; l++ ) {
  168.                                     if ( option.dataset.optionId == options[k][l].dataset.optionId ) {
  169.                                         if ( value == null ) {
  170.                                             value = options[k][l].innerHTML;
  171.                                         }
  172.                                         if ( value != options[k][l].innerHTML ) {
  173.                                             similar = false;
  174.                                         }
  175.                                         hit++;
  176.                                     }
  177.                                 }
  178.                             }
  179.                             if ( hit != options.length ) {
  180.                                 similar = false;
  181.                             }
  182.                             if ( similar == true ) {
  183.                                 for ( let k = 0; k < options.length; k++ ) {
  184.                                     for ( let l = 0; l < options[k].length; l++ ) {
  185.                                         if ( option.dataset.optionId == options[k][l].dataset.optionId ) {
  186.                                             options[k][l].classList.add('text-muted');
  187.                                         }
  188.                                     }
  189.                                 }
  190.                             } else {
  191.                                 for ( let k = 0; k < options.length; k++ ) {
  192.                                     for ( let l = 0; l < options[k].length; l++ ) {
  193.                                         if ( option.dataset.optionId == options[k][l].dataset.optionId ) {
  194.                                             options[k][l].classList.add('fw-bold');
  195.                                         }
  196.                                     }
  197.                                 }
  198.                             }
  199.                             checked.push(option.dataset.optionId);
  200.                         }
  201.                     }
  202.                 }
  203.             });
  204.         }
  205.     </script>
  206. {% endblock %}    
  207. {% block title %}{{ 'Product comparison' |trans }} | {{ parent() }}{% endblock %}
  208. {% block header %}
  209.     {{ include(template_from_string(header)) }}
  210. {% endblock %}
  211. {% block footer %}
  212.     {{ include(template_from_string(footer)) }}
  213. {% endblock %}