Specific template for category and product page in OpenCart 2.2.0.0

天大地大妈咪最大 提交于 2019-12-02 11:03:10

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');

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')) {

If found that file:

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

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));

conclusion:

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));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!