diff --git a/composer.json b/composer.json index 9aaacd3..0556e59 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "hyva-themes/magento2-compat-module-fallback": "*", "hyva-themes/magento2-default-theme": "^1.2", "php": ">=8.0 <8.3", - "tweakwise/magento2-tweakwise": ">=5.2.0." + "tweakwise/magento2-tweakwise": ">=6.0.0." }, "autoload": { "files": [ diff --git a/src/view/frontend/templates/layer/navigation-form.phtml b/src/view/frontend/templates/layer/navigation-form.phtml index 9052092..7b4c836 100644 --- a/src/view/frontend/templates/layer/navigation-form.phtml +++ b/src/view/frontend/templates/layer/navigation-form.phtml @@ -323,6 +323,7 @@ use Magento\Framework\View\Element\Template; this.replaceNode(oldToolbarLast, newToolbarLast); } }, + ajaxUpdateState(response) { window.history.pushState({html: response.html}, '', response.url); }, diff --git a/src/view/frontend/templates/layer/view.phtml b/src/view/frontend/templates/layer/view.phtml index b81c368..346ab7d 100644 --- a/src/view/frontend/templates/layer/view.phtml +++ b/src/view/frontend/templates/layer/view.phtml @@ -193,6 +193,55 @@ $filtered = count($block->getLayer()->getState()->getFilters()); } } } + + function initFilterSearch() { + return { + filterSearch() { + let items = this.$refs.items; + const filterSearch = this.$refs.tw_filtersearch; + let value = filterSearch.value.toLowerCase().trim(); + let noItems = this.$refs.search_no_results; + let moreItems = this.$refs.moreItems; + let lessItems = this.$refs.lessItems; + + //swatch + if (!items || !items.children) { + items = this.$refs.swatch; + } + + if (!items || !items.children) { + return; + } + + Array.from(items.children).forEach(function(item) { + //find input element in item + let input = item.querySelector('input'); + if (input.value.toLowerCase().trim().indexOf(value) === -1) { + item.style.display = 'none'; + } else { + item.style.display = ''; + } + }); + + let visibleItems = Array.from(items.children).filter(item => item.style.display !== 'none'); + if(visibleItems.length < 1) { + noItems.style.display = ''; + } else { + noItems.style.display = 'none'; + } + + if (moreItems) { + if(value.length === 0) { + moreItems.style.display = ''; + lessItems.style.display = ''; + } else { + moreItems.style.display = 'none'; + lessItems.style.display = 'none'; + } + } + } + } + } getChildHtml('tweakwise.navigation.form');?> diff --git a/src/view/frontend/templates/product/layered/default.phtml b/src/view/frontend/templates/product/layered/default.phtml index ce0104e..7b8336f 100644 --- a/src/view/frontend/templates/product/layered/default.phtml +++ b/src/view/frontend/templates/product/layered/default.phtml @@ -16,14 +16,20 @@ use Tweakwise\Magento2Tweakwise\Block\LayeredNavigation\RenderLayered\DefaultRen $hasHiddenItems = $block->hasHiddenItems(); $hasAlternateSortOrder = $block->hasAlternateSortOrder(); + ?>
+ isSearchable()): ?> + + +
    getItems() as $index => $item): ?>
  1. data-alternate-sort="getAlternateSortOrder(); ?>" + data-original-sort="" > @@ -66,11 +72,13 @@ $hasAlternateSortOrder = $block->hasAlternateSortOrder(); getMoreItemText()) ?> getLessItemText()) ?>
diff --git a/src/view/frontend/templates/product/layered/swatch.phtml b/src/view/frontend/templates/product/layered/swatch.phtml index 3e4afe3..310dd8a 100644 --- a/src/view/frontend/templates/product/layered/swatch.phtml +++ b/src/view/frontend/templates/product/layered/swatch.phtml @@ -89,7 +89,11 @@ if (!$swatchData['swatches']) { x-data="initLayeredSwatch_escapeJs($swatchData['attribute_code']) ?>()" data-attribute-code="escapeHtmlAttr($swatchData['attribute_code']) ?>" data-attribute-id="escapeHtmlAttr($swatchData['attribute_id']) ?>"> -
+ isSearchable()): ?> + + + +
$label): ?> getItemForSwatch($option);