title: Opencart get parent categories for product
body: <p>How could I make this into a recursive function. So that it would get a list of all categories for the selected parent_id?</p>
  
  <pre><code>public function getProductCategoryPath($product_id) {
      $query = $this-&gt;db-&gt;query("SELECT category_id FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "' LIMIT 1");
  
      if($query-&gt;row['category_id']){
  
          // Parent category
          $path = $query-&gt;row['category_id'];
  
          // Category parent 
          $query = $this-&gt;db-&gt;query("SELECT parent_id FROM " . DB_PREFIX . "category WHERE category_id = '" . $query-&gt;row['category_id'] . "' AND parent_id != 0");           
          if($query-&gt;num_rows){
              $path = $query-&gt;row['parent_id'] . "_" . $path;
  
              // Sub-category parent 
              $query = $this-&gt;db-&gt;query("SELECT parent_id FROM " . DB_PREFIX . "category WHERE category_id = '" . $query-&gt;row['parent_id'] . "' AND parent_id != 0");         
              if($query-&gt;num_rows){
                  $path = $query-&gt;row['parent_id'] . "_" . $path;
              } 
          } 
  
          return $path;
      }
  
      return false;
  }
  </code></pre>