Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Call to a member function getUrl() on null in vendor/magento/module-catalog/view/frontend/templates/category/image.phtml:21 #30753

Closed
primafair opened this issue Nov 2, 2020 · 15 comments

Comments

@primafair
Copy link

primafair commented Nov 2, 2020

Preconditions (*)

the category pages can no longer be accessed after upgrading from Magento 2.3.5 to Magento 2.4.1, we get the following message

Has anyone else encountered the problem? How do I fix this bug? Thanks a lot

Steps to reproduce (*)

  1. Update from Magento 2.3.5 to 2.4.1

Expected result (*)

  1. The category pages only show an error message

Actual result (*)

Error: Call to a member function getUrl() on null in vendor/magento/module-catalog/view/frontend/templates/category/image.phtml:21 Stack trace: #0 vendor/magento/framework/View/TemplateEngine/Php.php(71): include() #1 vendor/magento/framework/View/Element/Template.php(273): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Catalog\Block\Category\View), '/home/stubenbl/...', Array) #2 vendor/magento/framework/View/Element/Template.php(303): Magento\Framework\View\Element\Template->fetchView('/home/stubenbl/...') #3 vendor/magento/framework/View/Element/AbstractBlock.php(1111): Magento\Framework\View\Element\Template->_toHtml() #4 vendor/magento/framework/View/Element/AbstractBlock.php(1115): Magento\Framework\View\Element\AbstractBlock->Magento\Framework\View\Element{closure}() #5 vendor/magento/framework/View/Element/AbstractBlock.php(675): Magento\Framework\View\Element\AbstractBlock->_loadCache() #6 vendor/magento/framework/View/Layout.php(566): Magento\Framework\View\Element\AbstractBlock->toHtml() #7 vendor/magento/framework/View/Layout.php(542): Magento\Framework\View\Layout->_renderBlock('category.image') #8 generated/code/Magento/Framework/View/Layout/Interceptor.php(149): Magento\Framework\View\Layout->renderNonCachedElement('category.image') #9 vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('category.image') #10 generated/code/Magento/Framework/View/Layout/Interceptor.php(140): Magento\Framework\View\Layout->renderElement('category.image', false) #11 vendor/magento/framework/View/Layout.php(594): Magento\Framework\View\Layout\Interceptor->renderElement('category.image', false) #12 vendor/magento/framework/View/Layout.php(544): Magento\Framework\View\Layout->_renderContainer('category.view.c...', false) #13 generated/code/Magento/Framework/View/Layout/Interceptor.php(149): Magento\Framework\View\Layout->renderNonCachedElement('category.view.c...') #14 vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('category.view.c...') #15 generated/code/Magento/Framework/View/Layout/Interceptor.php(140): Magento\Framework\View\Layout->renderElement('category.view.c...', false) #16 vendor/magento/framework/View/Layout.php(594): Magento\Framework\View\Layout\Interceptor->renderElement('category.view.c...', false) #17 vendor/magento/framework/View/Layout.php(544): Magento\Framework\View\Layout->_renderContainer('columns.top', false) #18 generated/code/Magento/Framework/View/Layout/Interceptor.php(149): Magento\Framework\View\Layout->renderNonCachedElement('columns.top') #19 vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('columns.top') #20 generated/code/Magento/Framework/View/Layout/Interceptor.php(140): Magento\Framework\View\Layout->renderElement('columns.top', false) #21 vendor/magento/framework/View/Layout.php(594): Magento\Framework\View\Layout\Interceptor->renderElement('columns.top', false) #22 vendor/magento/framework/View/Layout.php(544): Magento\Framework\View\Layout->_renderContainer('main.content', false) #23 generated/code/Magento/Framework/View/Layout/Interceptor.php(149): Magento\Framework\View\Layout->renderNonCachedElement('main.content') #24 vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('main.content') #25 generated/code/Magento/Framework/View/Layout/Interceptor.php(140): Magento\Framework\View\Layout->renderElement('main.content', false) #26 vendor/magento/framework/View/Layout.php(594): Magento\Framework\View\Layout\Interceptor->renderElement('main.content', false) #27 vendor/magento/framework/View/Layout.php(544): Magento\Framework\View\Layout->_renderContainer('page.wrapper', false) #28 generated/code/Magento/Framework/View/Layout/Interceptor.php(149): Magento\Framework\View\Layout->renderNonCachedElement('page.wrapper') #29 vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('page.wrapper') #30 generated/code/Magento/Framework/View/Layout/Interceptor.php(140): Magento\Framework\View\Layout->renderElement('page.wrapper', false) #31 vendor/magento/framework/View/Layout.php(594): Magento\Framework\View\Layout\Interceptor->renderElement('page.wrapper', false) #32 vendor/magento/framework/View/Layout.php(544): Magento\Framework\View\Layout->_renderContainer('root', false) #33 generated/code/Magento/Framework/View/Layout/Interceptor.php(149): Magento\Framework\View\Layout->renderNonCachedElement('root') #34 vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('root') #35 generated/code/Magento/Framework/View/Layout/Interceptor.php(140): Magento\Framework\View\Layout->renderElement('root', true) #36 vendor/magento/framework/View/Layout.php(963): Magento\Framework\View\Layout\Interceptor->renderElement('root') #37 vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Layout->getOutput() #38 vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\Layout\Interceptor->___callParent('getOutput', Array) #39 vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Layout\Interceptor->Magento\Framework\Interception{closure}() #40 generated/code/Magento/Framework/View/Layout/Interceptor.php(347): Magento\Framework\View\Layout\Interceptor->___callPlugins('getOutput', Array, Array) #41 vendor/magento/framework/View/Result/Page.php(258): Magento\Framework\View\Layout\Interceptor->getOutput() #42 vendor/magento/framework/View/Result/Layout.php(171): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor)) #43 vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor)) #44 vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\Result\Page\Interceptor->___callParent('renderResult', Array) #45 vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception{closure}(Object(Magento\Framework\App\Response\Http\Interceptor)) #46 generated/code/Magento/Framework/View/Result/Page/Interceptor.php(95): Magento\Framework\View\Result\Page\Interceptor->___callPlugins('renderResult', Array, Array) #47 vendor/magento/framework/App/Http.php(120): Magento\Framework\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor)) #48 generated/code/Magento/Framework/App/Http/Interceptor.php(23): Magento\Framework\App\Http->launch() #49 vendor/magento/framework/App/Bootstrap.php(263): Magento\Framework\App\Http\Interceptor->launch() #50 index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor)) #51 {main}

