-
Notifications
You must be signed in to change notification settings - Fork 3
/
rocketoverridecmscattpl.php
93 lines (74 loc) · 2.33 KB
/
rocketoverridecmscattpl.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* @author Prestarocket <contact@prestarocket.com>
*/
if (!defined('_PS_VERSION_')) {
exit;
}
class rocketoverridecmscattpl extends Module
{
public function __construct()
{
$this->name = 'rocketoverridecmscattpl';
$this->tab = 'administration';
$this->version = '1.0.0';
$this->author = 'Prestarocket';
$this->bootstrap = true;
parent::__construct();
$this->extension = ".tpl";
$this->displayName = $this->l('Override tpl cms category in your theme');
$this->description = $this->l('Override tpl cms category with template hierarchy');
}
public function install()
{
return parent::install() && $this->registerHook('displayOverrideTemplate');
}
public function uninstall()
{
return parent::uninstall();
}
public function getContent()
{
return 'Module by <a href="https://prestarocket.com/" target="_blank" rel="">Prestarocket</a>';
}
/**
* @param array $params
* @return mixed|string
*/
public function hookDisplayOverrideTemplate(array $params)
{
$template_file = $params['template_file'];
if($template_file === "cms/category"){
$id = $params['controller']->cms_category->id;
return $this->getTemplateCmsCategory($id,$params['locale']);
}
}
/**
*
* @param $id
* @param $locale
* @return mixed|string
*/
public function getTemplateCmsCategory($id, $locale)
{
$locale = (Validate::isLocale($locale)) ? $locale : '';
$templates = array(
'cms/category-' . $id,
'cms/category'
);
$directories = $this->context->smarty->getTemplateDir();
foreach ($directories as $dir) {
foreach ($templates as $tpl) {
if (!empty($locale) && is_file($dir . $locale . DIRECTORY_SEPARATOR . $tpl . $this->extension)) {
return $locale . DIRECTORY_SEPARATOR . $tpl . $this->extension;
}
if (is_file($dir . $tpl . $this->extension)) {
return $tpl . $this->extension;
}
if (is_file($dir . $tpl) && false !== strpos($tpl, $this->extension)) {
return $tpl;
}
}
}
}
}