Help make Auto Category Image work for Opencart 1.5.6

Discussion in 'eCommerce' started by dtblingerie, Dec 29, 2013.

  1. #1
    I have found two excellent extensions; however, neither of them work for 1.5.6. I keep getting the same error whenever I try to run them:

    Notice: Error: Table 'removed_removed.category' doesn't exist
    Error No: 1146
    SELECT category_id FROM `category` WHERE parent_id > 0 Order By category_id ASC in /removed/removed/mysql.php on line 50

    Can someone please tell me what to do in order to make these work for 1.5.6.

    Here is the first file: autocategoryimage.php
    
    <?php
    require_once('config.php');
    require_once(DIR_SYSTEM . 'startup.php');
    
    // Registry
    $registry = new Registry();
    
    // Loader
    $loader = new Loader($registry);
    $registry->set('load', $loader);
    
    // Config
    $config = new Config();
    $registry->set('config', $config);
    
    // Database 
    $db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
    $registry->set('db', $db);
    
    
    $query = $db->query("SELECT category_id FROM `category` WHERE parent_id > 0 Order By category_id ASC");
    
    foreach ($query->rows as $category){
        $query2 = $db->query("SELECT * FROM `" . DB_PREFIX . "product_to_category` WHERE category_id = '" . $category['category_id'] . "' ORDER BY RAND() LIMIT 1");
        foreach($query2->rows as $product){
            $query3 = $db->query("SELECT * FROM `" . DB_PREFIX . "product` WHERE product_id = '" . $product['product_id'] . "'");
            foreach($query3->rows as $image){
                $query4 = $db->query("UPDATE `" . DB_PREFIX . "category` SET image = '" . $image['image'] . "' WHERE category_id = '" . $category['category_id'] . "'");
                //echo ("UPDATE `" . DB_PREFIX . "category` SET image = '" . $image['image'] . "' WHERE category_id = '" . $category['category_id'] . "' <hr>");
            }
        }
    }
       
    
    $query = $db->query("SELECT category_id,parent_id FROM `category` WHERE parent_id > 0 and image='' Order By category_id ASC");
    
     foreach ($query->rows as $category){
        $query2x = $db->query("SELECT * FROM `" . DB_PREFIX . "category` WHERE parent_id = '" . $category['category_id'] . "' LIMIT 0, 1");
        foreach($query2x->rows as $realcat){
        //echo "{$realcat['category_id']}-{$realcat['parent_id']} <hr>";
            $query2 = $db->query("SELECT * FROM `" . DB_PREFIX . "product_to_category` WHERE category_id = '" . $realcat['category_id'] . "' ORDER BY RAND() LIMIT 1");
            foreach($query2->rows as $product){
                $query3 = $db->query("SELECT * FROM `" . DB_PREFIX . "product` WHERE product_id = '" . $product['product_id'] . "'");
                foreach($query3->rows as $image){
                    $query4 = $db->query("UPDATE `" . DB_PREFIX . "category` SET image = '" . $image['image'] . "' WHERE category_id = '" . $realcat['parent_id'] . "'");
                    //echo ("UPDATE `" . DB_PREFIX . "category` SET image = '" . $image['image'] . "' WHERE category_id = '" . $realcat['parent_id'] . "' <hr>");
                }
            }
        }
       
    }
    
    echo 'All category images are set.';
    
    ?>
    
    Code (markup):
    and here is the second: runonce.php
    
    <?php
    require_once('config.php');
    require_once(DIR_SYSTEM . 'startup.php');
    
    // Registry
    $registry = new Registry();
    
    // Loader
    $loader = new Loader($registry);
    $registry->set('load', $loader);
    
    // Config
    $config = new Config();
    $registry->set('config', $config);
    
    // Database 
    $db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
    $registry->set('db', $db);
    
    
    
    $query = $db->query("SELECT category_id FROM `category` WHERE parent_id > 0 Order By category_id ASC");
    
    foreach ($query->rows as $category){
        $query2 = $db->query("SELECT * FROM `" . DB_PREFIX . "product_to_category` WHERE category_id = '" . $category['category_id'] . "' LIMIT 0, 1");
        foreach($query2->rows as $product){
            $query3 = $db->query("SELECT * FROM `" . DB_PREFIX . "product` WHERE product_id = '" . $product['product_id'] . "'");
            foreach($query3->rows as $image){
                $query4 = $db->query("UPDATE `" . DB_PREFIX . "category` SET image = '" . $image['image'] . "' WHERE category_id = '" . $category['category_id'] . "'");
            }
        }
    }
       
    echo 'done';
    @unlink('runonce.php');
    
    Code (markup):
    I have also included the extension urls:
    http://www.opencart.com/index.php?route=extension/extension/info&extension_id=5781
    http://forum.opencart.com/viewtopic.php?t=48045


    Any help would truly be appreciated.
     
    dtblingerie, Dec 29, 2013 IP
  2. Nigel Lew

    Nigel Lew Notable Member

    Messages:
    4,642
    Likes Received:
    406
    Best Answers:
    21
    Trophy Points:
    295
    #2
    Nigel Lew, Jan 4, 2014 IP