Showing posts with label Ecommerce. Show all posts
Showing posts with label Ecommerce. Show all posts

Wednesday 29 October 2014

Display Category on Product Page in Opencart

Necessity is the advent of everything today while doing some project i got requirement from my client to show the categories of the product to which that particular product belongs along with the product on the product view page So in order to accomplish this task we have to perform some simple and easy steps :

  • In your open-cart folder whether it is online or offline double click on Catalog Folder
  • Then inside Catalog folder double click on Controller folder
  • Then inside Controller Folder double click on Product Folder
  • Then inside Product Folder open Product.php file in your text editor
  • Then Search for following line in Product.php file

$this->load->model('catalog/product');

  • When this line found just below this line add the following code 

//product category

$this->load->model('catalog/category');

$this->data['catprod'] = array();

$product_category = $this->model_catalog_product->getCategories($product_id);

foreach ($product_category as $prodcat) {

$category_info = $this->model_catalog_category->getCategory($prodcat['category_id']);

if ($category_info) {

$this->data['catprod'][] = array(
'name' => $category_info['name'],
'href' => $this->url->link('product/category', 'path=' . $category_info['category_id'])
);
}
}

//end of product category


  • Then again come in root folder of opencart
  • In your open-cart folder whether it is online or offline double click on Catalog Folder
  • Then inside Catalog folder double click on view folder
  • Then inside Controller Folder double click on theme Folder
  • Then inside Product Folder open your currently applied theme folder
  • Then inside theme folder open template folder