@m2-assistant
Copy link

m2-assistant bot commented Nov 2, 2020

Hi @primafair. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

Please, add a comment to assign the issue: @magento I am working on this


⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@primafair primafair changed the title Error: Call to a member function getUrl() on null in /Magento_Catalog/templates/category/image.phtml:21 Error: Call to a member function getUrl() on null in vendor/magento/module-catalog/view/frontend/templates/category/image.phtml:21 Nov 2, 2020
@mrtuvn
Copy link
Contributor

mrtuvn commented Nov 3, 2020

Or maybe this is bug but no body notice or can reproduce exactly scenario
@primafair
If you updated to 2.4.1 you also need this patch
https://magento.com/tech-resources/download#tab-36
MC-38509 Create New Customer Account patch
You should update more details for easier check problem. Such as do you use custom theme or not ? any customise modules 3rd-party. This issue happen in only some category when visit or issue in all category

@hostep
Copy link
Contributor

hostep commented Nov 3, 2020

@primafair: you're probably using the Magento_Catalog::category/image.phtml in an xml file in your custom theme and that block doesn't have the images as an argument.
This was changed in Magento 2.3.6 and 2.4.0 apparently.

So adjust your xml like it was done in 6fc1e3c#diff-e83ea1b571c022bdf3362f880222c12bf800ecbcbbeb6765b8f327754f8b9a33 and you should be up and running again.

Magento architects are currently discussing such issues and are figuring out if these can be seen as backwards incompatible. So when they decide that these kind of changes are backwards incompatible, they will no longer allow such changes to be made in the future.

@mrtuvn
Copy link
Contributor

mrtuvn commented Nov 4, 2020

seem a lot of customise theme will break after this

@pixel-paul
Copy link

I encountered this going from 2.3.5 to 2.3.6

@christianbookpwood
Copy link

I can confirm that I'm having this issue after upgrading from CE 2.3.4 to 2.4.1.
I can also confirm that applying the fix described by @hostep to my custom theme fixed the issue for me.

@vandana-gupta1
Copy link

Even I am facing the same issue after upgrading from 2.3.5 to 2.4.1
I tried the step suggested by @hostep to my custom theme, still no luck.
Any other suggestion would help me.

@mrtuvn
Copy link
Contributor

mrtuvn commented Dec 23, 2020

You should check file view.xml in folder etc of your theme. Maybe you miss some variables that cause problem

@zexperto
Copy link

zexperto commented Jan 29, 2021

@primafair: you're probably using the Magento_Catalog::category/image.phtml in an xml file in your custom theme and that block doesn't have the images as an argument.
This was changed in Magento 2.3.6 and 2.4.0 apparently.

So adjust your xml like it was done in 6fc1e3c#diff-e83ea1b571c022bdf3362f880222c12bf800ecbcbbeb6765b8f327754f8b9a33 and you should be up and running again.

Magento architects are currently discussing such issues and are figuring out if these can be seen as backwards incompatible. So when they decide that these kind of changes are backwards incompatible, they will no longer allow such changes to be made in the future.

I confirm that this solution is working well, but I do not suggest to roll back Magento changes but it is better (as you said )to fix the xml file by adding those two arguments , this is worked for me

@stale
Copy link

stale bot commented Apr 16, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

@stale stale bot added the stale issue label Apr 16, 2021
@dverkade
Copy link
Member

Posting a comment. Issues should not be automatically closed.

@stale stale bot removed the stale issue label Apr 18, 2021
@tuyennn
Copy link
Member

tuyennn commented Apr 27, 2021

@dverkade Try @hostep fix, this is exactly what are you looking for, this issue should be closed

@hostep
Copy link
Contributor

hostep commented Apr 27, 2021

Indeed, this issue should be closed, can somebody do that please, maybe @ihor-sviziev? Thanks! 🙂

@ihor-sviziev
Copy link
Contributor

Closing this issue, as we have a solution in #30753 (comment)

@davidduong90
Copy link

davidduong90 commented Aug 5, 2022

I found the issue is our theme. Our theme follows the old standard, they don't have an argument when they call the image.
https://prnt.sc/f9C5C5u6rQz5

Magento 2.4.4 try to add some arguments when they call the image in category pages.
https://prnt.sc/SnzLFqb827GY

So, I just change the code to call the image in the file app/design/frontend/Alothemes/default/Magento_Catalog/layout/catalog_category_view.xml

From:
<block class="Magento\Catalog\Block\Category\View" name="category.image" template="Magento_Catalog::category/image.phtml"/>

To:

<block class="Magento\Catalog\Block\Category\View" name="category.image" template="Magento_Catalog::category/image.phtml">
    <arguments>
        <argument name="image" xsi:type="object">Magento\Catalog\ViewModel\Category\Image</argument>
        <argument name="output" xsi:type="object">Magento\Catalog\ViewModel\Category\Output</argument>
    </arguments>
</block>

Note: change Alothemes/default to your theme. Hope it helps someone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests