Post by MrBrain » Fri Jun 12, 2020 7:29 pm

In catalog I just added this string to controller to use this variable:

Code: Select all

'cat_id' => $this->request->get['path'],
But in special module it doesn't work, how else can I do it?

Newbie

Posts

Joined
Tue Jun 11, 2019 5:25 pm

Post by straightlight » Fri Jun 12, 2020 7:46 pm

You could see how it's done in your catalog/controller/product/product.php file.

In catalog/controller/extension/module/special.php file,

find:

Code: Select all

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

Code: Select all

$this->load->model('catalog/category');
Then, find:

Code: Select all

$this->load->model('tool/image');
Add below:

Code: Select all

if (isset($this->request->get['path'])) {
			$path = '';

			$parts = explode('_', (string)$this->request->get['path']);

			$category_id = (int)array_pop($parts);

			foreach ($parts as $path_id) {
				if (!$path) {
					$path = $path_id;
				} else {
					$path .= '_' . $path_id;
				}

				$category_info = $this->model_catalog_category->getCategory($path_id);

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

			// Set the last category breadcrumb
			$category_info = $this->model_catalog_category->getCategory($category_id);

			if ($category_info) {
				$url = '';

				if (isset($this->request->get['sort'])) {
					$url .= '&sort=' . $this->request->get['sort'];
				}

				if (isset($this->request->get['order'])) {
					$url .= '&order=' . $this->request->get['order'];
				}

				if (isset($this->request->get['page'])) {
					$url .= '&page=' . $this->request->get['page'];
				}

				if (isset($this->request->get['limit'])) {
					$url .= '&limit=' . $this->request->get['limit'];
				}

				$data['breadcrumbs'][] = array(
					'text' => $category_info['name'],
					'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url)
				);
			}
		}
You could then use the $data['breadcrumbs'] and replace it with what you want to add in your special.twig file. Once replaced, ensure to clear your SAAS cache and developers cache.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by MrBrain » Fri Jun 12, 2020 11:37 pm

straightlight wrote:
Fri Jun 12, 2020 7:46 pm
You could see how it's done in your catalog/controller/product/product.php file.
I tried something like that but it didn't work, I think I made some mistake because I have Journal theme which works a bit differently, I used this file to print product attributes in special module as you can see in the last string and tried to get category id, attributes worked but category didn't, can you plz look where I must add your code? I tried to add it after line 16, 17 and 298, nothing worked. Also added category.php in which I could get id on line 208.

Newbie

Posts

Joined
Tue Jun 11, 2019 5:25 pm

Post by MrBrain » Sat Jun 13, 2020 2:27 am

I did it much simpler, just added:

Code: Select all

$categories = $this->model_catalog_product->getCategories($result['product_id']);
if($categories){
    $categories_info = $this->model_catalog_category->getCategory($categories[0]['category_id']);
    $id = $categories_info['category_id'];
}else{
    $id = '';
}

Newbie

Posts

Joined
Tue Jun 11, 2019 5:25 pm

Post by straightlight » Sat Jun 13, 2020 7:56 pm

MrBrain wrote:
Sat Jun 13, 2020 2:27 am
I did it much simpler, just added:

Code: Select all

$categories = $this->model_catalog_product->getCategories($result['product_id']);
if($categories){
    $categories_info = $this->model_catalog_category->getCategory($categories[0]['category_id']);
    $id = $categories_info['category_id'];
}else{
    $id = '';
}
That's because you're using the first constant category ID of those products which is not what my original post states. What it does is it tracks the first category of the top or parent category ID of the depth position where the user clicked on from the breadcrumb and so forth.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 12 guests