/** * Add filter by indexable attribute * * @param \Magento\CatalogSearch\Model\Resource\Advanced\Collection $collection * @param \Magento\Catalog\Model\Resource\Eav\Attribute $attribute * @param string|array $value * @return bool */ public function addIndexableAttributeModifiedFilter($collection, $attribute, $value) { if ($attribute->getIndexType() == 'decimal') { $table = $this->getTable('catalog_product_index_eav_decimal'); } else { $table = $this->getTable('catalog_product_index_eav'); } $tableAlias = 'a_' . $attribute->getAttributeId(); $storeId = $this->_storeManager->getStore()->getId(); $select = $collection->getSelect(); if (is_array($value)) { if (isset($value['from']) && isset($value['to'])) { if (empty($value['from']) && empty($value['to'])) { return false; } } } $select->distinct(true); $select->join(array($tableAlias => $table), "e.entity_id={$tableAlias}.entity_id " . " AND {$tableAlias}.attribute_id={$attribute->getAttributeId()}" . " AND {$tableAlias}.store_id={$storeId}", array()); if (is_array($value) && (isset($value['from']) || isset($value['to']))) { if (isset($value['from']) && !empty($value['from'])) { $select->where("{$tableAlias}.value >= ?", $value['from']); } if (isset($value['to']) && !empty($value['to'])) { $select->where("{$tableAlias}.value <= ?", $value['to']); } return true; } $select->where("{$tableAlias}.value IN(?)", $value); return true; }