5

I have been having this issue for several weeks now and after looking through similar issues on this site and others, I still can't figure out how to solve this problem.

After successfully executing setup:di:compile, the var/di folder gets created in my Magento directory. my homepage and CMS pages keep working fine, but after compilation I noticed my category pages (for ex. domain.com/shop) give me the following error:

Fatal error: Uncaught TypeError: Argument 1 passed to Plazathemes\LayeredNavigation\Controller\Category\View::__construct() must be an instance of Magento\Framework\App\Action\Context, instance of Magento\Framework\ObjectManager\ObjectManager given, called in directory/www/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 93 and defined in directory/www/app/code/Plazathemes/Layerednavigation/Controller/Category/View.php:27 Stack trace: #0 directory/www/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(93): Plazathemes\LayeredNavigation\Controller\Category\View->__construct(Object(Magento\Framework\ObjectManager\ObjectManager)) #1 directory/www/vendor/magento/framework/ObjectManager/Factory/Compiled.php(88): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('Plazathemes\Lay...', Array) #2 directory/www/vendor/magento/framework/ObjectManager/ObjectManager.php(57): Magento\F in directory/www/app/code/Plazathemes/Layerednavigation/Controller/Category/View.php on line 27

My code/Plazathemes/LayeredNavigation/Controller/Category/View file starts with this:

class View extends \Magento\Catalog\Controller\Category\View
{
    private $layerResolver;

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Catalog\Model\Design $catalogDesign,
        \Magento\Catalog\Model\Session $catalogSession,
        \Magento\Framework\Registry $coreRegistry,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator,
        PageFactory $resultPageFactory,
        \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory,
        Resolver $layerResolver,
        CategoryRepositoryInterface $categoryRepository
    )
    {
        parent::__construct($context, $catalogDesign, $catalogSession, $coreRegistry, $storeManager, $categoryUrlPathGenerator, $resultPageFactory, $resultForwardFactory, $layerResolver, $categoryRepository);
        $this->layerResolver = $layerResolver;
    }

    public function execute()
    {
        // somthing
    }

}

I contacted my theme support but they told me this error is not a result of a bug in their theme.

Anyone who can help me figure this out? I'm fairly new to Magento and quite overwhelmed by all these errors. I've already sorted out most of my problems and errors, but this one keeps coming back.

If you need any additional code, please let me know.

I'm running Magento 2.1.5

EDIT: FYI when I delete my var/di folder or just the global.serand frontend.serfiles in it, the category pages work again but uncompiled, making them extremely slow to load. So I need to sort this out in order to have my compiled files working.

  • Which PHP version ur using? – Ankit Shah Mar 16 '17 at 8:28
  • My PHP version is 7.0.15 – Senne Vandenputte Mar 16 '17 at 8:30
  • Their theme is working fine on 2.1.3? They have demo for that version? – Ankit Shah Mar 16 '17 at 8:35
  • Yes they have a working demo which I also tested on my local system with sample data. Their website says the theme is fully compatible with Magento 2.1.x – Senne Vandenputte Mar 16 '17 at 8:41
  • Check here /www/app/code/Plazathemes/Layerednavigation/Controller/Category/View.php on line 27 – Ankit Shah Mar 16 '17 at 8:47
6

I found that in the LN module 2 different namespace declarations was used: Layerednavigation and LayeredNavigation. When code is compiled all di class arguments was stored in the array where the class name with namespace was used as key (string).

log config

The problem is in the autoloader: it can not find the files because array keys are case sensitive in the php and Layerednavigation is different from LayeredNavigation. I don't know why, but Theme developers used 2 different words. 😞 Possibly they just do not test it with compiled version.

I have renamed all namespaces and filenames to the LayeredNavigation (camel-case) and all works fine.

Step-by-step actions:

  1. Change filenames and class names (including namespaces, block names in the layout, etc.) from the Layerednavigation to the LayeredNavigation
  2. Reinstall module
  3. Recompile code

PS: This question is not off-topic (third party module) because you can change the Layerednavigation to another name.

  • This is not my error I got but the solution is what I was looking for to find my issue. Thanks. – dchayka Apr 3 '18 at 19:44
2

The following sequence of actions usually help me to resolve such errors:

  • bin/magento cache:flush
  • remove var/generation and var/di
  • bin/magento setup:di:compile
0

As they have extension layout has issue

Go to here -> app/code/Plazathemes/Layerednavigation/view/frontend/layout in file catalogsearch_result_index.xml

Change this one

<referenceContainer name="page.wrapper">
            <block class="Plazathemes\LayeredNavigation\Block\LayeredNavigation" name="layered.loading.background" as="layered_loading_background" after="-">
                <action method="setTemplate" ifconfig="ajaxlayerednavigation/general/enabled">
                    <argument name="template" xsi:type="string">Plazathemes_Layerednavigation::layerbackground.phtml</argument>
                </action>
            </block>
        </referenceContainer>

to this one

<referenceContainer name="page.wrapper">
            <block class="Plazathemes\Layerednavigation\Block\Layerednavigation" name="layered.loading.background" as="layered_loading_background" after="-">
                <action method="setTemplate" ifconfig="ajaxlayerednavigation/general/enabled">
                    <argument name="template" xsi:type="string">Plazathemes_Layerednavigation::layerbackground.phtml</argument>
                </action>
            </block>
        </referenceContainer>

and clear cache your issue solve.

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.