-
Notifications
You must be signed in to change notification settings - Fork 1
/
restrictaccess.php
47 lines (39 loc) · 1.3 KB
/
restrictaccess.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
class RestrictAccess extends Module
{
public function __construct()
{
$this->name = 'restrictaccess';
$this->tab = 'front_office_features';
$this->version = '1.0.0';
$this->author = 'Iksuri';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Restrict Access to Products and Categories');
$this->description = $this->l('Restricts access to product and category pages for non-logged-in users.');
$this->ps_versions_compliancy = array('min' => '8.0.0', 'max' => _PS_VERSION_);
}
public function install()
{
return parent::install() && $this->registerHook('actionFrontControllerSetMedia');
}
public function uninstall()
{
return parent::uninstall();
}
public function hookActionFrontControllerSetMedia($params)
{
$controller = get_class($this->context->controller);
if (
in_array($controller, ['ProductController', 'CategoryController']) &&
!$this->context->customer->isLogged()
) {
$redirectUrl = $this->context->link->getPageLink('authentication', true);
Tools::redirect($redirectUrl);
}
}
}