Bobcares

“Uncaught Error: Call to a Member Function getSectionNames()” After Magento 2 Upgrade

PDF Header PDF Footer

Resolve the “Uncaught Error: Call to a Member Function getSectionNames()” after Magento 2 upgrade. Our Magento Support Team is here to help.

“Uncaught Error: Call to a Member Function getSectionNames()” After Magento 2 Upgrade

Did you know that upgrading Magento 2 can sometimes trigger unexpected errors due to compatibility issues between custom themes, extensions, and changes in Magento’s core files?

One such standard error is:

Uncaught Error: Call to a member function getSectionNames()

This issue is widespread when upgrading to versions such as 2.3.4, 2.3.6, or 2.4.5, where Magento introduced breaking changes in layout XML structures and class methods.

Why This Error Occurs

In Magento 2.3.4, a new XML argument called `sectionNamesProvider` was introduced for certain frontend blocks. This means Magento expects the `sectionNamesProvider` argument for every instance of these blocks.

If a custom theme or overridden `default.xml` file does not include this argument, Magento will throw the fatal error:

Fatal error: Uncaught Error: Call to a member function getSectionNames()

Sometimes, Magento 2 upgrades also cause issues like “Cannot instantiate interface”, which happens due to dependency injection mismatches.

Example Scenario

For instance, we might see this error in:

/vendor/magento/module-customer/view/frontend/templates/js/section-config.phtml:20

Here, the issue is that the `section-config.phtml` file is being called without the required `sectionNamesProvider` argument in its corresponding layout XML.

Solution 1 – Add the Missing Argument in the XML File

Identify the XML file calling the problematic PHTML file and add the `sectionNamesProvider` argument as shown below:


<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>

Once this argument is added, the error should be resolved.

Solution 2 – Update Overridden `default.xml` in Custom Theme

If the theme overrides vendor/magento/module-customer/view/frontend/layout/default.xml, it may be missing the new `sectionNamesProvider` argument. Add it as follows:


<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>

This ensures compatibility with Magento’s updated XML structure.

How to Fix `isClearShoppingCartEnabled() on null` error

Another error that may occur after upgrading Magento 2 is:

Error Call to a member function isClearShoppingCartEnabled() on null

  1. First, search for XML files where the following is used:
    Magento_Checkout::cart/form.phtml
  2. Then, add the missing View Model argument by going inside the `block` tag and adding:

    <arguments>
    <argument name="view_model" xsi_type="object">
    Magento\Checkout\ViewModel\Cart
    </argument>
    </arguments>
  3. Then, save changes, clear the cache, and test the checkout page.

“Uncaught Error: Call to a Member Function getSectionNames()” After Magento 2 Upgrade

Other Magento 2 Upgrade Errors Worth Checking

During upgrades, other errors might also surface, such as:

Checking logs and reviewing overridden theme files can help catch these problems early.

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

This error occurs when custom themes or extensions are not updated to match Magento’s latest layout XML structure. By adding the missing `sectionNamesProvider` or `view_model` arguments, we can restore functionality after an upgrade.

In brief, our Support Experts demonstrated how to fix the “Uncaught Error: Call to a Member Function getSectionNames()” after Magento 2 Upgrade.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Get featured on the Bobcares blog and share your expertise with a global tech audience.

WRITE FOR US
server management

Spend time on your business, not on your servers.

TALK TO US

Or click here to learn more.

Speed issues driving customers away?
We’ve got your back!