Skip to content

Instantly share code, notes, and snippets.

@veganista
Created June 21, 2016 10:35
Show Gist options
  • Save veganista/c204b1e0b25379765b03a4595643ede9 to your computer and use it in GitHub Desktop.
Save veganista/c204b1e0b25379765b03a4595643ede9 to your computer and use it in GitHub Desktop.
Get the path to a category in opencart 1.5.*
<?php
/**
* Returns the path to a category in the format 1_2_3
* @param int $category_id
* @return string the path to the category
*/
public function getCategoryPath($category_id){
$path = '';
$category = $this->db->query("SELECT * FROM " . DB_PREFIX . "category c WHERE c.category_id = " .(int)($category_id));
if($category->row['parent_id'] != 0){
$path .= $this->getCategoryPath($category->row['parent_id']) . '_';
}
$path .= $category->row['category_id'];
return $path;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment