How solve this issue? Error log (PHP Fatal error: Uncaught Error: Call to a member function getName() on null in) is for line 4: $page_title = $brand->getName();
protected function _prepareLayout()
{
$brand = $this->getCurrentBrand();
$page_title = $brand->getName();
$meta_description = $brand->getMetaDescription();
$meta_keywords = $brand->getMetaKeywords();
$this->_addBreadcrumbs();
if($page_title){
$this->pageConfig->getTitle()->set($page_title);
}
if($meta_keywords){
$this->pageConfig->setKeywords($meta_keywords);
}
if($meta_description){
$this->pageConfig->setDescription($meta_description);
}
return parent::_prepareLayout();
}
asked May 30, 2020 at 23:06
Peter
4511 gold badge6 silver badges18 bronze badges
2 Answers 2
$this->getCurrentBrand() is returning NULL.
You can solve the issue by ensuring the data is set before the layout is prepared.
answered May 31, 2020 at 0:10
Shapeshifter
2721 silver badge10 bronze badges
You can add code on your theme Magento_LayeredNavigation/templates/layer File.
Previous Code
$brandBlock = $block->getLayout()->createBlock('Rokanthemes\Brand\Block\Brand\View');
$_brand = $brandBlock->getCurrentBrand();
Updated Code
if($this->getRequest()->getControllerName() == 'brand' && $this->getRequest()->getRouteName() == 'rokanthemesbrand') {
$brandBlock = $block->getLayout()->createBlock('Rokanthemes\Brand\Block\Brand\View');
$_brand = $brandBlock->getCurrentBrand();
}
answered Nov 16, 2021 at 14:14
Meet Shekhat
3811 silver badge9 bronze badges
default