3

i have an custom design were we overload the: \app\design\frontend\Come\schlafgut\Magento_LayeredNavigation\templates\layer\view.phtml

We add there a new block methode .. fe. sayHello()

<?php

namespace Come\ProductListSwatches\Block\Catalog;

class Swatches extends \Magento\LayeredNavigation\Block\Navigation
{
    public function sayHello()
    {
        return "something";
    }
}

In view.phtml:

<?php if ($block->canShowBlock()): ?>
    <div class="block filter">

        <?php echo $block->sayHello(); ?>

Than we create a di.xml file:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <preference for="Magento\LayeredNavigation\Block\Navigation" type="Come\ProductListSwatches\Block\Catalog\Swatches" />
</config>

We work in developer mode, but we received this error:

PHP Fatal error:  Uncaught Error: Cannot instantiate interface Magento\\Catalog\\Model\\Layer\\FilterableAttributeListInterface 
in /var/www/schlafgut/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:73\nStack trace:\n#0 /var/www/schlafgut/vendor/magento/framework/ObjectManager/ObjectManager.php(71): 
Magento\\Framework\\ObjectManager\\Factory\\Dynamic\\Developer->create('Magento\\\\Catalog...')\n#1 /var/www/schlafgut/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(126): 
Magento\\Framework\\ObjectManager\\ObjectManager->get('Magento\\\\Catalog...')\n#2 /var/www/schlafgut/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(53): 
Magento\\Framework\\ObjectManager\\Factory\\AbstractFactory->resolveArgument(Array, 'Magento\\\\Catalog...', NULL, 'filterableAttri...', 'Magento\\\\Catalog...')\n#3 /
var/www/schlafgut/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(82): Magento\\Framework\\ObjectManager\\Factory\\Dynamic\\Developer->_resolveArguments('Magento\\\\Catalog...', Array, Array)\n#4 
/var/w in /var/www/schlafgut/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php on line 73

Do anyone know what is wrong?

5 Answers 5

0

An interface which you cannot instantiate isn't had its own preference but implemented by Magento\Catalog\Model\Layer\Category\FilterableAttributeList.

It's ok to not to have a preference since FilterableAttributeListInterface isn't something general and should contain attributes for a specific case (like Category Layered Navigation, for example).

However, \Magento\Catalog\Model\Layer\FilterList depends on that interface. And Magento\LayeredNavigation\Block\Navigation is depends on \Magento\Catalog\Model\Layer\FilterList.

So, to correctly instantiate Magento\LayeredNavigation\Block\Navigation we need to pass to its constructor a configured instance of \Magento\Catalog\Model\Layer\FilterList.

Let's look where is Magento\LayeredNavigation\Block\Navigation used. We can find that it never used itself, but two virtual types use it (Magento/LayeredNavigation/etc/frontend/di.xml):

  • Magento\LayeredNavigation\Block\Navigation\Category
  • Magento\LayeredNavigation\Block\Navigation\Search

They are both customize filterList argument.

So it's all ok with your code (at least with your example), but something went wrong in place where your object should be instantiated.

Look at debugger which type do you fail to instantiate.

2
  • I just can work on a dev server (outside from my computer ) .. is there a option to debug this ( central point?? ) .. The main goal of my request is, that i want to transform a multiselect attribute (we have to use in Backend) to display as Swatch in Frontend .. if you know a solution or link, please let me know! Commented Aug 28, 2016 at 14:11
  • 1
    I solved it by using mandev and rewrite there filterRenderer Commented Aug 28, 2016 at 17:32
1

This could be more/less a core bug. The solution, at this point, is to include this line along with the original preference:

<preference for="Magento\Catalog\Model\Layer\FilterableAttributeListInterface" type="Magento\Catalog\Model\Layer\Category\FilterableAttributeList"/>

I found this suggestion in a similar post. It feels like somewhat of a hack, but for me, it corrected the issue.

1
  • This solution works for us. we would be thanks full if anyone can share details why we need this rather than its own class ( <preference for="Magento\LayeredNavigation\Block\Navigation" type="Come\ProductListSwatches\Block\Catalog\Swatches" /> ) Commented Oct 5, 2022 at 12:37
0

Looks fine to me at first glance, you should try clearing the cache via bin/magento cache:flush --all (also make sure to clear var/generation/ and var/cache/ just to be sure) and afterwards running bin/magento setup:di:compile. Have a look at the official documentation as well to learn more about the DI compiler:

http://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-compiler.html#config-cli-subcommands-single

4
  • We work in development mode .. so no need to compile. Commented Aug 28, 2016 at 12:28
  • Nevertheless, you should still try clearing the relevant var/ directories, it's not the first time I have come across weird issues like that where something was cached and caused these kinds of issues. In any case, keep us posted if you end up finding a solution. Also, I cannot comment on the other reply from Bilal Usean due to my low reputation score here, but copying the whole block is definitely not the right solution and bad practice, do not do that. Extending the block the way you do is correct.
    – TiEul
    Commented Aug 28, 2016 at 12:39
  • I did .. but same problem at all. Commented Aug 28, 2016 at 12:57
  • indeed @TiEul half sleepy ans. deleted :-) Commented Aug 28, 2016 at 13:44
0

Must combine with interceptor, for example di.xml plugin must be like:

<type name="Magento\LayeredNavigation\Block\Navigation">
    <plugin name="example_name1" type="SlavaYurthev\Example\Block\Templates\Layer\View" sortOrder="9999" />
</type>
<type name="Magento\LayeredNavigation\Block\Navigation\Search">
    <plugin name="example_name2" type="SlavaYurthev\Example\Block\Templates\Layer\View" sortOrder="9998" />
</type>
<type name="Magento\LayeredNavigation\Block\Navigation\Category">
    <plugin name="example_name3" type="SlavaYurthev\Example\Block\Templates\Layer\View" sortOrder="9997" />
</type>

And now in SlavaYurthev\Example\Block\Templates\Layer\View

public function afterYourMethod($subject, $result){
    // for example
    // return $newResult;
}
0
<type name="Come\ProductListSwatches\Block\Catalog\Swatches">
    <arguments>
        <argument name="filterList" xsi:type="object">categoryFilterList</argument>
    </arguments>
</type>

add this in your module's di.xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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