cancel
Showing results for 
Search instead for 
Did you mean: 

Ask about getProductCollection on Mage_Catalog_Model_Layer Class

SOLVED

Ask about getProductCollection on Mage_Catalog_Model_Layer Class

When we run link http://localhost/magento19/test.html/?manufacturer=3 (witt test is category) they will return the collection with product has been filtered.

go to Mage_Catalog_Model_Layer Class Reference

 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;
    }

    return $collection;
}

when I remove the code:

  $this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;

This will return the collection with no filter (http://localhost/magento19/test.html/?manufacturer=3)>. I don't understand how does it work ? why can the collection filter the attribute "manufacture" with this code

$this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;

Thanks for reading this post

2 REPLIES

Re: Ask about getProductCollection on Mage_Catalog_Model_Layer Class

Hi,

 

$this->_productCollections[$this->getCurrentCategory()->getId()

It will return current category id. If you remove it, Magento not found current category id and it will return all category instead of current category.

$this->setCurrentCategory()->getId() will return current category i.e manufacture and his ID: 3.

 

If this post is fullfil your solution then please mark accept.

 

Thanks,

Dibyajyoti

Re: Ask about getProductCollection on Mage_Catalog_Model_Layer Class

You misunderstand my issue. Example when you run layer navigation on magento 

http://localhost/magento19/test.html/?manufacturer=3. It will return the result for you. I want to change this: 

http://localhost/magento19/test.html/?manufacturer=nike ( with the option_id=3, option_value=nike). I found this code 

$this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;

it used to filter. But I don't understand what function or class this has called to  filter.