Which interface instantiation is missing in my constructor

namespace Vendor\Module\Block;

use Magento\Catalog\Block\Product\ListProduct;
use Magento\Catalog\Model\Layer\Resolver as LayerResolver;
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection;
use Magento\CatalogSearch\Helper\Data;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\LayeredNavigation\Block\Navigation;
use Magento\Search\Model\QueryFactory;
use Magento\Catalog\Model\Layer\FilterableAttributeListInterface;
use Magento\Catalog\Model\Layer\FilterList;
use Magento\Catalog\Model\Layer\AvailabilityFlagInterface;
use Magento\Catalog\Model\Layer\Category\FilterableAttributeList;

class Result extends \Magento\Framework\View\Element\Template

   protected $tglssearchHelper;
   protected $catalogLayer;
   public function __construct(
   Context $context,
    LayerResolver $layerResolver,
    \Magento\Catalog\Model\Layer\FilterList $filterList,
    \Magento\Catalog\Model\Layer\AvailabilityFlagInterface $visibilityFlag,
    \Vendor\Module\Helper\Data $tglssearchHelper,
    QueryFactory $queryFactory,
    FilterableAttributeListInterface $filterableAttributes,
    array $data = []
) {
    $this->catalogLayer = $layerResolver->get();
    $this->tglssearchHelper = $tglssearchHelper;
    $this->queryFactory = $queryFactory;
    $this->filterableAttributes = $filterableAttributes;

 protected function _prepareLayout()

    $this->renderer = $this->getChildBlock('renderer');
    foreach ($this->filterList->getFilters($this->_catalogLayer) as $filter) {
    return parent::_prepareLayout();

my etc di

 <?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\CatalogSearch\Controller\Result\Index" type="Vendor\Module\Controller\Result\Index" />
<preference for="Magento\Catalog\Controller\Category\View" type="Vendor\Module\Controller\Category\View" />
<preference for="Magento\CatalogSearch\Block\Result" type="Vendor\Module\Block\Result" />
<preference for="Magento\LayeredNavigation\Block\Navigation" type="Vendor\Module\Block\Navigation" />
<preference for="Magento\Catalog\Block\Product\ListProduct" type="Vendor\Module\Block\Product\ListProduct" />
<preference for="Magento\Catalog\Block\Product\ProductList\Toolbar" type="Vendor\Module\Block\Product\ProductList\Toolbar" />
 <preference for="Magento\Catalog\Model\ResourceModel\Product\Collection" type="Vendor\Module\Model\ResourceModel\Product\Collection" />
<!-- <type name="Magento\Catalog\Model\ResourceModel\Product\Collection">
    <plugin name="mymoduletag" type="Vendor\Module\Model\ResourceModel\Product\Collection" sortOrder="10"/>
</type> -->

I get :

Cannot instantiate interface Magento\Catalog\Model\Layer\FilterableAttributeListInterface in C:\xampp\htdocs\magento2x_2\lib\internal\Magento\Framework\ObjectManager\Factory\Dynamic\Developer.php on line 73

  • is this your own class or a core one? And if it's your own, are you trying to use it on frontend or backend? – Marius Jul 5 '16 at 13:28
  • Please see updated answer .. to use filterList i have used as above – Sushivam Jul 5 '16 at 14:32

If you are trying to use this \Magento\Catalog\Model\Layer\AvailabilityFlagInterface as a dependency for a class that you are going to use in the backend, you need to add this to the adminhtml/di.xml of your module

<preference for="Magento\Catalog\Model\Layer\AvailabilityFlagInterface" type="Magento\Catalog\Model\Layer\Category\AvailabilityFlag" />

If you are going to use it on frontend it should work without any issues.

This happens because the preference (the class to use by default by the object manager) for the interface Magento\Catalog\Model\Layer\AvailabilityFlagInterface is declared in app/code/Magento/LayeredNavigation/etc/frontend/di.xml so it only works for frontend.

  • Please see updated answer .. to use filterList i have used as above – Sushivam Jul 5 '16 at 14:32
  • updated my etc di in answer as well – Sushivam Jul 5 '16 at 14:34
  • i added AvailabilityFlagInterface in an assumption that error was thrown because of some missing dependencies, nyways im not using this AvailabilityFlagInterface, i need filterList(i suppose its from LayeredNavigation) which i need it in my Result.php – Sushivam Jul 5 '16 at 14:40
  • any update on this? @Marius – Sushivam Jul 6 '16 at 10:53
  • @SachinS I have no other idea. – Marius Jul 6 '16 at 10:59

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.