Post by yop289 » Sat Jul 02, 2011 6:35 pm

Opencart version 1.5

When we use right now, modules like Featured,Bestsellers and latest in home the link of the product on image or button don`t have the category variable. I think is better if future realeases have this option.

I have done by my own.

In model catalog I write this function:

Code: Select all

public function getAllCategoriesfromProduct($product_id) {
		$product_data = array();
		
			
		$sql="SELECT category_id FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'";
		
		
		$product_query = $this->db->query($sql);
		

		foreach ($product_query->rows as $product) {
			
			$product_data[] = $product['category_id'];
			$line_separated = implode("_", $product_data);			
		}
		
		return $line_separated;
	}

And in each module I write this code (example for module/latest.php):

Code: Select all

$categorias = $this->model_catalog_category->getAllCategoriesfromProduct($result['product_id']);
and change href link

Code: Select all

'href'    	 => $this->url->link('product/product', . $result['product_id']),
for this one

Code: Select all

 'href'        => $this->url->link('product/product', 'path=' .$categorias . '&product_id=' . $result['product_id'])
Thanks

Expert in OpenCart, visit my other modules.
http://www.opencart.com/index.php?route ... ame=yop289
Custom coder, what you need you will have


Active Member

Posts

Joined
Sat Jun 25, 2011 1:49 am

Post by kliMa » Tue Feb 05, 2013 11:33 pm

Hi,
This is very good way to add it.
How to add parent_id of category inside the link?

Regards,
kliMa

New member

Posts

Joined
Sat May 08, 2010 2:24 am
Location - London
Who is online

Users browsing this forum: No registered users and 8 guests