before opencart 2.2 version


if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category_' . $category_id . '.tpl')) {
    $this->template = $this->config->get('config_template') . '/template/product/category_' . $category_id . '.tpl';
} elseif (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category.tpl')) {
    $this->template = $this->config->get('config_template') . '/template/product/category.tpl';
} else {
    $this->template = 'default/template/product/category.tpl';
}

opencart 2.2 version onwards


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.

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




ONE MORE TYPE EXPLAINATION OF  OPENCART 2.2

 
//$data['header'] = $this->load->controller('common/header');

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category.tpl')) {
if ($category_id == 67) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/category_67.tpl', $data));}
elseif ($category_id == 69) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/category_69.tpl', $data));}
elseif ($category_id == 70) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/category_70.tpl', $data));}
elseif ($category_id == 71) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/category_71.tpl', $data));}
else{
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/category.tpl', $data));}
/*if ($category_id == 69) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/category_69.tpl', $data));}
else{
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/category.tpl', $data));}*/
}
else {
$this->response->setOutput($this->load->view('default/template/product/category.tpl', $data));
}

} else {
$url = '';

Comments

Popular posts from this blog

Script For Login, Logout and View Using PHP, MySQL and Bootstrap

PHP Ajax Login Validation Tutorial

Insert CheckBox and Radio button Data in MySQL Database Using PHP