I need override \vendor\magento\module-catalog-search\Model\Layer\Search\Plugin\CollectionFilter.php File, i need get the search term and replace "-" and "." for nothing. Which a best method for make this? I know how to override view files in my design theme but i don't know how to override Model files.
Example:
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogSearch\Model\Layer\Search\Plugin;
use Magento\Catalog\Model\Category;
use Magento\Search\Model\QueryFactory;
/**
* Catalog search plugin for search collection filter in layered navigation.
*/
class CollectionFilter
{
/**
* @var \Magento\Search\Model\QueryFactory
*/
protected $queryFactory;
/**
* @param QueryFactory $queryFactory
*/
public function __construct(QueryFactory $queryFactory)
{
$this->queryFactory = $queryFactory;
}
/**
* Add search filter criteria to search collection
*
* @param \Magento\Catalog\Model\Layer\Search\CollectionFilter $subject
* @param null $result
* @param \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $collection
* @param Category $category
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterFilter(
\Magento\Catalog\Model\Layer\Search\CollectionFilter $subject,
$result,
$collection,
Category $category
) {
/** @var \Magento\Search\Model\Query $query */
$query = $this->queryFactory->get();
if (!$query->isQueryTextShort()) {
$text = $query->getQueryText();
$text = str_replace(array("-","."),"",$text);
$collection->addSearchFilter($text);
}
}
}