Search code examples
phpopencart2.3

Check if a user is logged in or not to OpenCart 2.3.X


I am using latest version of OpenCart "2.3.0.2" and i would like to display a specific div at the home page only for non-logged users. The file i am trying to edit is:catalog/view/theme/default/template/common/home.tpl

The code i already tried is:

<?php if (!$logged) { ?>
//My code here
<?php } ?>

However this code doesnt work as i am getting this error message:

Notice: Undefined variable: logged in \catalog\view\theme\default\template\common\home.tpl on line 3

The weird is that when i use the code above on other files e.g. header.tpl everything works fine. Can anyone point me to the right direction as i am new on MVC structures ?


Solution

  • Ok after a little of research i ended up with the right solution. This might be helpful also for other people.

    So the answer is that i had to define the variable in the home page controller. catalog\controller\common\home.php

    $data['logged'] = $this->customer->isLogged();
    

    Now it work the way it should ;)