/** * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection * @param Morphes_Filters_Model_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()->join(array($tableAlias => $this->getMainTable()), $conditions, array()); return $this; }
/** * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection * @param Morphes_Filters_Model_Filter_Attribute $model * @return Morphes_Filters_Resource_Filter_Decimal */ public function countOnCollection($collection, $model) { $select = $collection->getSelect(); $select->reset(Zend_Db_Select::COLUMNS); $select->reset(Zend_Db_Select::ORDER); $select->reset(Zend_Db_Select::LIMIT_COUNT); $select->reset(Zend_Db_Select::LIMIT_OFFSET); $attributeId = $model->getAttributeModel()->getId(); $storeId = $collection->getStoreId(); $select->join(array('decimal_index' => $this->getMainTable()), 'e.entity_id = decimal_index.entity_id' . ' AND ' . $this->_getReadAdapter()->quoteInto('decimal_index.attribute_id = ?', $attributeId) . ' AND ' . $this->_getReadAdapter()->quoteInto('decimal_index.store_id = ?', $storeId), array()); $adapter = $this->_getReadAdapter(); $countExpr = new Zend_Db_Expr("COUNT(*)"); $rangeExpr = new Zend_Db_Expr("FLOOR(decimal_index.value / {$model->getRange()}) + 1"); $select->columns(array('range' => $rangeExpr, 'count' => $countExpr)); $select->group('range'); return $adapter->fetchPairs($select); }
/** * @param Enterprise_Search_Model_Resource_Collection $collection * @param Morphes_Filters_Model_Filter_Attribute $model * @param array $value * @return Morphes_Filters_Resource_Solr_Attribute */ public function applyToCollection($collection, $model, $value) { $collection->addFqFilter(array($model->getFilterField() => array('reverse' => $value))); }
protected function _applyToCollection($collection, $value = null) { if ($rangeAndLabels = $this->_getRangeAndLabels()) { extract($rangeAndLabels); /* @var $text array */ /* @var $from string */ /* @var $to string */ $isInside = false; $items = $this->_getItemsData(); $values = array(); foreach ($items as $item) { if ($item['value'] == $from) { if ($item['value'] != $to) { $isInside = true; } $values[] = $item['value']; } elseif ($item['value'] == $to) { $isInside = false; $values[] = $item['value']; } elseif ($isInside) { $values[] = $item['value']; } } parent::_applyToCollection($collection, $values); } //$this->_getResource()->applyToCollection($collection, $this, $this->getMSelectedValues()); }