diff --git a/Block/LayeredNavigation/RenderLayered/DefaultRenderer.php b/Block/LayeredNavigation/RenderLayered/DefaultRenderer.php index f235785e..041859c2 100644 --- a/Block/LayeredNavigation/RenderLayered/DefaultRenderer.php +++ b/Block/LayeredNavigation/RenderLayered/DefaultRenderer.php @@ -238,6 +238,30 @@ public function getLessItemText() return 'Minder filters tonen'; } + /** + * @return bool + */ + public function isSearchable() + { + return ($this->getFacetSettings()->isSearchable() && $this->hasHiddenItems()); + } + + /** + * @return mixed|string|null + */ + public function getSearchPlaceholder() + { + return $this->getFacetSettings()->getSearchPlaceholder(); + } + + /** + * @return mixed|string|null + */ + public function getSearchNoResultsText() + { + return $this->getFacetSettings()->getSearchNoResultsText(); + } + /** * @return bool */ diff --git a/Block/LayeredNavigation/RenderLayered/SwatchRenderer.php b/Block/LayeredNavigation/RenderLayered/SwatchRenderer.php index 588cda29..04b16a56 100644 --- a/Block/LayeredNavigation/RenderLayered/SwatchRenderer.php +++ b/Block/LayeredNavigation/RenderLayered/SwatchRenderer.php @@ -217,4 +217,28 @@ public function shouldDisplayProductCountOnLayer() { return $this->getFacetSettings()->getIsNumberOfResultVisible(); } + + /** + * @return bool + */ + public function isSearchable() + { + return $this->getFacetSettings()->isSearchable(); + } + + /** + * @return mixed|string|null + */ + public function getSearchPlaceholder() + { + return $this->filter->getFacet()->getFacetSettings()->getSearchPlaceholder(); + } + + /** + * @return mixed|string|null + */ + public function getSearchNoResultsText() + { + return $this->filter->getFacet()->getFacetSettings()->getSearchNoResultsText(); + } } diff --git a/Model/Client/Type/FacetType/SettingsType.php b/Model/Client/Type/FacetType/SettingsType.php index 3570abf8..314ce1a6 100644 --- a/Model/Client/Type/FacetType/SettingsType.php +++ b/Model/Client/Type/FacetType/SettingsType.php @@ -210,4 +210,27 @@ public function getCssClass() return null; } + /** + * @return bool + */ + public function isSearchable() + { + return ($this->getBoolValue('issearchable')); + } + + /** + * @return mixed|string|null + */ + public function getSearchPlaceholder() + { + return empty($this->getValue('searchplaceholder')) ? '' : $this->getValue('searchplaceholder'); + } + + /** + * @return mixed|string|null + */ + public function getSearchNoResultsText() + { + return empty($this->getValue('searchnoresultstext')) ? '' : $this->getValue('searchnoresultstext'); + } } diff --git a/view/frontend/templates/product/layered/default.phtml b/view/frontend/templates/product/layered/default.phtml index 347d7e5d..6332d313 100644 --- a/view/frontend/templates/product/layered/default.phtml +++ b/view/frontend/templates/product/layered/default.phtml @@ -21,6 +21,10 @@ $shouldDisplayProductCountLayer = $block->shouldDisplayProductCountOnLayer(); ?>
+ isSearchable()): ?> + + +
    getItems() as $index => $item): ?>
  1. + isSearchable()): ?> + + +
    $label): ?> getItemForSwatch($option);?> diff --git a/view/frontend/web/css/style.less b/view/frontend/web/css/style.less index 65f56e17..a09a00bb 100644 --- a/view/frontend/web/css/style.less +++ b/view/frontend/web/css/style.less @@ -141,7 +141,7 @@ width: 24px; } } - + input[type='checkbox']:checked { + label .swatch-option { outline: 2px solid #ee0000; @@ -216,6 +216,11 @@ } } } + + .no_search_results { + display: none; + padding-top: 10px; + } } .filter .filter-current-subtitle, diff --git a/view/frontend/web/js/navigation-form.js b/view/frontend/web/js/navigation-form.js index 68b4ad8e..a761afaa 100644 --- a/view/frontend/web/js/navigation-form.js +++ b/view/frontend/web/js/navigation-form.js @@ -211,6 +211,10 @@ define([ _ajaxHandler: function (event) { event.preventDefault(); + if(event.target.name == 'tw_filtersearch') { + return; + } + if (this.currentXhr) { this.currentXhr.abort(); } diff --git a/view/frontend/web/js/navigation-sort.js b/view/frontend/web/js/navigation-sort.js index bc86f078..5e9d2685 100644 --- a/view/frontend/web/js/navigation-sort.js +++ b/view/frontend/web/js/navigation-sort.js @@ -27,6 +27,7 @@ define([ _hookEvents: function () { this.element.on('click', '.more-items', this._handleMoreItemsLink.bind(this)); this.element.on('click', '.less-items', this._handleLessItemsLink.bind(this)); + this.element.on('keyup', '.tw_filtersearch', this._handleFilterSearch.bind(this)); }, /** @@ -73,6 +74,42 @@ define([ return $(a).data(type) - $(b).data(type); }).appendTo(list); }, + + _handleFilterSearch: function () { + var filterInput = this.element.find('.tw_filtersearch'); + var value = filterInput.val().toLowerCase().trim(); + var items = filterInput.parent('div').find('ol'); + var noItems = filterInput.parent('div').find('.search_no_results'); + var defaultVisibleItems = filterInput.data('max-visible'); + var filterElement = 'li'; + var moreItems = filterInput.parent('div').find('.more-items'); + var lessItems = filterInput.parent('div').find('.less-items'); + + if (items.length === 0) { + //swatch + items = filterInput.parent('div'); + filterElement = 'a'; + defaultVisibleItems = 100; + } + + var filterItems = items.find(filterElement); + + filterItems.show().filter(function () { + return $(this).find('input').val().toLowerCase().trim().indexOf(value) === -1; + }).hide(); + + //more items visible than max visible items + filterItems.filter(':visible').slice(defaultVisibleItems).hide(); + + noItems.toggle(filterItems.filter(':visible').length < 1); + if (value.length === 0) { + moreItems.show(); + lessItems.hide(); + } else { + moreItems.hide(); + lessItems.hide(); + } + }, }); return $.tweakwise.navigationSort;