Post by harlomedia » Sat Mar 28, 2009 3:26 am

Hi guys, just curious about how to customize the page for a particular category.

For instance, "category/path/27" "category/path/26" and "category/path/24" should all be controlled by category.tpl

How do I set up a file to control just "category/path/25" ?

Thanks for any help. Let me know if I need to clarify more.

Newbie

Posts

Joined
Sat Mar 28, 2009 3:21 am

Post by harlomedia » Sat Mar 28, 2009 4:24 am

I just noticed that someone asked a similar question below. Sorry to post it again but that one didn't make sense anyway :P .

Newbie

Posts

Joined
Sat Mar 28, 2009 3:21 am

Post by Qphoria » Sat Mar 28, 2009 5:22 am

I'll show you a very easy and cool dynamic way to do this:

Edit: catalog/controller/product/category.php

Find:

Code: Select all

$this->template = $this->config->get('config_template') . 'product/category.tpl';
Replace with:

Code: Select all

$this->template = $this->config->get('config_template') . 'product/category_' . $this->request->get['path'] . '.tpl';
if (!file_exists(DIR_TEMPLATE . $this->template)) {
	$this->template = $this->config->get('config_template') . 'product/category.tpl';
}
Now, anytime you want a custom category template. Create a clone of the category.tpl file using the category path as part of the name. For example:

category_25.tpl
category_25_38.tpl
category_25_38_72.tpl
etc.

The code will first check for the existence of an override file. If there is one it will use it. If there is none for that category, then it will default to the original file.

This can be done for virtually any file. Products, information, etc.

OpenCart 2.0.x Mod Update Info

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by harlomedia » Sat Mar 28, 2009 5:47 am

Uh oh... I do not have any folders inside of catalog/controller/

I checked it against the latest download of OpenCart. I'm assuming I have a slightly older version of OpenCart. Can't find the version listed anywhere, though.

Any chance there's a way to do this with the older versions of OpenCart?

Newbie

Posts

Joined
Sat Mar 28, 2009 3:21 am

Post by harlomedia » Sat Mar 28, 2009 6:52 am

And now I see the OpenCart 0.x part of the forum and it's locked. I'm scattered today.

Assuming it's now unsupported. Is there documentation on how to upgrade?

Newbie

Posts

Joined
Sat Mar 28, 2009 3:21 am

Post by Qphoria » Sat Mar 28, 2009 7:52 am

OpenCart 0.x is now its own cart system with its own forums:
OpenCart Zero
It is very much alive, and yes a similar feature can be accomplished with 0.x as well:
Posted here

OpenCart 2.0.x Mod Update Info

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by harlomedia » Tue Mar 31, 2009 12:04 am

Thank you! I really appreciate the help.

Newbie

Posts

Joined
Sat Mar 28, 2009 3:21 am

Post by paulcortez » Tue Mar 31, 2009 11:59 pm

Hi Q,
Sorry i'm confused. What is the difference between opencart and opencart zero?
Qphoria wrote:OpenCart 0.x is now its own cart system with its own forums:
OpenCart Zero
It is very much alive, and yes a similar feature can be accomplished with 0.x as well:
Posted here
I already installed opencart in my server ( i like it so far :) ) and maybe opencart zero has a little bit more advantage than this one.

Newbie

Posts

Joined
Sun Mar 22, 2009 9:24 pm

Post by Qphoria » Wed Apr 01, 2009 12:06 am

OpenCart version 0.x was the original version of OpenCart. After the release of OpenCart 1.x, it was deemed that the 2 projects were so different that they needed to progress their own separate ways.

OpenCart Zero, just refers to the 0.x branch. It's been around a bit longer so it has a leg up on stability, but both carts have different features, so it comes down to what you are looking for in a cart. I am currently ramping up for a new v0.8 release of OpenCart Zero within a week (hopefully) that will have a whole new assortment of features, improvements (imo), and a new default look.

