I am trying to get the full category path for each product but I am having a hard time getting it to work.
The following code returns the cattegory id path correctly (from what I have seen) but can't seem to be able to modify it so it returns the name of the category instead of the id.
Can anyone help?
Code: Select all
public function getProductCategoryPath($product_id) {//nick
$query = $this->db->query("SELECT category_id FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "' LIMIT 1");
if($query->row['category_id']){
// Parent category
$path2 = $query->row['category_id'];
// Category parent
$query = $this->db->query("SELECT parent_id FROM " . DB_PREFIX . "category WHERE category_id = '" . $query->row['category_id'] . "' AND parent_id != 0");
while($query->num_rows){
$path2 = $query->row['parent_id'] . "_" . $path2;
// Sub-category parent
$query = $this->db->query("SELECT parent_id FROM " . DB_PREFIX . "category WHERE category_id = '" . $query->row['parent_id'] . "' AND parent_id != 0");
}
return $path2;
}
return false;
}