* Deployed locale or live: Live
* Installed/Used Template/Theme: Journal3
* Installed/Used Translation: none
* Servertype (Linux/MS): Linux
* php-Version: I forget. I was told it was the latest version that opencart 3.0.3.3 can use
* MySQL-Version: not sure
* Used Browser: Firefox, Chrome, Brave
* I use CloudFlare (yes/no): no
* I am the only admin (yes/no): no
* Content of error log file (OpenCart/Server): there is no change in the error logs.
Good morning,
I'm trying to make a function that will take a category id and collect all it's parents back to it's root category. I am using ocmod and I can see my code in the copy of catalog.php in the modifications cache. I have cleared and refreshed the caches as I normally do when installing or configuring a mod. Here is my function.
Code: Select all
public function getCategoryPath($category_id) {
$query = $this->db->query("SELECT parent_id FROM " . DB_PREFIX . "category WHERE category_id = '" . (int)$category_id . "'");
if($query->row['category_id']){ //if this category exists start the path with it
$CategoryPath = (string)$query->row['category_id'];
//get current Category's parrents and add them to the begining of the path till we hit root
while($query->row['parent_id'] > 0) { //If we just added the root to the path we are done
$query = $this->db->query("SELECT parent_id FROM " . DB_PREFIX . "category WHERE category_id = '" . (int)$query->row['parent_id'] . "'");
$CategoryPath = $query->row['parent_id'] . "_" . $CategoryPath;
}
return $CategoryPath;
}
return false;
}
Code: Select all
$canonical_path = this->getCategoryPath(265);
$this->log = new \Log('MyCatalogPath.log');
$this->log->write("The Canonical path for category id 265" . " is " . $canonical_path);
Additionally, in the catalog.php controller when I try to log variables even without calling my function nothing is logged and no file is created. When I use logging in some other controllers it works fine but pasting it in this particular one has no effect. I do have multiple error logs but my logged data doesn’t show up in any of them if I log from catalog.php.
Anyone have some ideas where I am going wrong from an OpenCart perspective?.