Post by matt6805 » Fri Nov 13, 2009 2:35 am

I've been trying to adjust the product.php controller to allow me the ability to display the product category title on an individual product tpl template. I find it odd that OpenCart doesn't do this by default. I know there's a way to do it, and I've seen a few threads on this board that are asking the same question, but none of them have been answered.

Can anyone help, or point me in the right direction? Thank you in advance!

Regards,
Matt

Newbie

Posts

Joined
Fri Nov 13, 2009 2:31 am

Post by Qphoria » Fri Nov 13, 2009 2:59 am

In all controllers the breadcrumb builds its path for the product. So just set a variable to the last path in the for loop in catalog/controller/product/product.php

Something like

FIND:

Code: Select all

if ($category_info) {
	$this->document->breadcrumbs[] = array(
	'href'      => $this->model_tool_seo_url->rewrite($this->url->http('product/category&path=' . $path)),
	'text'      => $category_info['name'],
	'separator' => $this->language->get('text_separator')
	);
}
AFTER, ADD:

Code: Select all

$category_title = $category_info['name'];

Then change:
$this->document->title = $product_info['name'];
to
$this->document->title = $category_title . ' - ' . $product_info['name'];

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by matt6805 » Fri Nov 13, 2009 4:00 am

Thank you for the quick response. I altered the product.php controller as you suggested, but then how do i call the value in the tpl? I tried echoing $category_title, but that didn't work.

I should also mention that I don't want this in the title tag. I'm trying to include the category name in the body somewhere, perhaps as an H1 tag. So, I'm not sure if $this->document->title will allow me to do that?

Regards,
Matt

Newbie

Posts

Joined
Fri Nov 13, 2009 2:31 am

Post by dramony » Sat Mar 27, 2010 3:49 pm

Qphoria wrote:In all controllers the breadcrumb builds its path for the product. So just set a variable to the last path in the for loop in catalog/controller/product/product.php

Something like

FIND:

Code: Select all

if ($category_info) {
	$this->document->breadcrumbs[] = array(
	'href'      => $this->model_tool_seo_url->rewrite($this->url->http('product/category&path=' . $path)),
	'text'      => $category_info['name'],
	'separator' => $this->language->get('text_separator')
	);
}
AFTER, ADD:

Code: Select all



$category_title = $category_info['name'];

Then change:
$this->document->title = $product_info['name'];
to
$this->document->title = $category_title . ' - ' . $product_info['name'];
output on my title bar:

Code: Select all

- product name
the category title is missing.

Or can this be:
Store Name - category - product name

What do you think?

Active Member

Posts

Joined
Sat Oct 24, 2009 12:34 pm

Post by Noman » Mon Apr 05, 2010 11:58 pm

Hi Guys

I need something similar to the above one.

Is there any way to include Category and Subcategory names in text format somewhere down in Product description box?

We have a product, which belongs to many categories and subcategories [Brands and Models]. Our Search has "Search in product descriptions" enabled by default. But Search won't find anything if we don't include the full name in the Product Name

What we have now:
Acer -> Aspire 3000 - Universal 3G Laptop Modem [this modem belongs to many categories and subcats]

Search won't find anything if I try only Acer Aspire 3000.

Adding automatically Acer -> Aspire 3000 [main category and subcategory names] to the product description field in Admin would help.

I know, this one isn't easy. Thank you.

New member

Posts

Joined
Wed Jun 24, 2009 7:44 pm

Post by dmonco » Mon Sep 05, 2011 6:50 am

So, what about the answer? Did somebody do that? Did somebody add category title to product page?
Please, explain how to do that.

New member

Posts

Joined
Sun Jun 12, 2011 8:05 am
Location - Ukraine

Post by nec2 » Sat Nov 12, 2011 12:57 am

@dmonco
See post by Chones http://forum.opencart.com/viewtopic.php?t=13347

My modified a little bit modified code (not using SEO url) :

Code: Select all

