Post by thomasbrentnall » Mon Aug 10, 2015 5:12 pm

cheeseus wrote:Just adding that VettelS' code also works for OpenCart 2.0.2.0 and 2.0.3.1.

The only thing you need to be careful with is placing the code NOT immediately after the foreach loop opens, but after the second line of code inside it:

Code: Select all

$product_info = $this->model_catalog_product->getProduct($product_id);
This is necessary because the code uses the $product_info['product_id'] array element which isn't declared if the line above comes after the addition, which will trigger an error.

This is how your foreach loop should look:

Code: Select all

foreach ($products as $product_id) {
	$product_info = $this->model_catalog_product->getProduct($product_id);

	// Hack to create full path in the breadcrumbs for featured products
	$cat = $this->model_catalog_product->getCategories($product_id);
	if(!empty($cat)) {
		$cat_trace = array($cat[0]['category_id']);
		$i = 0; $stop = false;
		while(!$stop) {
			$arr = $this->model_catalog_category->getCategory($cat_trace[$i++]);
			if($arr['parent_id'] != 0)
				$cat_trace[] = $arr['parent_id'];
			else
				$stop = true;
		}

		$cat_trace = implode('_', array_reverse($cat_trace));
             
		$link = $this->url->link('product/product', 'path=' . $cat_trace . '&product_id=' . $product_info['product_id']);
	}
	else {
		$link = $this->url->link('product/product', 'product_id=' . $product_info['product_id']);
	}				
	// end hack				
				
	if ($product_info) {
.......
Thank you, VettelS!
Hello,

I've just tried this solution on version 2.0.3.1 however I'm getting the error

Code: Select all

Fatal error: Call to a member function getCategddories() on a non-object in C:\xampp\htdocs\opencart\catalog\controller\module\featured.php on line 39
Did you have any issues with this?

Thanks,

Tom


Posts

Joined
Mon Aug 10, 2015 5:10 pm

Post by VaGeLiS3 » Mon Apr 18, 2016 9:50 pm

Hi to all,

can you tell us, how to do this in OC 2.1.0.2. All the changes in one post

Thanks a lot!

Newbie

Posts

Joined
Fri May 16, 2014 9:19 pm

Post by tingwing » Sat Jan 21, 2017 10:16 pm

solution is simple

just set values for the "seo url" item of these categories

my extension:https://www.opencart.com/index.php?rout ... estshop24h
email :support@bestshop24h.com
site:http://www.bestshop24h.com


Active Member

Posts

Joined
Tue Aug 02, 2016 9:01 pm

Post by IP_CAM » Sat Jan 21, 2017 11:00 pm


My Github OC Site: https://github.com/IP-CAM
5'600 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland
Who is online

Users browsing this forum: No registered users and 19 guests