To customize the layered navigation in Magento 2, sometimes, we need to override the core class file. Generally, we can use preference to override models, but it’s not possible every time.
So on that case, we need to use a different approach and have to use virtualType to achieve that.
Please find below the steps to override models using virtualType.
1. Create an di.xml in : /app/code/Magemonkeys/LayerModel/etc
1 2 3 4 5 6 7 |
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <virtualType name="categoryFilterList" type="Magemonkeys\LayerModel\Model\Layer\FilterList"> <arguments> <argument name="filterableAttributes" xsi:type="object">Magento\Catalog\Model\Layer\Category\FilterableAttributeList</argument> </arguments> </virtualType> </config> |
2. Create an FilterList.php in : /app/code/Magemonkeys/LayerModel/Model/Layer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php namespace Magemonkeys\LayerModel\Model\Layer; class FilterList extends \Magento\Catalog\Model\Layer\FilterList { public function getFilters(\Magento\Catalog\Model\Layer $layer) { if (!count($this->filters)) { $this->filters = [ $this->objectManager->create($this->filterTypes[self::CATEGORY_FILTER], ['layer' => $layer]), ]; foreach ($this->filterableAttributes->getList() as $attribute) { $this->filters[] = $this->createAttributeFilter($attribute, $layer); } } return $this->filters; } } ?> |
[crayon-63e096896aa6e445557155/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.