OpenCart 2.0.x Mod Update Info

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by paulcortez » Wed Apr 01, 2009 12:30 am

Thankz a lot Q. That's a relief. hehe :) I thought opencart v1.x will loosing its support. I'm still getting my self acquainted with this system and first time to accept this online shopping project. Thankz again Q. I'll post the URL of my project here when i'm done and open to public.

I made some changes on the template and i'm glad to share it with you.

Newbie

Posts

Joined
Sun Mar 22, 2009 9:24 pm

Post by timkirtley » Fri Jun 18, 2010 6:12 pm

How would I go about using dynamic templates for products/categories in 1.4.8? The code currently in my category.php appears slightly different...
Qphoria wrote:I'll show you a very easy and cool dynamic way to do this:

Edit: catalog/controller/product/category.php

Find:

Code: Select all

$this->template = $this->config->get('config_template') . 'product/category.tpl';
Replace with:

Code: Select all

$this->template = $this->config->get('config_template') . 'product/category_' . $this->request->get['path'] . '.tpl';
if (!file_exists(DIR_TEMPLATE . $this->template)) {
	$this->template = $this->config->get('config_template') . 'product/category.tpl';
}
Now, anytime you want a custom category template. Create a clone of the category.tpl file using the category path as part of the name. For example:

category_25.tpl
category_25_38.tpl
category_25_38_72.tpl
etc.

The code will first check for the existence of an override file. If there is one it will use it. If there is none for that category, then it will default to the original file.

This can be done for virtually any file. Products, information, etc.

Newbie

Posts

Joined
Fri Jun 04, 2010 7:01 am

Post by timkirtley » Mon Jun 28, 2010 6:45 pm

Does anyone have any solutions for doing this in the current version?

I have two main categories of products but need a slightly different layout for the product pages for each and have so far been unable to achieve this.

Would really appreciate any assistance with this, thanks.

Newbie

Posts

Joined
Fri Jun 04, 2010 7:01 am

Post by Qphoria » Mon Jun 28, 2010 10:03 pm

In 1.4.0 and later you can do it this way.

1. FIND (All instances):

Code: Select all

if (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';
} 
2. REPLACE WITH:

