refactor: add filters on the products list

pagebuilder
Dinesh Salunke 2023-11-03 19:57:40 +05:30
parent 681dff1dbd
commit 6cafbe1ca5
3 changed files with 66 additions and 27 deletions

View File

@ -23,23 +23,71 @@
* International Registered Trademark & Property of PrestaShop SA
*}
{if $facets|count}
<div id="search_filters">
{block name='facets_title'}
<p class="text-uppercase h6 hidden-sm-down">{l s='Filter By' d='Shop.Theme.Actions'}</p>
{/block}
<div id="search_filters" class="flex gap-4 flex-1 flex-col lg:flex-row lg:items-center">
{block name='facets_clearall_button'}
{if $activeFilters|count}
<div id="_desktop_search_filters_clear_all" class="hidden-sm-down clear-all-wrapper">
<button data-search-url="{$clear_all_link}" class="btn btn-tertiary js-search-filters-clear-all">
<i class="material-icons">&#xE14C;</i>
{l s='Clear all' d='Shop.Theme.Actions'}
</button>
<button id="_desktop_search_filters_clear_all" data-search-url="{$clear_all_link}" class="flex w-6 h-6 flex items-center justify-center select-none js-search-filters-clear-all">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-filter-off hover:stroke-2 cursor-pointer" width="16" height="16" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M8 4h12v2.172a2 2 0 0 1 -.586 1.414l-3.914 3.914m-.5 3.5v4l-6 2v-8.5l-4.48 -4.928a2 2 0 0 1 -.52 -1.345v-2.227"></path>
<path d="M3 3l18 18"></path>
</svg>
</button>
{else}
<div class="flex w-6 h-6 items-center justify-center select-none">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-filter hover:stroke-2 cursor-pointer" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M4 4h16v2.172a2 2 0 0 1 -.586 1.414l-4.414 4.414v7l-6 2v-8.5l-4.48 -4.928a2 2 0 0 1 -.52 -1.345v-2.227z"></path>
</svg>
</div>
{/if}
{/block}
{foreach from=$facets item="facet"}
<div class="flex gap-4 flex-1 flex-col lg:flex-row">
{foreach from=$facets item="facet"}
{if !$facet.displayed}
{continue}
{/if}
{if $facet.widgetType === 'dropdown'}
<div class="dropdown relative flex-1 max-w-[140px] group">
<button class="dropdown-toggle relative px-4 pr-6 leading-1 w-full text-left">
{$active_found = false}
{foreach from=$facet.filters item="filter"}
{if $filter.active}
{$filter.label}
{$active_found = true}
{/if}
{/foreach}
{if !$active_found}
{$facet.label}
{/if}
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-chevron-down absolute right-0 top-1" width="16" height="16" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M6 9l6 6l6 -6"></path>
</svg>
</button>
<div class="dropdown-menu hidden group-hover:flex flex-col position absolute left-0 top-full w-full bg-white">
{foreach from=$facet.filters item="filter"}
{if !$filter.active}
<a
rel="nofollow"
href="{$filter.nextEncodedFacetsURL}"
class="select-list px-4 py-1"
>
{$filter.label}
</a>
{/if}
{/foreach}
</div>
</div>
{/if}
{/foreach}
</div>
</div>
{/if}
{**
{if !$facet.displayed}
{continue}
{/if}
@ -163,6 +211,4 @@
{/block}
{/if}
</section>
{/foreach}
</div>
{/if}
*}

View File

@ -22,19 +22,13 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<div id="js-product-list-top" class="flex w-full justify-between">
<div id="js-product-list-top" class="flex w-full flex-col lg:flex-row lg:justify-between">
{if !empty($listing.rendered_facets)}
<div class="col-sm-3 col-xs-4 hidden-md-up filter-button">
<button id="search_filter_toggler" class="btn btn-secondary">
{l s='Filter' d='Shop.Theme.Actions'}
</button>
</div>
{include file='catalog/_partials/facets.tpl'}
{else}
<div></div>
{/if}
<div class="relative flex gap-4">
{block name='sort_by'}
{include file='catalog/_partials/sort-orders.tpl' sort_orders=$listing.sort_orders}
{/block}
</div>
{block name='sort_by'}
{include file='catalog/_partials/sort-orders.tpl' sort_orders=$listing.sort_orders}
{/block}
</div>

View File

@ -22,8 +22,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<div class="relative flex gap-2 items-center">
<span class="text-base">{l s='Sort by:' d='Shop.Theme.Global'}</span>
<div class="relative flex gap-2 lg:items-center">
<div class="relative w-48 dropdown group">
<button
class="w-full px-4 pr-8 py-1 gap-4 relative text-left h-8 hover:text-yellow-700 dropdown-toggle"