It seems like Overriding Block and Model in magento2 work only if the class is directly being called.

For Example i want to override model file


Here is my 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\Filter\AbstractFilter" type="Mynamespace\Comman\Model\Layer\Filter\AbstractFilter" />

And This is my AbstractFilter.php

namespace Mynamespace\Comman\Model\Layer\Filter;

abstract class AbstractFilter extends \Magento\Catalog\Model\Layer\Filter\AbstractFilter
    public function __construct(
        \Magento\Catalog\Model\Layer\Filter\ItemFactory $filterItemFactory,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Catalog\Model\Layer $layer,
        \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder $itemDataBuilder,
        array $data = []
    ) {

        if ($this->hasAttributeModel()) {
            $this->_requestVar = $this->getAttributeModel()->getAttributeCode();

    /* i want to override this function*/
    protected function isOptionReducesResults($optionCount, $totalSize)
        return $optionCount <= $totalSize;

This is not working because AbstractFilter is not being called directly from anywhere.

If i do same thing for


It is working fine.

I am facing same issue for class:


Which is not working however classes



which are working fine.

Can someone guide me if i am wrong here.

  • magento.stackexchange.com/questions/157797/… give u some hint if u want to override abstract class – Jackson Feb 6 '17 at 10:19
  • @AnkitShah This is not the case for only abstract class.vendor/magento/module-bundle/Block/Catalog/Product/View/Type/Bundle/Option.php is not abstract class but is parent of Checkbox and Radio – Minesh Patel Feb 6 '17 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.