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

(Dmitry Fedyuk) #1

In Magento 2.3.1 the 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 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()

Step 2

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

1 Like

(Bhavin Shah) #2

Wow. Thanks! You saved my time.