magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.56k stars 9.32k forks source link

$block->getProduct() in catalog product view template failed after upgrading from 2.3.0 to 2.3.1 #22036

Closed Hailong closed 4 years ago

Hailong commented 5 years ago

Preconditions (*)

  1. Magento 2.3.1
  2. Porto theme for Magento 2.3.x

Steps to reproduce (*)

  1. Install Magento 2.3.1
  2. Install Porto theme

Expected result (*)

  1. Product page renders with no problem

Actual result (*)

  1. Product page doesn't render

The problem is a new block class introduced in 2.3.1, while it doesn't provide the getProduct() method. It's not backward compatible. Created the pull request as well.

Hailong commented 5 years ago

The PR#22034 request has been approved, but I'm not sure how to update the status of this bug.

magento-engcom-team commented 5 years ago

:white_check_mark: Confirmed by @shikhamis11 Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-98977 were created

Issue Available: @shikhamis11, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

panteliskopsias commented 5 years ago

Hello, same issue to me too. But i think that the error is at
at app/design/frontend/Smartwave/porto/Magento_Catalog/templates/product/view/details.phtml on line 18

$page_type = $_product->getData('product_page_type'); if(!$page_type) $page_type = isset($_config['product_page_type'])?$_config['product_page_type']:'';

Hailong commented 5 years ago

Hi @panteliskopsias , if the $_product returned from Line 17 is NULL, then the null object reference error would be reported on Line 18. I'm not sure if that is the reason you see the error on Line 18.

panteliskopsias commented 5 years ago

Is it an easy way to fix it at details.phtml?

Hailong commented 5 years ago

I got a fix at https://github.com/magento/magento2/pull/22034/files, please take a look.

panteliskopsias commented 5 years ago

i have seen it, but i have not app/code/Magento/Catalog/Block/Product/View/Details.php

Hailong commented 5 years ago

oh, it should be under the vendor directory if you installed it with composer.

panteliskopsias commented 5 years ago

Yes... i had installed it with composer. The fix work! Thank you!

Hailong commented 5 years ago

Sounds good. I see a document about how to apply a patch, but I have not tried it yet. I installed my instance with a cloned repository which takes the fix.

abhi-ranosys commented 5 years ago

"I am working on this at #dmcdindia19”

magento-engcom-team commented 5 years ago

@abhi-ranosys thank you for joining. Please accept team invitation here and self-assign the issue.

abhi-ranosys commented 5 years ago

I am working on this at #dmcdindia19

m2-assistant[bot] commented 5 years ago

Hi @abhi-ranosys. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

abhisekumar commented 5 years ago

oh, it should be under the vendor directory if you installed it with composer.

Yes its works .. Direct path will be /vendor/magento/module-catalog/Block/Product/View

liquidia commented 5 years ago

same issue when I try to fix it with given solution .. it gives me following error `1 exception(s): Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Magento\Catalog\Block\Product\View\Details\Interceptor Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Magento\Catalog\Block\Product\View\Details\Interceptor

#1 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() called at [vendor/magento/framework/ObjectManager/ObjectManager.php:56]
#2 Magento\Framework\ObjectManager\ObjectManager->create() called at [vendor/magento/framework/View/Element/BlockFactory.php:46]
#3 Magento\Framework\View\Element\BlockFactory->createBlock() called at [vendor/magento/framework/View/Layout/Generator/Block.php:268]
#4 Magento\Framework\View\Layout\Generator\Block->getBlockInstance() called at [vendor/magento/framework/View/Layout/Generator/Block.php:248]
#5 Magento\Framework\View\Layout\Generator\Block->createBlock() called at [vendor/magento/framework/View/Layout/Generator/Block.php:226]
#6 Magento\Framework\View\Layout\Generator\Block->generateBlock() called at [vendor/magento/framework/View/Layout/Generator/Block.php:134]
#7 Magento\Framework\View\Layout\Generator\Block->process() called at [vendor/magento/framework/View/Layout/GeneratorPool.php:81]
#8 Magento\Framework\View\Layout\GeneratorPool->process() called at [vendor/magento/framework/View/Layout.php:343]
#9 Magento\Framework\View\Layout->generateElements() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:89]
#10 Magento\Framework\View\Layout\Interceptor->generateElements() called at [vendor/magento/framework/View/Layout/Builder.php:129]
#11 Magento\Framework\View\Layout\Builder->generateLayoutBlocks() called at [vendor/magento/framework/View/Page/Builder.php:55]
#12 Magento\Framework\View\Page\Builder->generateLayoutBlocks() called at [vendor/magento/framework/View/Layout/Builder.php:65]
#13 Magento\Framework\View\Layout\Builder->build() called at [vendor/magento/framework/View/Page/Config.php:224]
#14 Magento\Framework\View\Page\Config->build() called at [vendor/magento/framework/View/Page/Config.php:237]
#15 Magento\Framework\View\Page\Config->publicBuild() called at [vendor/magento/framework/View/Result/Page.php:242]
#16 Magento\Framework\View\Result\Page->render() called at [vendor/magento/framework/View/Result/Layout.php:171]
#17 Magento\Framework\View\Result\Layout->renderResult() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#18 Magento\Framework\View\Result\Page\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#19 Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#20 Magento\Framework\View\Result\Page\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/View/Result/Page/Interceptor.php:130]
#21 Magento\Framework\View\Result\Page\Interceptor->renderResult() called at [vendor/magento/framework/App/Http.php:141]
#22 Magento\Framework\App\Http->launch() called at [generated/code/Magento/Framework/App/Http/Interceptor.php:24]
#23 Magento\Framework\App\Http\Interceptor->launch() called at [vendor/magento/framework/App/Bootstrap.php:261]
#24 Magento\Framework\App\Bootstrap->run() called at [pub/index.php:40]
` Any help?
LiamTrioTech commented 4 years ago

Think I'm seeing this issue on Magento 2.3.5 after upgrading from 2.2.0.

Fatal error: Uncaught Error: Call to a member function getSomeAttribute() on null in /var/www/html/app/design/frontend/Alothemes/default/Magento_Catalog/templates/product/view/details.phtml:15 Stack trace: #0 /var/www/html/vendor/magento/framework/View/TemplateEngine/Php.php(59): include() #1 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Catalog\Block\Product\View\Details\Interceptor), '/var/www/html/a...', Array) #2 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\TemplateEngine\Php\Interceptor->___callParent('render', Array) #3 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\TemplateEngine\Php\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Catalog\Block\Product\View\Details\Interceptor), '/var/www/html/a...', Array) #4 /var/www/html/generated/code/Magento/Framework/View/TemplateEngine/Php/Interceptor.php(26): Magento\Fr in /var/www/html/app/design/frontend/Alothemes/default/Magento_Catalog/templates/product/view/details.phtml on line 15

$block->getProduct() is null.

Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Magento\Catalog\Block\Product\View\Details\Interceptor
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento cache:flush
chown -R www-data:www-data .

Note: After applying the fix from https://github.com/magento/magento2/pull/22034/files it gives another error. But after I run upgrade, di compile it fixes it. Thanks very much.

Is there a patch for this that we can apply with composer or do I just have to upgrade to 2.4.x?

gabrieldagama commented 4 years ago

We are sorry that you faced a backwards-incompatible change since that was released some time ago, any action now would create other problems. Closing this issue as there is not a real fix for it.