Question

We're seeing frequent (every minute) entries in system.log like this:

2017-05-26T08:48:22+00:00 ERR (3): Notice: Trying to get property of non-object  in /chroot/home/<domain>/html/app/code/community/Creare/CreareSeoCore/Model/Observer.php on line 272
2017-05-26T08:48:22+00:00 ERR (3): Notice: Trying to get property of non-object  in /chroot/home/<domain>/html/app/code/community/Creare/CreareSeoCore/Model/Observer.php on line 279
2017-05-26T08:48:22+00:00 ERR (3): Notice: Trying to get property of non-object  in /chroot/home/<domain>/html/app/code/community/Creare/CreareSeoCore/Model/Observer.php on line 279

The relevant section of observer.php is:

public function getTitle()
{
    $pagetype = $this->metaHelper()->getPageType(); 
    if ($pagetype && $pagetype->_code != "cms")
    {
        if (!$pagetype->_model->getMetaTitle())
        {
            $this->_data['title'] = $this->setConfigTitle($pagetype->_code);
        } else {
            $this->_data['title'] = $pagetype->_model->getMetaTitle();
        }
    } else if($pagetype->_code == "cms"){       // line 272
        $this->_data['title'] = $pagetype->_model->getTitle();
    }

    if (empty($this->_data['title'])) {

        // check if it's a category or product and default to name.
        if($pagetype->_code == "category" || $pagetype->_code == "product"){    //line 279
            $this->_data['title'] = $pagetype->_model->getName();
        } else {
            $this->_data['title'] = $this->getDefaultTitle();
        }
    }



    return htmlspecialchars(html_entity_decode(trim($this->_data['title']), ENT_QUOTES, 'UTF-8'));
}

Any ideas what's happening?

Was it helpful?

Solution

You are getting errors because the code is trying to get properties of an object even if its not set. Above code should look something like this.

public function getTitle()
{
    $pagetype = $this->metaHelper()->getPageType(); 
    if ($pagetype && $pagetype->_code != "cms")
    {
        if (!$pagetype->_model->getMetaTitle())
        {
            $this->_data['title'] = $this->setConfigTitle($pagetype->_code);
        } else {
            $this->_data['title'] = $pagetype->_model->getMetaTitle();
        }
    } else if($pagetype && $pagetype->_code == "cms"){       // line 272 // Added condition to check if $pagetype is set
        $this->_data['title'] = $pagetype->_model->getTitle();
    }

    if (empty($this->_data['title'])) {

        // check if it's a category or product and default to name.
        if($pagetype && ($pagetype->_code == "category" || $pagetype->_code == "product")){    //line 279 // Added condition to check if $pagetype is set
            $this->_data['title'] = $pagetype->_model->getName();
        } else {
            $this->_data['title'] = $this->getDefaultTitle();
        }
    }

    return htmlspecialchars(html_entity_decode(trim($this->_data['title']), ENT_QUOTES, 'UTF-8'));
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top