1

My shop is built with Prestashop 1.5.6.2.

On a error log file on my server, I can see the following error about 10 times a day : PHP Fatal error: Call to a member function getSubCategories() on null in ../controllers/front/ProductController.php on line 551

On the line 551 of the ProductController.php file is :

 'subCategories' => $this->category->getSubCategories($this->context->language->id, true),

This line is part of the following code :

// various assignements before Hook::exec
    $this->context->smarty->assign(array(
        'path' => $path,
        'category' => $this->category,
        'subCategories' => $this->category->getSubCategories($this->context->language->id, true),
        'id_category_current' => (int)$this->category->id,
        'id_category_parent' => (int)$this->category->id_parent,
        'return_category_name' => Tools::safeOutput($this->category->name),
        'categories' => Category::getHomeCategories($this->context->language->id, true, (int)$this->context->shop->id)
    ));

I am not a developer and I do not know what could lead to this error.

Would you have any idea of what could make this error ?

Thank you in advance for your any reply.

Patrick

user3278588
  • 81
  • 1
  • 12
  • 2
    This error means that `$this->category` is null, check it – Nerea May 04 '17 at 08:11
  • Possible duplicate of [Reference - What does this error mean in PHP?](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – Nico Haase May 20 '19 at 12:07

1 Answers1

0

The error is coming because the $this->category variable is not defined in some cases.
You should add a condition to check that in code (controllers/front/ProductController.php on line 551)

Replace the following

'subCategories' => $this->category->getSubCategories($this->context->language->id, true),

with

'subCategories' => Validate::isLoadedObject($this->category) ? $this->category->getSubCategories($this->context->language->id, true) : array(),

See if the issue is fixed.

fmsthird
  • 1,745
  • 2
  • 17
  • 34
Knowband Plugins
  • 1,297
  • 1
  • 7
  • 6