PHP fatal error: Uncaught TypeError: Argument 2 passed to Magento\Catalog\Plugin\Block\Topmenu
-
31-01-2021 - |
Вопрос
this is happening when I install megamenu from template monster and updated to Magento 2.2.6 any ideas? full error below
Fatal error: Uncaught TypeError: Argument 2 passed to Magento\Catalog\Plugin\Block\Topmenu::__construct() must be an instance of Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory, instance of Magento\Catalog\Model\ResourceModel\Category\CollectionFactory given, called in /home/olabrava/public_html/app/code/TemplateMonster/Megamenu/Plugin/Block/Topmenu.php on line 27 and defined in /home/olabrava/public_html/vendor/magento/module-catalog/Plugin/Block/Topmenu.php:47 Stack trace: #0 /home/olabrava/public_html/app/code/TemplateMonster/Megamenu/Plugin/Block/Topmenu.php(27): Magento\Catalog\Plugin\Block\Topmenu->__construct(Object(Magento\Catalog\Helper\Category), Object(Magento\Catalog\Model\ResourceModel\Category\CollectionFactory), Object(Magento\Store\Model\StoreManager), Object(Magento\Catalog\Model\Layer\Resolver)) #1 /home/olabrava/public_html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(111): TemplateMonster\Megamenu\Plugin\Block\Topmenu->__construct(Object(Magento\Catalo in /home/olabrava/public_html/vendor/magento/module-catalog/Plugin/Block/Topmenu.php on line 47
Решение
Open vendor/magento/module-catalog/Plugin/Block/Topmenu.php
The constructor of this class looks like
public function __construct(
\Magento\Catalog\Helper\Category $catalogCategory,
\Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory $categoryCollectionFactory,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Catalog\Model\Layer\Resolver $layerResolver
)
Now, open TemplateMonster\Megamenu\Plugin\Block\Topmenu
and take a look at its __construct
method.
Your first check should be if parent::_construct()
is called.
If it does, what parameters are send there?
Your checks here:
A. Does parent::__construct
receives 4 parameters?
B. What variable is send as a second parameter?
This last one is actually the problem: the second parameter that you send is NOT of type
\Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory
but of type
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory
Inject the correct type for the second parameter, confirm that the rest are send as expected, re-compile if you must, and you are done :).
I hope this helps.