Post by georgegsp » Mon Feb 18, 2013 4:11 pm

Dear all, hello!

I've used OpenCart (1.4.9.3) and have read a thread over here: http://www.opencartnews.com/tutorials/s ... duct-page/ in order to be able to have different template per category. I've actually managed that using the instructions given there.

Though, what I can't do, is having same product template for all products in a specific category (so I won't have to create template for each and every product manually).

Could I please have some help on this?

Web Design & Development - Web & Mobile Apps


User avatar
Newbie

Posts

Joined
Mon Feb 18, 2013 4:03 pm
Location - L. Kalamakiou 3, Alimos, Athens - Greece

Post by qahar » Thu Feb 21, 2013 6:20 pm

Open catalog/controller/product/product.php
And put code bellow (see the comment)

Code: Select all

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

// put this code
$categories = $this->model_catalog_product->getCategories($product_info['product_id']); 
if ($categories){ 
    foreach ($categories as $category) {
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product_cat_'.$category['category_id'].'.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/product/product_cat_'.$category['category_id'].'.tpl';
        }
    }
}
// end code

$this->children = array(
    'common/column_right',
    'common/column_left',
    ...
);
 
In OpenCart, you can set a product to several category. With code above you can create custom template based on all category where the product belong to.
Let say a product is in categories with id 110 and 111. You can create product_cat_110.tpl and product_cat_111.tpl

User avatar
Expert Member

Posts

Joined
Tue Jun 29, 2010 10:24 pm
Location - Indonesia

Post by georgegsp » Fri Feb 22, 2013 12:44 am

Your help was great!

That absolutely did the trick :)

Thank you very much qahar, I really appreciate it ;)

Web Design & Development - Web & Mobile Apps


User avatar
Newbie

Posts

Joined
Mon Feb 18, 2013 4:03 pm
Location - L. Kalamakiou 3, Alimos, Athens - Greece

Post by 528491 » Tue Jul 16, 2013 2:13 pm

Hello, thanks for this great solution.

However, I need to make this work not for the product page, but for the parent category page. How can this be made?

EDIT:
Found the solution, if anyone else needs it: http://stackoverflow.com/questions/1363 ... a-category
with the exception that i did not make the new category.php file in controller/products folder, I simply made the changes in the original file. Also I did not need to change the class in this file, because, for my specific need, it works without changing it (I do not need registering the new route change in admin as the topic creator needed).

New member

Posts

Joined
Tue Apr 02, 2013 6:05 pm
Who is online

Users browsing this forum: No registered users and 24 guests