0

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

2 Answers 2

1

$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
0

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.