且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

OpenCart 2.2.0.0中类别和产品页面的特定模板

更新时间:2023-11-29 22:59:28

由于Opencart从2.2更改了代码不再起作用的方法,因此您可以像这样修改它:

Since Opencart changed its method from 2.2 that code doesn't work anymore, you can modify it like this:

首先,我们必须知道哪个主题处于活动状态,并将其名称存储在变量中

First we must know which theme is active, store its name in a variable

$config_theme = $this->config->get('config_theme') == 'theme_default' ? 'default' : $this->config->get('config_theme');

然后,我们必须检查是否有一个专门用于当前类别的文件,例如,如果我们位于类别20中,我们将检查category_20.tpl是否存在.

Then we must check if there is a file specially for current category, for example if we are on category 20, we check for category_20.tpl existance.

if (file_exists(DIR_TEMPLATE . $config_theme . '/template/product/category_' . $category_id . '.tpl')) {

如果找到该文件:

$view = 'product/category_' . $category_id;

如果没有这样的文件,请使用原始文件:category.tpl

if there is no such file, use original file: category.tpl

} else {
    $view = 'product/category';
}

根据上述声明加载选定的视图文件.

load selected view file based on above statement.

$this->response->setOutput($this->load->view($view, $data));

结论:

catalog/controller/product/category.php中找到$this->response->setOutput($this->load->view('product/category', $data));并用上面的代码替换,这里是完整代码:

find $this->response->setOutput($this->load->view('product/category', $data)); in catalog/controller/product/category.php and replace it with above codes, here is full code:

$config_theme = $this->config->get('config_theme') == 'theme_default' ? 'default' : $this->config->get('config_theme');
if (file_exists(DIR_TEMPLATE . $config_theme . '/template/product/category_' . $category_id . '.tpl')) {
    $view = 'product/category_' . $category_id;
} else {
    $view = 'product/category';
}
$this->response->setOutput($this->load->view($view, $data));