Code: Select all

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category_' . $this->request->get['path'] . '.tpl')) {
                    $this->template = $this->config->get('config_template') . 'product/category_' . $this->request->get['path'] . '.tpl';
                } elseif (file_exists(DIR_TEMPLATE . 'default/template/product/category_' . $this->request->get['path'] . '.tpl')) {
                    $this->template = 'defaul/template/product/category_' . $this->request->get['path'] . '.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.0.x Mod Update Info

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by timkirtley » Wed Jun 30, 2010 4:45 pm

Awesome.. that's a great help with my category pages.

In case anyone else just copies and pastes the above code, I had to make a couple of tiny corrections:

On the third line
$this->template = $this->config->get('config_template') . 'product/category_' . $this->request->get['path'] . '.tpl';

needed: /template/ in front of 'product/category_'

and default is missing a 't' on the end on the sixth line.

Works a treat though as I say...

How easy is it to apply this approach, or something similar to product templates?

Really I would want to have a different template according to the category the product resides in, as my products only have one category assigned to them.

Newbie

Posts

Joined
Fri Jun 04, 2010 7:01 am

Post by JAY6390 » Wed Jun 30, 2010 6:45 pm

You mean based on product id's or the categories still? Either way it should be fairly straightforward

ImageImageImage

SEO MEGA KIT PLUS - Get your site ranking higher in the search engines
Better Product SEO URL's - Perfectly structured product links
SEO URL's Route Editor PRO - Make ANY url on your site have clean keywords - even third party extensions (remove index.php)


Image


User avatar
Newbie

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by timkirtley » Mon Jul 19, 2010 8:14 pm

Hello.. back on this project again (been juggling magento, wordpress e-commerce and opencart projects!)


I'd rather not have to do it via product id's to keep things flexible, but I'd like to have different templates for products in different categories.

Newbie

Posts

Joined
Fri Jun 04, 2010 7:01 am

Post by spikeachu » Tue Jul 20, 2010 3:24 am

timkirtley wrote:Awesome.. that's a great help with my category pages.

In case anyone else just copies and pastes the above code, I had to make a couple of tiny corrections:

On the third line
$this->template = $this->config->get('config_template') . 'product/category_' . $this->request->get['path'] . '.tpl';

needed: /template/ in front of 'product/category_'

and default is missing a 't' on the end on the sixth line.

Works a treat though as I say...

How easy is it to apply this approach, or something similar to product templates?

Really I would want to have a different template according to the category the product resides in, as my products only have one category assigned to them.
I made a mod for this very thing, You select the template from the category / product page in the admin area. So no need to hardcode every page.

http://forum.opencart.com/viewtopic.php?f=23&t=12935

Wedding Invitations and Stationery by Love2print

Commercial Mods
Product Colours on Category Page
Cardsave Direct Gateway
Clear Cache
Promotional Watermarks on Images
Multiple Category / Product Templates ** Popular **
Log Failed Login Attempts
Display Eligible Coupons with Products
Twitter Feeds

Have I helped you out or saved you some time? Please donate


Newbie

Posts

Joined
Fri Mar 12, 2010 6:31 am

Post by timkirtley » Tue Jul 20, 2010 11:13 pm

Sounds perfect.. downloaded it any got so far but ran in to a small problem as described in the other thread... But yeah, this sounds like it will be perfect.

Newbie

Posts

Joined
Fri Jun 04, 2010 7:01 am

Post by sanken » Wed Sep 07, 2011 7:47 pm

Hi Qphoria,
Does this mod works in 1.5.1? I have a site (www.bodybebe.ro) with 6 templates, one for each category, one intro&about. I made a clone of category.tpl (in view/theme/default/product ) as category_59_60.tpl; category_59_63.tpl;category_59_65.tpl;category_59_66.tpl;category_59_67.tpl
and the code was :
if (file_exists(DIR_TEMPLATE . $this->config->get
('config_template') . '/template/product/category_' . $this->request->get['path'] . '.tpl')) {
$this->template = $this->config->get('config_template') . '/template/product/category_' . $this->request->get['path'] . '.tpl';
} elseif (file_exists(DIR_TEMPLATE . 'default/template/product/category_' . $this->request->get['path'] . '.tpl')) {
$this->template = 'default/template/product/category_' . $this->request->get['path'] . '.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';
}

But nothing happened, seems code don't work. Any sugestions?

Newbie

Posts

Joined
Wed Sep 07, 2011 7:39 pm

Post by maffu » Fri Dec 13, 2013 11:51 pm

Hi, i need to identify the category NOT by path or id, but by SKU or Model or something else..i can do this?

ps: sorry for my bad english ^^'
Qphoria wrote:I'll show you a very easy and cool dynamic way to do this:

Edit: catalog/controller/product/category.php

Find:

Code: Select all

$this->template = $this->config->get('config_template') . 'product/category.tpl';
Replace with:

Code: Select all

$this->template = $this->config->get('config_template') . 'product/category_' . $this->request->get['path'] . '.tpl';
if (!file_exists(DIR_TEMPLATE . $this->template)) {
	$this->template = $this->config->get('config_template') . 'product/category.tpl';
}
Now, anytime you want a custom category template. Create a clone of the category.tpl file using the category path as part of the name. For example:

category_25.tpl
category_25_38.tpl
category_25_38_72.tpl
etc.

The code will first check for the existence of an override file. If there is one it will use it. If there is none for that category, then it will default to the original file.

This can be done for virtually any file. Products, information, etc.

Newbie

Posts

Joined
Thu Dec 12, 2013 4:45 pm
Who is online

Users browsing this forum: No registered users and 16 guests