<?php
   $this->load->model('catalog/category');
   $query = $this->db->query("SELECT category_id
   FROM product_to_category
   WHERE product_id = '".$product_id."'");
   $prodcategories = $query->rows;
   foreach($prodcategories as $prodcategory){
   $category_id = $prodcategory['category_id'];
   $category_info = $this->model_catalog_category->getCategory($category_id);
   $caturl = (HTTP_SERVER . 'index.php?route=product/category&path=' . $category_id); ?>
   Category : <a href="<?php echo $caturl; ?>"><?php echo $category_info['name']; ?></a><br />
<?php  }  ?>

New member

Posts

Joined
Tue Aug 04, 2009 4:57 pm

Post by dklnd » Tue Nov 15, 2011 2:04 am

Qphoria wrote:In all controllers the breadcrumb builds its path for the product. So just set a variable to the last path in the for loop in catalog/controller/product/product.php

Something like

FIND:

Code: Select all

if ($category_info) {
	$this->document->breadcrumbs[] = array(
	'href'      => $this->model_tool_seo_url->rewrite($this->url->http('product/category&path=' . $path)),
	'text'      => $category_info['name'],
	'separator' => $this->language->get('text_separator')
	);
}
AFTER, ADD:

Code: Select all

$category_title = $category_info['name'];

Then change:
$this->document->title = $product_info['name'];
to
$this->document->title = $category_title . ' - ' . $product_info['name'];
What do you mean with 'after - add' do you add the code in the lines or where do I put the code? How will the total code look like?

Thx!

Active Member

Posts

Joined
Mon Nov 14, 2011 6:30 pm

Post by dklnd » Fri Nov 18, 2011 5:27 pm

please? anyone?

Active Member

Posts

Joined
Mon Nov 14, 2011 6:30 pm

Post by BBMleaf » Thu Jan 05, 2012 2:16 pm

@nec - thanks, your little work around still works

Newbie

Posts

Joined
Mon Oct 10, 2011 12:13 pm

Post by jeoob » Thu Jan 19, 2012 6:33 am

Hmm it doesnt work for us for some reason on 1.5.1.3 .... I triple checked it, but the title tag still just has the product name in it. did something change in this version?

Newbie

Posts

Joined
Tue Dec 27, 2011 3:47 am

Post by eleven28 » Fri Mar 02, 2012 6:24 am

nec2 wrote:@dmonco
See post by Chones http://forum.opencart.com/viewtopic.php?t=13347

My modified a little bit modified code (not using SEO url) :

Code: Select all

<?php
   $this->load->model('catalog/category');
   $query = $this->db->query("SELECT category_id
   FROM product_to_category
   WHERE product_id = '".$product_id."'");
   $prodcategories = $query->rows;
   foreach($prodcategories as $prodcategory){
   $category_id = $prodcategory['category_id'];
   $category_info = $this->model_catalog_category->getCategory($category_id);
   $caturl = (HTTP_SERVER . 'index.php?route=product/category&path=' . $category_id); ?>
   Category : <a href="<?php echo $caturl; ?>"><?php echo $category_info['name']; ?></a><br />
<?php  }  ?>
Worked like a charm for me in 1.5.1.3! Thank you.

User avatar
Newbie

Posts

Joined
Fri Jan 27, 2012 6:41 am
Location - Australia

Post by yubnub » Tue Mar 05, 2013 11:00 pm

hi,

I realize this is an old post - however I wanted to use Q's code but on ver 1.5.5.1

the code basically works and does return the page title exactly as planned - however i do get a error in my log :

Code: Select all

2013-03-05 14:49:53 - PHP Notice:  Undefined variable: category_info in /var/www/vhosts/xxxxx.co.uk/httpdocs/store/vqmod/vqcache/vq2-catalog_controller_product_product.php on line 226
Does anyone know what tweaks would be needed to fix the error?

many thanks in advance,

anthony

New member

Posts

Joined
Mon Nov 28, 2011 1:38 am

Post by beattie » Sun Mar 24, 2013 6:25 am

@eleven28
Just a minor tweak to get this working in OC version 1.5.5.1:
added the prefix oc_ to product_to_category

Code: Select all

<?php
       $this->load->model('catalog/category');
       $query = $this->db->query("SELECT category_id
       FROM oc_product_to_category
       WHERE product_id = '".$product_id."'");
       $prodcategories = $query->rows;
       foreach($prodcategories as $prodcategory){
       $category_id = $prodcategory['category_id'];
       $category_info = $this->model_catalog_category->getCategory($category_id);
       $caturl = (HTTP_SERVER . 'index.php?route=product/category&path=' . $category_id); ?>
       Category : <a href="<?php echo $caturl; ?>"><?php echo $category_info['name']; ?></a><br />
    <?php  }  ?>

New member

Posts

Joined
Tue May 22, 2012 11:33 am
Location - Australia
Who is online

Users browsing this forum: No registered users and 13 guests