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?
Open catalog/controller/product/product.php
And put code bellow (see the comment)
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
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',
...
);
Let say a product is in categories with id 110 and 111. You can create product_cat_110.tpl and product_cat_111.tpl
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).
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).
Who is online
Users browsing this forum: No registered users and 24 guests