How to fix the «Call to a member function getData() on null» error in Smartwave Porto after upgrading Magento to 2.3.1?

bug-fix
porto
magento231
(Dmitry Fedyuk) #1

In Magento 2.3.1 the product.info.details block has changed its class from Magento\Catalog\Block\Product\View\Description to Magento\Catalog\Block\Product\View\Details.

Magento 2.3.0

Magento 2.3.1

The Magento\Catalog\Block\Product\View\Description class has the getProduct() method:

The Magento\Catalog\Block\Product\View\Details class does not have such method.
So any third-party design theme which calls the getProduct() method in the product.info.details block’s template will fail.

How to fix

In the Smartwave Porto’s case you need to patch the file app/design/frontend/Smartwave/porto_child/Magento_Catalog/templates/product/view/details.phtml

Step 1

Replace the line:

$_product = $block->getProduct();

with the following code block:

$_product = \Magento\Framework\App\ObjectManager::getInstance()
	->get(\Magento\Framework\Registry::class)->registry('product');

Step 2

Then replace each $block->getProduct() expression with $_product.

0 Likes