A method could be coded to do this, but would rely on the product only being added to one sub category or man category (not both and not multiple) Which is the reason I guess it works the way it does now.
I have such a method which is used in one of my extensions
edit: catalog/model/catalog/product.php
find
add before
Code: Select all
public function getCategoryPath($product_id) {
$category = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");
if($category->num_rows){
$path = array();
foreach($category->rows as $paths){
$path[0] = $paths['category_id'];
}
$parent = $this->db->query("SELECT * FROM " . DB_PREFIX . "category WHERE category_id = '" . (int)$path[0] . "'");
$pid = $parent->row['parent_id'];
$p = 1;
if($pid>0){
do{
$path[$p] = $pid;
$parent2 = $this->db->query("SELECT * FROM " . DB_PREFIX . "category WHERE category_id = '" . (int)$pid . "'");
$pid = $parent2->row['parent_id'];
$p++;
}while($pid>0);
}
$path = array_reverse($path);
$fullpath = '';
foreach($path as $val){
$fullpath .= '_'.$val;
}
return ltrim($fullpath, '_');
}else{
return '0';
}
}
Now, in whichever controller you wish that lists products (i.e. it already loads the model we just edited), then put the product link as follows
Code: Select all
$this->url->link('product/product', 'path=' . $this->model_catalog_product->getCategoryPath($product['product_id']) . '&product_id=' . $product['product_id'])
You may need to replace $product['product_id'] with whatever is used in the controller for the product_id