Solved: Fatal Error: Uncaught Error: Call to a Member Function getSectionNames() After Upgrading Magento 2
Facing a “Fatal error: Uncaught Error: Call to a member function getSectionNames()” after Magento 2 upgrade? Read this blog post to find the complete solution.
Adobe releases several upgrades throughout the year, fixing various issues and adding new features to the Magento platform. Major upgrades are released every six-twelve months, with minor upgrades and patches in between. These updates introduce new features and functionalities, known bug fixes, and security improvements.
Sometimes, these new feature introductions may conflict with the existing customizations in the store and produce errors. One such error after upgrading Magento version is the “Fatal error: Uncaught Error: Call to a member function getSectionNames()”
I recently faced the same issue while upgrading a client’s store from Magento 2.3.3 to the 2.4.5 version. On further investigation, I found the root cause of the problem.
Let’s understand the cause & the method to solve the issue.
Where is the Problem?
Magento 2.3.4 release has introduced a new argument named sectionNamesProvider
tag for the frontend blocks. This means Magento assumes a sectionNamesProvider argument for every instance of the block. If you use a custom theme or have overridden the default.xml, you may encounter the ‘Fatal error: Uncaught Error: Call to a member function getSectionNames()’ error.
The solution to ‘Fatal error: Uncaught Error: Call to a member function getSectionNames()’
The solution to getting rid of the error in Magento 2 is to find the XML file that is being called by the custom PHTML file and add the argument tag.
For example, in my case, the error read:
Fatal error: Uncaught Error: Call to a member function getSectionNames() on /vendor/magento/module-customer/view/frontend/templates/js/section-config.phtml:20
Therefore, the section-config.phml
file was causing the error here.
Here, we need to find the XML file where this PHTML file is called and add the argument tag as per the default.xml
file
1 2 3 4 5 6 |
<block name="customer.section.config" class="Magento\Customer\Block\SectionConfig" template="Magento_Customer::js/section-config.phtml"> <arguments> <argument name="sectionNamesProvider" xsi:type="object">Magento\Customer\Block\SectionNamesProvider</argument> </arguments> </block> |
and the problem will be solved!
Solution to a similar error:
I hope the above method will help solve the issue.
In case you still have any doubts, feel free to comment. 💭
I’d be happy to help you.
Do not forget to share this solution with your developer friends! 😃
Thanks for reading. 🍀
Prev
First Ever Digital Marketing Meetup in Bhavnagar by Meetanshi
Monthly Recap: Meetanshi Launches and Updates – February 2023
Next