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();
}

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.

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();
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.