Post by adam.skrzynka » Wed Nov 28, 2018 6:12 pm

I would ask for a little help

I would like to create another template for my three categories (category ID 119 / ID 125 / ID 140).

I found one solution for version 2.2.0.0.

find $this->response->setOutput($this->load->view('product/category', $data));
in catalog/controller/product/category.php

and replace it with above codes, here is:

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

Link to the solution:
<https://stackoverflow.com/questions/407 ... 9#53498989>


I created category_119 however, it does not work. I tried to complete this code but nothing works

perhaps I have to complete code by:

* entering the name of my new template (category_119) = but I do not know exactly where to sign

* enter the category ID (119/125/140) = = but I do not know exactly where to sign

* probably enter the name of my template - although I have default - (Default (Default Store Theme)




How to enter correctly, because I try but it fails.

Thank you for your help

Best Regards. Adam.

Newbie

Posts

Joined
Mon Jun 12, 2017 9:57 pm

Post by muldercs » Thu Nov 29, 2018 8:26 am

I changed the template in the category.tpl by just saying


<?php if ($heading_title =='name of your category you want to change') { ?>

Your new template code goes here
<?php } ?>

<?php if ($heading_title <>'name of your category you want to change') { ?>
Your regular category code
<?php } ?>

Newbie

Posts

Joined
Sun Mar 26, 2017 8:28 pm

Post by adam.skrzynka » Thu Nov 29, 2018 5:03 pm

Thank you very much, it works and a much easier solution.

Best Regards.
Adam.

Newbie

Posts

Joined
Mon Jun 12, 2017 9:57 pm

Post by OSWorX » Thu Nov 29, 2018 6:58 pm

Really can't see any benefit in editing the template!
Why?
This 'solution' is limited to one language only.
If you are using more languages, you have to edit always the code inside the template - or adding a if .. then .. else or switch.

The easiest (and most correct, because change is done inside the controller - you should avoid to mix html and php inside any template), is to change this in the controller:

from:

Code: Select all

$this->response->setOutput($this->load->view('product/category', $data));
to:

Code: Select all

$this->response->setOutput($this->load->view('product/category' . $category_info['category_id'], $data));
But this code is limited, because what if you have a category without a custom template?
Then, you should do this instead (check before if exist, otherwise use standard):

Code: Select all

$tpl = 'category_' . $category_info['category_id'];
if( !file_exists( DIR_TEMPLATE . $tpl . '.tpl' ) ) {
	$tpl = 'category';
}

$this->response->setOutput($this->load->view('product/' . $tpl, $data));
Done once, always useable.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by adam.skrzynka » Fri Nov 30, 2018 5:14 pm

Hello, thank you for your help - you're right I actually use two languages and it would be less work for your solution

I have a standard template then just use it:
$this->response->setOutput($this->load->view('product/category' . $category_info['category_id'], $data));

however, now I would have to create a file for each category - if I do not have one - it's not loading standard ( category.tpl )

there is no note that if it does not find the category_xxx = it loads the standard category

how to add it correctly??

Thank you very much for your help

Newbie

Posts

Joined
Mon Jun 12, 2017 9:57 pm

Post by OSWorX » Fri Nov 30, 2018 6:32 pm

As already written:

Code: Select all

$tpl = 'category_' . $category_info['category_id'];
if( !file_exists( DIR_TEMPLATE . $tpl . '.tpl' ) ) {
	$tpl = 'category';
}

$this->response->setOutput($this->load->view('product/' . $tpl, $data));

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by adam.skrzynka » Fri Nov 30, 2018 7:04 pm

still a problem

**** when I exchange for:
$this->response->setOutput($this->load->view('product/category' . $category_info['category_id'], $data));
it works but then I must have an individual template for each category

***** when I exchange for (or insert)
$tpl = 'category_' . $category_info['category_id'];
if( !file_exists( DIR_TEMPLATE . $tpl . '.tpl' ) ) {
$tpl = 'category';
}

$this->response->setOutput($this->load->view('product/' . $tpl, $data));
do not find new categories

***** when I exchange for:

$this->response->setOutput($this->load->view('product/category' . $category_info['category_id'], $data));
$tpl = 'category_' . $category_info['category_id'];
if( !file_exists( DIR_TEMPLATE . $tpl . '.tpl' ) ) {
$tpl = 'category';
}

error.
Parse error: syntax error,

What I'm doing wrong is not working?

Newbie

Posts

Joined
Mon Jun 12, 2017 9:57 pm

Post by OSWorX » Fri Nov 30, 2018 7:47 pm

Sorry. 2.2.x is a totally crap!
Here the tested and working code:

Code: Select all

$tpl = 'category_' . $category_info['category_id'];
if( !file_exists( DIR_TEMPLATE . $this->config->get('theme_default_directory') . '/template/product/' . $tpl . '.tpl' ) ) {
	$tpl = 'category';
}

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by adam.skrzynka » Fri Nov 30, 2018 8:10 pm

works - it's great

thank you very much for the moment of your time and help me.

Best Regards.
Adam.

Newbie

Posts

Joined
Mon Jun 12, 2017 9:57 pm

Post by OSWorX » Mon Dec 03, 2018 4:26 pm

adam.skrzynka wrote:
Fri Nov 30, 2018 8:10 pm
works - it's great

thank you very much for the moment of your time and help me.

Best Regards.
Adam.
Pleasure to help.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria
Who is online

Users browsing this forum: No registered users and 46 guests