Page 2 of 5 FirstFirst 1234 ... LastLast
Results 11 to 20 of 48
  1. #11
    Join Date
    Jul 2010
    Location
    Kent UK
    Posts
    50
    Plugin Contributions
    0

    Default Re: Automatically populate category images from their product images

    The following code will display a random category image based on on products from that category - I am aware the if statement could be condensed

    global $db;
    $sql = "select products_image from " . TABLE_PRODUCTS . " where master_categories_id = " . $categories->fields['categories_id'] . " ORDER BY RAND() LIMIT 1";
    $result = $db->Execute($sql);

    $cat_image = $result->fields['products_image'];
    $filename = DIR_WS_IMAGES . $cat_image;

    if (file_exists($filename)) {

    } else {

    $cat_image = "pixel_trans.gif";
    }

    if (!$categories->fields['categories_image']) !$categories->fields['categories_image'] = $cat_image;

  2. #12
    Join Date
    Jul 2010
    Location
    Kent UK
    Posts
    50
    Plugin Contributions
    0

    Default Re: Automatically populate category images from their product images

    $sql = "select products_image from " . TABLE_PRODUCTS . " where master_categories_id = " . $categories->fields['categories_id'] . " AND products_image IS NOT NULL AND products_image != '.jpg' AND products_image != ' ' ORDER BY RAND() LIMIT 1";


    you could change the sql to that to decrease the chances of it finding an empty image.......

    I am tempted to look into a way for the if statement to repeat the lookup if no file exists but this might be dangerous if no products have images in the category.....

  3. #13
    Join Date
    Jul 2010
    Location
    Kent UK
    Posts
    50
    Plugin Contributions
    0

    Default Re: Automatic Manufacturers Image SQL Statement

    If like my you were lucky enough to be planning ahead and have all your content ready and all the manufacturers images are convieniently already called the same as their category name and are jpgs, you could use sql to populate the fields with the path like so... (either in sql patches or phpmyadmin)

    update manufacturers set manufacturers_image =concat('manufacturers/',manufacturers_name,'.jpg')


    You have done this for the above also if you didnt want to play around with the code...

    (just make sure you have images in you manufactuers folder in the image folder called the same as the manufatuer name)

  4. #14
    Join Date
    May 2004
    Location
    UK
    Posts
    478
    Plugin Contributions
    0

    Default Re: Automatically populate category images from their product images

    I too would find a mod like this handy - for clients that update their stock and don't want out of date category images displayed - basically showing the first image for the first product into the category would be perfect!

    Did you get any progress on this?

  5. #15
    Join Date
    Aug 2010
    Location
    Hartland, MI
    Posts
    282
    Plugin Contributions
    3

    Default Re: Automatically populate category images from their product images

    This definitely looks like something I would like to implement... just not 100% sure where I place this code?

    Quote Originally Posted by WebMC View Post
    The following code will display a random category image based on on products from that category - I am aware the if statement could be condensed

    global $db;
    $sql = "select products_image from " . TABLE_PRODUCTS . " where master_categories_id = " . $categories->fields['categories_id'] . " ORDER BY RAND() LIMIT 1";
    $result = $db->Execute($sql);

    $cat_image = $result->fields['products_image'];
    $filename = DIR_WS_IMAGES . $cat_image;

    if (file_exists($filename)) {

    } else {

    $cat_image = "pixel_trans.gif";
    }

    if (!$categories->fields['categories_image']) !$categories->fields['categories_image'] = $cat_image;

  6. #16
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Automatically populate category images from their product images

    This will use images named for each category just by uploading them; no individual admin work needed.

    Edit /includes/modules/your_template/category_row.php.
    Find
    PHP Code:
      while (!$categories->EOF) {
        if (!
    $categories->fields['categories_image']) !$categories->fields['categories_image'] = 'pixel_trans.gif'
    and replace with
    PHP Code:
      while (!$categories->EOF) {
        
    $cat_image =  file_exists(DIR_WS_IMAGES 'categoryimg' $categories->fields['categories_id'] . '.jpg')? 'categoryimg' $categories->fields['categories_id'] . '.jpg''pixel_trans.gif';
        if (!
    $categories->fields['categories_image']) !$categories->fields['categories_image'] = $cat_image
    Name the images like categoryimg23.jpg (replacing 23 with the category's id) and save in /images/.

    Using the first product's image is more complicated unless it can be guaranteed that they will all be .jpg (or another fixed type).

  7. #17
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Automatically populate category images from their product images

    WebMC's randomizing code could also be put in the same place:
    PHP Code:
      while (!$categories->EOF) {
        global 
    $db;
        
    $sql "select products_image from " TABLE_PRODUCTS " where master_categories_id = " $categories->fields['categories_id'] . " ORDER BY RAND() LIMIT 1";
        
    $result $db->Execute($sql);
        
    $cat_image $result->fields['products_image'];
        
    $cat_image file_exists(DIR_WS_IMAGES $cat_image)? $cat_image'pixel_trans.gif';
        if (!
    $categories->fields['categories_image']) !$categories->fields['categories_image'] = $cat_image

  8. #18
    Join Date
    Aug 2010
    Location
    Hartland, MI
    Posts
    282
    Plugin Contributions
    3

    Default Re: Automatically populate category images from their product images

    Thanks
    Quote Originally Posted by gjh42 View Post
    WebMC's randomizing code could also be put in the same place:

  9. #19
    Join Date
    Aug 2010
    Location
    Hartland, MI
    Posts
    282
    Plugin Contributions
    3

    Default Re: Automatically populate category images from their product images

    The code just killed my subcategory links.... every time you click on a subcategory you jump to the store's home page. It worked great for the random photo, but no go...


    PHP Code:
      while (!$categories->EOF) {
        global 
    $db;
        
    $sql "select products_image from " TABLE_PRODUCTS " where master_categories_id = " $categories->fields['categories_id'] . " ORDER BY RAND() LIMIT 1";
        
    $result $db->Execute($sql);
        
    $cat_image $result->fields['products_image'];
        
    $cat_image file_exists(DIR_WS_IMAGES $cat_image)? $cat_image'pixel_trans.gif';
        if (!
    $categories->fields['categories_image']) !$categories->fields['categories_image'] = $cat_image
    Last edited by mikestaps; 9 Sep 2010 at 10:25 PM. Reason: remove typo

  10. #20
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Automatically populate category images from their product images

    If we can see it in action, perhaps we can tell what is going wrong.

 

 
Page 2 of 5 FirstFirst 1234 ... LastLast

Similar Threads

  1. Category images from product images
    By korayp in forum All Other Contributions/Addons
    Replies: 3
    Last Post: 22 Dec 2009, 04:12 PM
  2. How do I keep the banner images from resizing automatically?
    By bparker in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 19 Nov 2008, 03:33 AM
  3. Populate Images by Category and Product
    By borillion_star in forum Customization from the Admin
    Replies: 0
    Last Post: 1 Sep 2008, 08:57 PM
  4. Automatically populate sub category images + change attribute ordering
    By GTrotter in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 30 Apr 2007, 07:54 AM

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