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

Table of Content

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/magento2/blob/2.3.0/app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml#L139-L139


Magento 2.3.1
magento/magento2/blob/2.3.1/app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml#L139-L139

The Magento\Catalog\Block\Product\View\Description class has the getProduct() method:
magento/magento2/blob/2.3.0/app/code/Magento/Catalog/Block/Product/View/Description.php#L48-L57
/**
* @return Product
*/
public function getProduct()
{
if (!$this->_product) {
$this->_product = $this->_coreRegistry->registry(‘product’);
}
return $this->_product;
}
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.

Залишити відповідь

Ваша e-mail адреса не оприлюднюватиметься. Обов’язкові поля позначені *

Navigation