Overriding
Magento\Catalog\Model\Layer
class not working in Magento 2.
I'm trying to create a custom module for showing custom product collection with layered navigation.
here i added di.xml
file to overwrite model using preference
.
But its not working, i tried to create log also, no log generated.
\app\code\Mage\Search\etc\di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Catalog\Model\Layer" type="Mage\Search\Model\Layer" />
</config>
Layer.php
namespace Mage\Search\Model;
class Layer extends \Magento\Catalog\Model\Layer
{
public function getProductCollection()
{
/*added log here*/
var_dump('test'); // nothing showed.
die(); // this also not helped
if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) {
$collection = $this->_productCollections[$this->getCurrentCategory()->getId()];
} else {
$collection = $this->collectionProvider->getCollection($this->getCurrentCategory());
$this->prepareProductCollection($collection);
$this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;
}
return $collection;
}
}
Please suggest any solution for this.
Thank you!
\app\code\Mage\Search\etc\di.xml