Vin_fugen
Vin_fugen

Reputation: 581

Opencart display module only if user logged in

Is there any way in opencart to display sidebar modules only for logged in users ?

Upvotes: 1

Views: 2124

Answers (2)

Vin_fugen
Vin_fugen

Reputation: 581

Thanks for your quick reply. I found one simple solution.

Gone to my module controller

wrapped $this->render(); with if(!$this->customer->isLogged()) { $this->render(); }

It's working great.

Upvotes: 1

shadyyx
shadyyx

Reputation: 16065

Of course and there is also a simple collution!

Open up e.g. left column controller (catalog/controller/common/column_left.php) and after the line:

protected function index() {

add this condition (only with opening bracket):

    if($this->customer->isLogged()) {

now find the line

    $this->render();

and before it add this:

    } else {
        $this->data['modules'] = array();
    }

So the final code should look like this:

<?php  
class ControllerCommonColumnLeft extends Controller {
    protected function index() {
        if($this->customer->isLogged()) {
            // ... all the previous code up to the render() call
        } else {
            $this->data['modules'] = array();
        }

        $this->render();
    }
}

Now do the same in column_right.php, content_bottom.php and content_top.php and You should be done ;-)

EDIT: One may also want to edit the concrete module controllers and add the condition there but this wouldn't be as simple and has other implications - there still would be a DB queries to gather all the available modules. Within my solution besides it's simplicity there is also a fact that for unlogged user no DB calls for modules will be done at all..

Upvotes: 1

Related Questions