{% sw_extends '@Storefront/storefront/component/product/listing.html.twig' %}
{% block element_product_listing_row %}
{# Default to ONE column on mobile, 3 columns on desktop #}
{% set listingColumns = "col-12 col-md-4 col-lg-4" %}
<div class="listing-column-toggle-wrapper" data-listing-column-toggle>
{% block listing_column_toggle %}
<div class="listing-column-toggle d-sm-none">
<button type="button"
class="listing-column-toggle__btn listing-column-toggle__btn--one-col active"
data-columns="one"
id="listing-toggle-one"
title="{{ "listing.columnToggle.oneColumn"|trans|sw_sanitize }}">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="4" y="4" width="16" height="16" stroke="currentColor" stroke-width="2" fill="none"/>
</svg>
</button>
<button type="button"
class="listing-column-toggle__btn listing-column-toggle__btn--two-col"
data-columns="two"
id="listing-toggle-two"
title="{{ "listing.columnToggle.twoColumns"|trans|sw_sanitize }}">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="4" y="4" width="7" height="16" stroke="currentColor" stroke-width="2" fill="none"/>
<rect x="13" y="4" width="7" height="16" stroke="currentColor" stroke-width="2" fill="none"/>
</svg>
</button>
</div>
{% endblock %}
<div class="listing-products-wrapper listing-view--one-column" data-listing-view="one">
{{ parent() }}
</div>
</div>
<script>
(function() {
function isMobile() {
return window.innerWidth < 576;
}
function init() {
if (!isMobile()) return;
const btnOne = document.getElementById('listing-toggle-one');
const btnTwo = document.getElementById('listing-toggle-two');
const wrapper = document.querySelector('.listing-products-wrapper');
const cols = document.querySelectorAll('.cms-listing-col');
if (!btnOne || !btnTwo || !wrapper) return;
// Load saved preference
let savedView = 'one';
try {
savedView = localStorage.getItem('donCarne_listingColumnView') || 'one';
} catch (e) {}
// Apply saved view
applyView(savedView);
// Button click handlers
btnOne.addEventListener('click', function() {
applyView('one');
saveView('one');
});
btnTwo.addEventListener('click', function() {
applyView('two');
saveView('two');
});
}
function applyView(type) {
const wrapper = document.querySelector('.listing-products-wrapper');
const cols = document.querySelectorAll('.cms-listing-col');
const btnOne = document.getElementById('listing-toggle-one');
const btnTwo = document.getElementById('listing-toggle-two');
if (!wrapper) return;
// Update wrapper classes
wrapper.classList.remove('listing-view--one-column', 'listing-view--two-column');
wrapper.classList.add('listing-view--' + type + '-column');
wrapper.setAttribute('data-listing-view', type);
// Update HTML class
document.documentElement.classList.remove('mobile-one-column-view', 'mobile-two-column-view');
document.documentElement.classList.add('mobile-' + type + '-column-view');
// Update column classes
cols.forEach(function(col) {
col.classList.remove('col-6', 'col-12');
col.classList.add(type === 'one' ? 'col-12' : 'col-6');
});
// Update button states
btnOne.classList.toggle('active', type === 'one');
btnTwo.classList.toggle('active', type === 'two');
}
function saveView(type) {
try {
localStorage.setItem('donCarne_listingColumnView', type);
} catch (e) {}
}
// Initialize on DOM ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();
</script>
{% endblock %}
{% block element_product_listing_pagination_nav_actions %}
{% block element_product_listing_pagination_nav_top %}
{# pagination will only appear at bottom (if at all) #}
{% endblock %}
{# uncomment for now in case client wants it back at some point SD-5951 #}
{# <div class="col-sorting">
{% block element_product_listing_sorting %}
{{ parent() }}
{% endblock %}
</div> #}
<div class="cms-element-product-listing__total">
{{ searchResult.total }}
{% sw_include '@Storefront/solution360/utilities/pluralise-snippets.twig' with {
integer: searchResult.total,
plural: "listing.products"|trans|sw_sanitize,
singular: "listing.product"|trans|sw_sanitize
}%}
</div>
{% endblock %}