/app/code/core/Mage/Catalog/Block/Product/List.php
there is a function
protected function _getProductCollection()
{
if (is_null($this->_productCollection)) {
$layer = $this->getLayer();
/* @var $layer Mage_Catalog_Model_Layer */
if ($this->getShowRootCategory()) {
$this->setCategoryId(Mage::app()->getStore()->getRootCategoryId());
}
// if this is a product view page
if (Mage::registry('product')) {
// get collection of categories this product is associated with
$categories = Mage::registry('product')->getCategoryCollection()
->setPage(1, 1)
->load();
// if the product is associated with any category
if ($categories->count()) {
// show products from this category
$this->setCategoryId(current($categories->getIterator()));
}
}
$origCategory = null;
if ($this->getCategoryId()) {
$category = Mage::getModel('catalog/category')->load($this->getCategoryId());
if ($category->getId()) {
$origCategory = $layer->getCurrentCategory();
$layer->setCurrentCategory($category);
$this->addModelTags($category);
}
}
$this->_productCollection = $layer->getProductCollection();
$this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
if ($origCategory) {
$layer->setCurrentCategory($origCategory);
}
}
return $this->_productCollection;
}
It returns the product collection after applying the layered navigation filters.
Anyone could let me know where it is applying the filters.
For example : I have an attribute brand which is shown in layered navigation.
If I select a value for this attribute then Magento refreshes the page and returns the product collection after applying the filter. The above function is returning the product collection but I could not find the query where it is applying this condition.
Anyone could tell me how magento is getting the product collection, where is the query.
So as suggested by @simonthesorcerer
$this->_productCollection = $layer->getProductCollection();
I looked into the function getProductCollection() and echoed out what was there in the collection. Here is the function
/**
* Retrieve current layer product collection
*
* @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
*/
public function getProductCollection()
{
if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) {
$collection = $this->_productCollections[$this->getCurrentCategory()->getId()];
} else {
$collection = $this->getCurrentCategory()->getProductCollection();
$this->prepareProductCollection($collection);
$this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;
}
echo "<pre>";print_r($collection->getData());die(); //Custom to check collection
return $collection;
}
I selected a category and got 62 products in collection that was correct and then I selected an attribute filter and again it shows 62 products, means this is not the function which is applying attribute filter to categories. So anyone could tell me where is the code where attribute filter is applied to the collection. I just want to locate that code.