Page 1 of 1

Category name on featured product line

Posted: Fri Dec 02, 2016 12:27 am
by lklicpouch
Hello. I have line of four featured products. how to display, what are the categories on this products?

Thanks for help.

Re: Category name on featured product line

Posted: Fri Dec 02, 2016 1:26 am
by opencartmart
It won't be easy if you don't know programming. I am just giving summery what to do. You need to modify two files.

1. Controller: catalog/controller/extension/featured.php

Code: Select all

$category_list= $this->model_catalog_product->getCategories($product_id);
Since a product belongs to more than one categories, it will give an array of categories list. Now you can find categories details by using category model. For using category mode, first load it by placing following code where product model is loaded.

Code: Select all

$this->load->model('catalog/category');
Now following code will give your category details list from above category ID list

Code: Select all

 $category_info = [];
  foreach ($category_list as $single) {
    $category_info[] = $this->model_catalog_category->getCategory($single['cateogry_id']);
}
Assign this array into featured product list like:

Code: Select all

$data['products'][] = array(
						'product_id'  => $product_info['product_id'],
						'thumb'       => $image,
						'name'        => $product_info['name'],
						'description' => utf8_substr(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get($this->config->get('config_theme') . '_product_description_length')) . '..',
						'price'       => $price,
						'special'     => $special,
						'tax'         => $tax,
						'rating'      => $rating,
                     'category' => $category_info,
						'href'        => $this->url->link('product/product', 'product_id=' . $product_info['product_id'])
					);

Now in template file: catalog/view/theme/YOUR_THEME/templates/extensions/module/featured.tpl, you will have to iterate category array for each product whatever you to place.

Better you can take professional support. Good luck!