/** * Add filter by indexable attribute * * @param Mage_CatalogSearch_Model_Resource_Advanced_Collection $collection * @param Mage_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 = Mage::app()->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; }
/** * Add filter by indexable attribute * * @param Mage_CatalogSearch_Model_Resource_Advanced_Collection $collection * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute * @param string|array $value * @return bool */ public function addCustomIndexableAttributeModifiedFilter($collection, $attribute, $value) { if ($attribute->getIndexType() == 'decimal') { $table = $this->getTable('catalog/product_index_eav_decimal'); } else { $table = $this->getTable('catalog/product_entity_int'); } $tableAlias = 'a_' . $attribute->getAttributeId(); $storeId = Mage::app()->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), "cp.child_id={$tableAlias}.entity_id " . " AND {$tableAlias}.attribute_id={$attribute->getAttributeId()}" . " AND {$tableAlias}.store_id={$storeId}", array()); /*$select->joinLeft( array( 'catalog_product_entity_int'), "catalog_product_entity_int.attribute_id={$attribute->getAttributeId()} ", array() ); $select->join( array( 'catalog_product_bundle_selection'), "catalog_product_entity_int.entity_id=catalog_product_bundle_selection.product_id " . " AND e.entity_id=catalog_product_bundle_selection.parent_product_id", array("other_product_id"=>"catalog_product_bundle_selection.product_id") ); */ 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", $value); return true; }