Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2011
    Posts
    72
    Plugin Contributions
    0

    Default Automatic Category Images Error

    Using Zen Cart 1.5.6c

    I get this error if there is no image for an item.. I have 20k items and a ton of categories.. I do try and correct the problem, but I'd rather it just put "NoImage.jpg" instead of throwing an error.

    Any help would be appreciated.

    This is error

    PHP Warning: array_rand() expects parameter 1 to be array .... httpdocs/includes/functions/extra_functions/functions_auto_category_images.php on line 13

    This is line 13:

    $image = auto_category_images( $sub_categories[array_rand( $sub_categories, 1 )] );

    PHP Code:
    <?php

        
    function auto_category_images$catID ) {
            global 
    $db;

            if ( 
    $catID ) {

                
    $cat_has_products $db->Execute("SELECT p.products_image FROM " TABLE_PRODUCTS " p, " TABLE_PRODUCTS_TO_CATEGORIES " p2c WHERE p.products_id = p2c.products_id AND p2c.categories_id = " $catID " ORDER BY RAND() LIMIT 1");
                if(
    $cat_has_products->RecordCount() > 0){
                    
    $image $cat_has_products->fields['products_image'];
                } else {
                    
    zen_get_subcategories$sub_categories$catID );
                    
    $image auto_category_images$sub_categories[array_rand$sub_categories)] ); 
                  }
            } else {
                
    // This category contains no products!
                
    $image 'pixel_trans.gif';
            }

            return 
    $image;
        }

    ?>

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Automatic Category Images Error

    Where did this function come from? It's not part of Zen Cart core.

    I suspect the following will stop the error by virtue of setting the variable to an array before it is accessed. But it feels like your function is doing a lot of extra queries.

    Code:
                    $image = $cat_has_products->fields['products_image']; 
                } else { 
                    $sub_categories = array();
                    zen_get_subcategories( $sub_categories, $catID );
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,690
    Plugin Contributions
    123

    Default Re: Automatic Category Images Error

    This bug is fixed in the latest version of Automatic Category Images.
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

 

 

Similar Threads

  1. v139h Automatic Resize of Uploaded Images?
    By jjj0923 in forum All Other Contributions/Addons
    Replies: 2
    Last Post: 23 Feb 2012, 10:32 PM
  2. Help - internal server error when doing super orders automatic payment
    By kenny724 in forum All Other Contributions/Addons
    Replies: 5
    Last Post: 27 Nov 2010, 10:50 PM
  3. Automatically populate category images from their product images
    By jackie.taferner in forum Setting Up Categories, Products, Attributes
    Replies: 47
    Last Post: 12 Oct 2010, 08:41 PM
  4. Related Products Recommended by Category, Automatically - Automatic Cross Sell
    By wolfderby in forum Contribution-Writing Guidelines
    Replies: 0
    Last Post: 5 Jan 2010, 10:37 PM
  5. Need different style for category images and product images
    By molls2714 in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 12 Jul 2008, 04:07 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR