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
Can anyone help, or point me in the right direction? Thank you in advance!
Regards,
Matt
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:
AFTER, ADD:
Then change:
$this->document->title = $product_info['name'];
to
$this->document->title = $category_title . ' - ' . $product_info['name'];
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')
);
}
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'];
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
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
output on my title bar: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:AFTER, ADD: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') ); }
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'];
Code: Select all
- product name
Or can this be:
Store Name - category - product name
What do you think?
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.
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.
@dmonco
See post by Chones http://forum.opencart.com/viewtopic.php?t=13347
My modified a little bit modified code (not using SEO url) :
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 } ?>
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?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:AFTER, ADD: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') ); }
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'];
Thx!
Worked like a charm for me in 1.5.1.3! Thank you.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 } ?>
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 :
Does anyone know what tweaks would be needed to fix the error?
many thanks in advance,
anthony
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
many thanks in advance,
anthony
@eleven28
Just a minor tweak to get this working in OC version 1.5.5.1:
added the prefix oc_ to product_to_category
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 } ?>
Who is online
Users browsing this forum: No registered users and 13 guests