/** * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection * @param Morphes_Filters_Resource_Filter_Attribute $model * @param array $value * @return Morphes_Filters_Resource_Filter_Attribute */ public function applyToCollection($collection, $model, $value) { $attribute = $model->getAttributeModel(); $connection = $this->_getReadAdapter(); $tableAlias = $attribute->getAttributeCode() . '_idx'; $conditions = array("{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $collection->getStoreId()), "{$tableAlias}.value in (" . implode(',', array_filter($value)) . ")"); $conditions = join(' AND ', $conditions); $collection->getSelect()->distinct()->where("NOT EXISTS (SELECT * " . "FROM `{$this->getMainTable()}` AS `{$tableAlias}` " . "WHERE {$conditions})"); return $this; }
/** * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection * @param Morphes_Filters_Resource_Filter_Attribute $model * @param array $value * @return Morphes_Filters_Resource_Filter_Attribute */ public function applyToCollection($collection, $model, $value) { $attribute = $model->getAttributeModel(); $connection = $this->_getReadAdapter(); foreach ($value as $i => $singleValue) { $tableAlias = $attribute->getAttributeCode() . '_idx' . $i; $conditions = array("{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $collection->getStoreId()), "{$tableAlias}.value = {$singleValue}"); $conditions = join(' AND ', $conditions); $collection->getSelect()->distinct()->join(array($tableAlias => $this->getMainTable()), $conditions, array()); } return $this; }