I created a custom price filter (without layered navigation). This function works great on simple products, but configurable products are filtered (maybe because they don't have a price?).
This is my function:
<?php namespace Silvan\Sidebar\Model\Plugin;
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
class SidebarFilter
{
public function aroundAddFieldToFilter(ProductCollection $collection, \Closure $proceed, $fields, $condition = null)
{
if ($fields === 'category_ids') {
$price = isset($_GET[ 'price' ]) ? $_GET[ 'price' ] : false;
if ($price && strpos($price, '-') !== false) {
$price = explode('-', $price);
$min = isset($price[ 0 ]) ? $price[ 0 ] : 0;
$max = isset($price[ 1 ]) ? $price[ 1 ] : 9999999;
$collection->addAttributeToFilter('price', ['gt' => $min]);
$collection->addAttributeToFilter('price', ['lt' => $max]);
}
}
return $fields ? $proceed($fields, $condition) : $collection;
}
}
I tried using min_price and max_price, but these attributes are ignored in the filter.