2 Commity ccdd44388e ... ec318c26e2

Autor SHA1 Správa Dátum
  Benjamin Harris ec318c26e2 Naming Improvements 2 týždňov pred
  Benjamin Harris ead903d0d8 Fix memory exhaustion caused by recursive category tree loading 2 týždňov pred
3 zmenil súbory, kde vykonal 38 pridanie a 14 odobranie
  1. 3 1
      CLAUDE.md
  2. 1 1
      install.xml
  3. 34 12
      upload/admin/controller/extension/module/reverb.php

+ 3 - 1
CLAUDE.md

@@ -72,7 +72,9 @@ upload/
         └── OrderMapper.php         # Maps Reverb order payload → OC order format
 ```
 
-OCMOD patch file (`reverb.ocmod.xml`) injects the per-product toggle into the product edit page without modifying core files.
+OCMOD patch file (`install.xml`) injects the per-product toggle into the product edit page without modifying core files.
+
+The upload folder and install.xml is zipped into a file called  reverb.ocmod.zip for installing via the extension installer in opencart admin backend
 
 ### Database Tables
 

+ 1 - 1
install.xml

@@ -2,7 +2,7 @@
 <modification>
     <name>Reverb Integration</name>
     <code>reverb</code>
-    <version>1.0.0</version>
+    <version>1.0.1</version>
     <author>Reverb OpenCart</author>
     <link>https://reverb.com/au/page/integrations</link>
 

+ 34 - 12
upload/admin/controller/extension/module/reverb.php

@@ -278,18 +278,40 @@ class ControllerExtensionModuleReverb extends Controller {
         ];
     }
 
-    private function getCategoryTree($parent_id = 0, $indent = '') {
-        $this->load->model('catalog/category');
-        $categories = [];
-        $results = $this->model_catalog_category->getCategories(['parent_id' => $parent_id]);
-        foreach ($results as $cat) {
-            $categories[] = [
-                'category_id' => $cat['category_id'],
-                'name'        => $indent . $cat['name'],
-            ];
-            $children = $this->getCategoryTree($cat['category_id'], $indent . '&nbsp;&nbsp;&nbsp;');
-            $categories = array_merge($categories, $children);
+    private function getCategoryTree() {
+        $language_id = (int)$this->config->get('config_language_id');
+
+        $query = $this->db->query("
+            SELECT c.category_id, c.parent_id, cd.name
+            FROM `" . DB_PREFIX . "category` c
+            LEFT JOIN `" . DB_PREFIX . "category_description` cd
+                ON cd.category_id = c.category_id AND cd.language_id = '" . $language_id . "'
+            WHERE c.status = 1
+            ORDER BY c.parent_id ASC, cd.name ASC
+        ");
+
+        $all    = $query->rows;
+        $byPid  = [];
+        foreach ($all as $row) {
+            $byPid[(int)$row['parent_id']][] = $row;
+        }
+
+        $result = [];
+        $stack  = [[0, '']];
+        while ($stack) {
+            [$pid, $indent] = array_pop($stack);
+            if (empty($byPid[$pid])) {
+                continue;
+            }
+            foreach (array_reverse($byPid[$pid]) as $cat) {
+                $result[] = [
+                    'category_id' => $cat['category_id'],
+                    'name'        => $indent . $cat['name'],
+                ];
+                array_push($stack, [(int)$cat['category_id'], $indent . '&nbsp;&nbsp;&nbsp;']);
+            }
         }
-        return $categories;
+
+        return $result;
     }
 }