{% extends 'AtechNetCoreBundle/base.html.twig' %}{% block content %} <div class="main-content"> <div class="container"> <div class="mt-5 mb-4 d-flex align-items-center justify-content-between"> <h1 class="mb-0">{{ 'Comparison' |trans }}</h1> <a class="text-decoration-underline text-secondary small" href="javascript:history.back()">{{ 'Back to shopping' |trans }}</a> </div> <div class="table-responsive mb-5"> <table class="table table-bordered small"> <tbody> <tr> <th class="border-start-0"></th> {% for product in products %} {% if loop.first and loop.last %} <th class="text-center border-start-0 border-end-0" style="height: 0"> {% elseif loop.first %} <th class="text-center border-start-0" style="height: 0"> {% elseif loop.last %} <th class="text-center border-end-0" style="height: 0"> {% else %} <th class="text-center" style="height: 0"> {% endif %} <div class="d-flex flex-column align-items-center h-100"> <img decoding="async" src="{{ product.image }}" alt="{{ product.name }}" width="120"> <strong>{{ product.name }}</strong> <small class="text-muted fw-normal">{{ 'Product code' |trans }}: {{ product.code }}</small> <strong class="mb-3">{{ product.price |price(currency, precision) }}</strong> <a href="{{ product.href }}" class="btn btn-primary btn-sm mt-auto px-0 py-2 w-50"> <small class="lh-lg d-md-block d-none">{{ 'View' |trans }}</small> <span class="d-md-none"> <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> </span> </a> </div> </th> {% endfor %} </tr> {% for key, label in { brand: 'Brand', model: 'Model', code: 'Product code', available: 'Availability', quality: 'Quality grading' } %} <tr> <th class="border-start-0 text-start">{{ label |trans }}:</th> {% for product in products %} {% if loop.last %} <td class="text-start border-end-0"> {% else %} <td class="text-start"> {% endif %} {% if key == 'available' and product[key] is defined %} {% if product[key] > 10 %} <span class="in-stock text-success">{{ '10+ in stock' | trans }}</span> {% elseif product[key] >= 5 %} <span class="in-stock text-success">{{ '5-10 in stock' | trans }}</span> {% elseif product[key] > 1 %} <span class="in-stock text-success">{{ '2-4 in stock'|trans }}</span> {% elseif product[key] == 1 %} <span class="in-stock text-danger">{{ 'Only one left'|trans }}!</span> {% elseif product.orderWaitingDays is defined and product.orderWaitingDays > 0 %} <span class="in-stock text-grey">{{ 'On order within %d working days' |trans |format(product.orderWaitingDays) }}</span> {% else %} <span class="in-stock text-grey">{{ 'Out of stock'|trans }}</span> {% endif %} {% elseif product[key] is defined %} {{ product[key] }} {% endif %} </td> {% endfor %} </tr> {% endfor %} {% for attribute in attributes %} <tr class="compare" data-attribute-id="{{ attribute.id }}"> <th class="border-start-0 text-start">{{ attribute.title |trans }}:</th> {% for product in products %} {% if loop.last %} <td class="text-start border-end-0"> {% else %} <td class="text-start"> {% endif %} {% if product.specification[attribute.id] is defined %} {% if product.specification[attribute.id] |length > 1 %} {% for option in product.specification[attribute.id] %} <span class="d-block" data-option-id="{{ option.attributeOptionId }}">{{- ( option.multiplier > 0 ? option.multiplier ~ ' x ' : '' ) ~ option.title -}}</span> {% endfor %} {% else %} {% for option in product.specification[attribute.id] %} {{- option.title -}} {% endfor %} {% endif %} {% else %} - {% endif %} </td> {% endfor %} </tr> {% endfor %} {% for key, label in { weight: 'Weight', dimensions: 'Dimensions' } %} <tr class="compare"> <th class="border-start-0 text-start">{{ label |trans }}:</th> {% for product in products %} {% if loop.last %} <td class="text-start border-end-0"> {% else %} <td class="text-start"> {% endif %} {% if product[key] is defined %} {{ product[key] }} {% else %} - {% endif %} </td> {% endfor %} </tr> {% endfor %} </tbody> </table> </div> </div> </div>{% endblock %}{% block javascripts %} {{ parent() }} <script type="text/javascript"> let rows = document.querySelectorAll('table tr.compare'); if ( rows.length > 0 ) { rows.forEach(( row ) => { let columns = row.querySelectorAll('td'); let options = []; let similar = true; let value = null; for ( let i = 0; i < columns.length; i++ ) { if ( columns[i].querySelectorAll('span').length > 0 ) { options[i] = columns[i].querySelectorAll('span'); continue; } if ( value == null ) { value = columns[i].innerHTML; } if ( value != columns[i].innerHTML ) { similar = false; } } if ( similar == true ) { columns.forEach(( column ) => { if ( column.querySelectorAll('span').length == 0 ) { column.classList.add('text-muted'); } }); } else { columns.forEach(( column ) => { if ( column.querySelectorAll('span').length == 0 ) { column.classList.add('fw-bold'); } }); } if ( options.length > 0 ) { let checked = []; for ( let i = 0; i < options.length; i++ ) { let column = options[i]; for ( let j = 0; j < column.length; j++ ) { let option = column[j]; if ( option.dataset.optionId in checked ) { continue; } let similar = true; let hit = 0; let value = null; for ( let k = 0; k < options.length; k++ ) { for ( let l = 0; l < options[k].length; l++ ) { if ( option.dataset.optionId == options[k][l].dataset.optionId ) { if ( value == null ) { value = options[k][l].innerHTML; } if ( value != options[k][l].innerHTML ) { similar = false; } hit++; } } } if ( hit != options.length ) { similar = false; } if ( similar == true ) { for ( let k = 0; k < options.length; k++ ) { for ( let l = 0; l < options[k].length; l++ ) { if ( option.dataset.optionId == options[k][l].dataset.optionId ) { options[k][l].classList.add('text-muted'); } } } } else { for ( let k = 0; k < options.length; k++ ) { for ( let l = 0; l < options[k].length; l++ ) { if ( option.dataset.optionId == options[k][l].dataset.optionId ) { options[k][l].classList.add('fw-bold'); } } } } checked.push(option.dataset.optionId); } } } }); } </script>{% endblock %} {% block title %}{{ 'Product comparison' |trans }} | {{ parent() }}{% endblock %}{% block header %} {{ include(template_from_string(header)) }}{% endblock %}{% block footer %} {{ include(template_from_string(footer)) }}{% endblock %}