Post by prototype0104 » Mon May 20, 2019 6:34 pm

Hi guys! I'm using 3.0.3.2 with Journal 3. I'm trying to make something with the search function. In product list from search I want to show me product title like:
Category name (of product) : Product name.
Now the problem is that I don't know who to get the category name of product.

New member

Posts

Joined
Sun Mar 24, 2019 6:08 pm

Post by thekrotek » Mon May 20, 2019 7:13 pm

Description couldn't be more vague. Display where? Search from where? You know, that a single product can have multiple categories assigned, right?

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member
Online

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by prototype0104 » Mon May 20, 2019 7:29 pm

route product -> search .. There are more search tools in a store? I know that products have more category assigned, I want to show the last subcategory.
Like: BMW - > 320d
320d : product name

New member

Posts

Joined
Sun Mar 24, 2019 6:08 pm

Post by thekrotek » Mon May 20, 2019 10:43 pm

prototype0104 wrote:
Mon May 20, 2019 7:29 pm
route product -> search .. There are more search tools in a store?
Yes, you can also search in admin.
prototype0104 wrote:
Mon May 20, 2019 7:29 pm
I know that products have more category assigned, I want to show the last subcategory.
Like: BMW - > 320d
320d : product name
Show WHERE?

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member
Online

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by uksitebuilder » Tue May 21, 2019 12:16 am

If you mean something like this:

Image


Assuming you have only assigned each product to one category in your store

edit: catalog/controller/product/search.php

find:

Code: Select all

$data['products'][] = array(
add before:

Code: Select all

$categories = $this->model_catalog_product->getCategories($result['product_id']);
$category_data = $this->model_catalog_category->getCategory($categories[0]['category_id']); 
$category_name = $category_data['name'];
find:

Code: Select all

'name'        => $result['name'],
change to:

Code: Select all

'name'        => $category_name . ': ' . $result['name'],
This is only a quick edit and can probably be done better!

Attachments

Screenshot 2019-05-20 at 17.11.53.png

Screenshot 2019-05-20 at 17.11.53.png (306.06 KiB) Viewed 149 times


ImageImageImageImageImage

For Friendly Professional Support - Click Here


User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by prototype0104 » Tue May 21, 2019 12:48 am

Thank you very much! For taking last subcategory?

New member

Posts

Joined
Sun Mar 24, 2019 6:08 pm

Post by uksitebuilder » Tue May 21, 2019 3:09 pm

It will display whichever category you have assigned the product to only.

ImageImageImageImageImage

For Friendly Professional Support - Click Here


User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by paulfeakins » Tue May 21, 2019 5:48 pm

thekrotek wrote:
Mon May 20, 2019 7:13 pm
Description couldn't be more vague.
It could if it didn't include the OC version and theme.

thekrotek wrote:
Mon May 20, 2019 7:13 pm
Display where?
The search results page.

thekrotek wrote:
Mon May 20, 2019 7:13 pm
Search from where?
The site search.

thekrotek wrote:
Mon May 20, 2019 7:13 pm
You know, that a single product can have multiple categories assigned, right?
You know it's possible to display multiple categories, right? ;)

For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Expert Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom

Post by thekrotek » Tue May 21, 2019 5:57 pm

paulfeakins wrote:
Tue May 21, 2019 5:48 pm
You know it's possible to display multiple categories, right? ;)
I know, but they guy said categorY, singular. And that description... arrrgh.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member
Online

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by paulfeakins » Tue May 21, 2019 6:13 pm

Well true a lot of descriptions hurt one's head to try and make sense of but this one did actually make sense to me.

It sounds like the OP would need to add to the controller to return the category(ies) of each product and then output those on the template.

For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Expert Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom

Post by prototype0104 » Wed May 22, 2019 3:23 am

In the end I did product list to be like, every product title : Category : Product name
Category = last subcategory - 1 (ex: CAR->BMW->320D) Category = BMW

Code: Select all

public function getcatID($category_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category WHERE category_id = '" . (int)$category_id . "'");
		return (int)$query->row['parent_id'];
	}
	

Code: Select all

$categories = $this->model_catalog_product->getCategories($result['product_id']);
				$catid= $this->model_catalog_category->getcatID($categories[0]['category_id']);
				$category_data = $this->model_catalog_category->getCategory($catid); 
				$category_name = $category_data['name'];

Code: Select all

'name'        => $category_name . ': ' . $result['name'],

New member

Posts

Joined
Sun Mar 24, 2019 6:08 pm
Who is online

Users browsing this forum: thekrotek and 9 guests