custom/plugins/theme/src/Resources/views/storefront/component/product/listing.html.twig line 1

Open in your IDE?
  1. {% sw_extends '@Storefront/storefront/component/product/listing.html.twig' %}
  2. {% block element_product_listing_row %}
  3.     {# Default to ONE column on mobile, 3 columns on desktop #}
  4.     {% set listingColumns = "col-12 col-md-4 col-lg-4" %}
  5.     <div class="listing-column-toggle-wrapper" data-listing-column-toggle>
  6.         {% block listing_column_toggle %}
  7.             <div class="listing-column-toggle d-sm-none">
  8.                 <button type="button"
  9.                         class="listing-column-toggle__btn listing-column-toggle__btn--one-col active"
  10.                         data-columns="one"
  11.                         id="listing-toggle-one"
  12.                         title="{{ "listing.columnToggle.oneColumn"|trans|sw_sanitize }}">
  13.                     <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
  14.                         <rect x="4" y="4" width="16" height="16" stroke="currentColor" stroke-width="2" fill="none"/>
  15.                     </svg>
  16.                 </button>
  17.                 <button type="button"
  18.                         class="listing-column-toggle__btn listing-column-toggle__btn--two-col"
  19.                         data-columns="two"
  20.                         id="listing-toggle-two"
  21.                         title="{{ "listing.columnToggle.twoColumns"|trans|sw_sanitize }}">
  22.                     <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
  23.                         <rect x="4" y="4" width="7" height="16" stroke="currentColor" stroke-width="2" fill="none"/>
  24.                         <rect x="13" y="4" width="7" height="16" stroke="currentColor" stroke-width="2" fill="none"/>
  25.                     </svg>
  26.                 </button>
  27.             </div>
  28.         {% endblock %}
  29.         <div class="listing-products-wrapper listing-view--one-column" data-listing-view="one">
  30.             {{ parent() }}
  31.         </div>
  32.     </div>
  33.     <script>
  34.     (function() {
  35.         function isMobile() {
  36.             return window.innerWidth < 576;
  37.         }
  38.         function init() {
  39.             if (!isMobile()) return;
  40.             const btnOne = document.getElementById('listing-toggle-one');
  41.             const btnTwo = document.getElementById('listing-toggle-two');
  42.             const wrapper = document.querySelector('.listing-products-wrapper');
  43.             const cols = document.querySelectorAll('.cms-listing-col');
  44.             if (!btnOne || !btnTwo || !wrapper) return;
  45.             // Load saved preference
  46.             let savedView = 'one';
  47.             try {
  48.                 savedView = localStorage.getItem('donCarne_listingColumnView') || 'one';
  49.             } catch (e) {}
  50.             // Apply saved view
  51.             applyView(savedView);
  52.             // Button click handlers
  53.             btnOne.addEventListener('click', function() {
  54.                 applyView('one');
  55.                 saveView('one');
  56.             });
  57.             btnTwo.addEventListener('click', function() {
  58.                 applyView('two');
  59.                 saveView('two');
  60.             });
  61.         }
  62.         function applyView(type) {
  63.             const wrapper = document.querySelector('.listing-products-wrapper');
  64.             const cols = document.querySelectorAll('.cms-listing-col');
  65.             const btnOne = document.getElementById('listing-toggle-one');
  66.             const btnTwo = document.getElementById('listing-toggle-two');
  67.             if (!wrapper) return;
  68.             // Update wrapper classes
  69.             wrapper.classList.remove('listing-view--one-column', 'listing-view--two-column');
  70.             wrapper.classList.add('listing-view--' + type + '-column');
  71.             wrapper.setAttribute('data-listing-view', type);
  72.             // Update HTML class
  73.             document.documentElement.classList.remove('mobile-one-column-view', 'mobile-two-column-view');
  74.             document.documentElement.classList.add('mobile-' + type + '-column-view');
  75.             // Update column classes
  76.             cols.forEach(function(col) {
  77.                 col.classList.remove('col-6', 'col-12');
  78.                 col.classList.add(type === 'one' ? 'col-12' : 'col-6');
  79.             });
  80.             // Update button states
  81.             btnOne.classList.toggle('active', type === 'one');
  82.             btnTwo.classList.toggle('active', type === 'two');
  83.         }
  84.         function saveView(type) {
  85.             try {
  86.                 localStorage.setItem('donCarne_listingColumnView', type);
  87.             } catch (e) {}
  88.         }
  89.         // Initialize on DOM ready
  90.         if (document.readyState === 'loading') {
  91.             document.addEventListener('DOMContentLoaded', init);
  92.         } else {
  93.             init();
  94.         }
  95.     })();
  96.     </script>
  97. {% endblock %}
  98. {% block element_product_listing_pagination_nav_actions %}
  99.     {% block element_product_listing_pagination_nav_top %}
  100.         {# pagination will only appear at bottom (if at all) #}
  101.     {% endblock %}
  102.     {# uncomment for now in case client wants it back at some point SD-5951 #}
  103.     {# <div class="col-sorting">
  104.         {% block element_product_listing_sorting %}
  105.             {{ parent() }}
  106.         {% endblock %}
  107.     </div> #}
  108.     <div class="cms-element-product-listing__total">
  109.         {{ searchResult.total }} 
  110.         {% sw_include '@Storefront/solution360/utilities/pluralise-snippets.twig' with {
  111.             integer: searchResult.total,
  112.             plural: "listing.products"|trans|sw_sanitize,
  113.             singular: "listing.product"|trans|sw_sanitize
  114.         }%}
  115.     </div>
  116.     
  117. {% endblock %}