Zen Cart Logo
Forums / Setting Up Categories, Products, Attributes / Automatically populate category images from their product images

Automatically populate category images from their product images

Locked

Views: 8,403

Results 21 to 40 of 48
This thread is locked. New replies are disabled.
10 Sep 2010, 2:53 PM
#21
mikestaps avatar

mikestaps

Zen Follower

Join Date:
Aug 2010
Location:
Grand Blanc, MI
Posts:
305
Plugin Contributions:
1

Automatically populate category images from their product images

Ok took store off "Down for Maintenance" and re implemented the changed category_row.php file.
Check it out - here

10 Sep 2010, 2:57 PM
#22
sarahl avatar

sarahl

Zen Follower

Join Date:
May 2004
Location:
UK
Posts:
471
Plugin Contributions:
0

Re: Automatically populate category images from their product images

I keep getting sent back to home page not into category?

10 Sep 2010, 3:33 PM
#23
mikestaps avatar

mikestaps

Zen Follower

Join Date:
Aug 2010
Location:
Grand Blanc, MI
Posts:
305
Plugin Contributions:
1

Re: Automatically populate category images from their product images

SarahL:

I keep getting sent back to home page not into category?

Yup - the question is why?

10 Sep 2010, 9:37 PM
#24
mikestaps avatar

mikestaps

Zen Follower

Join Date:
Aug 2010
Location:
Grand Blanc, MI
Posts:
305
Plugin Contributions:
1

Re: Automatically populate category images from their product images

Well I have to take the store back down for the weekend, hopefully we can figure it on monday...

16 Sep 2010, 7:25 PM
#25
cheaperbyfar avatar

cheaperbyfar

New Zenner

Join Date:
Aug 2010
Posts:
26
Plugin Contributions:
0

Re: Automatically populate category images from their product images

I'm just getting started with zencart. This was exactly what I was looking for with the random category pictures. However, it shows up the image unavailable picture for all. In the code, it should kick it to the transpixelgif if no file exists. I'm confused. You can check it out here: https://www.cheaperbyfar.com.

Thanks,
Will

16 Sep 2010, 7:29 PM
#26
mikestaps avatar

mikestaps

Zen Follower

Join Date:
Aug 2010
Location:
Grand Blanc, MI
Posts:
305
Plugin Contributions:
1

Re: Automatically populate category images from their product images

I ended up giving up (kept looping me back to the index page) and making all of my category photos using multiple photos of products for that category, came out very nice, but time consuming.

16 Sep 2010, 7:50 PM
#27
webmc avatar

webmc

New Zenner

Join Date:
Jul 2010
Location:
Kent UK
Posts:
50
Plugin Contributions:
0

Re: Automatically populate category images from their product images

This is my Category row.php - works for me although i am not using category images on home page or seo urls.

Infact i am using the css categories menu so dont even need this anymore.....

<?php /** * index category_row.php * * Prepares the content for displaying a category's sub-category listing in grid format. * Once the data is prepared, it calls the standard tpl_list_box_content template for display. * * @package page * @copyright Copyright 2003-2006 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license <http://www.zen-cart.com/license/2_0.txt> GNU Public License V2.0 * @version $Id: category_row.php 4084 2006-08-06 23:59:36Z drbyte $ */ if (!defined('IS_ADMIN_FLAG')) { die('Illegal Access'); } $title = ''; $num_categories = $categories->RecordCount(); $row = 0; $col = 0; $list_box_contents = ''; if ($num_categories > 0) { if ($num_categories < MAX_DISPLAY_CATEGORIES_PER_ROW || MAX_DISPLAY_CATEGORIES_PER_ROW == 0) { $col_width = floor(100/$num_categories); } else { $col_width = floor(100/MAX_DISPLAY_CATEGORIES_PER_ROW); } while (!$categories->EOF) { global $db; $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"; $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; $cPath_new = zen_get_path($categories->fields['categories_id']); // strip out 0_ from top level cats $cPath_new = str_replace('=0_', '=', $cPath_new); // $categories->fields['products_name'] = zen_get_products_name($categories->fields['products_id']); $list_box_contents[$row][$col] = array('params' => 'class="categoryListBoxContents"' . ' ' . 'style="width:' . $col_width . '%;"', 'text' => '<a href="' . zen_href_link(FILENAME_DEFAULT, $cPath_new) . '">' . zen_image(DIR_WS_IMAGES . $categories->fields['categories_image'], $categories->fields['categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) . '<br />' . $categories->fields['categories_name'] . '</a>'); $col ++; if ($col > (MAX_DISPLAY_CATEGORIES_PER_ROW -1)) { $col = 0; $row ++; } $categories->MoveNext(); } } ?>
16 Sep 2010, 7:59 PM
#28
mikestaps avatar

mikestaps

Zen Follower

Join Date:
Aug 2010
Location:
Grand Blanc, MI
Posts:
305
Plugin Contributions:
1

Re: Automatically populate category images from their product images

WebMC-
Thank you for reposting the code, I don't need it now thou...
check out the images I ended up making here
I'll have the store up till 5pm EST as I'm working on it.

16 Sep 2010, 8:06 PM
#29
webmc avatar

webmc

New Zenner

Join Date:
Jul 2010
Location:
Kent UK
Posts:
50
Plugin Contributions:
0

Re: Automatically populate category images from their product images

good stuff good luck with the store - nice website name btw!

16 Sep 2010, 8:52 PM
#30
cheaperbyfar avatar

cheaperbyfar

New Zenner

Join Date:
Aug 2010
Posts:
26
Plugin Contributions:
0

Re: Automatically populate category images from their product images

Dunno, copied yours in exactly, still doesn't work. Guess I'm gonna go the other route.....come back to this later. The other addon I have installed is category dressing, but don't think that's interfering.

16 Sep 2010, 9:43 PM
#31
mikestaps avatar

mikestaps

Zen Follower

Join Date:
Aug 2010
Location:
Grand Blanc, MI
Posts:
305
Plugin Contributions:
1

Re: Automatically populate category images from their product images

If you had this implemented just a minute ago it seemed to be working just fine, then the browser couldn't connect to the server any longer???

cheaperbyfar:

Dunno, copied yours in exactly, still doesn't work. Guess I'm gonna go the other route.....come back to this later. The other addon I have installed is category dressing, but don't think that's interfering.

16 Sep 2010, 9:49 PM
#32
cheaperbyfar avatar

cheaperbyfar

New Zenner

Join Date:
Aug 2010
Posts:
26
Plugin Contributions:
0

Re: Automatically populate category images from their product images

I cheated... Exported products and categories with apsona and matched filenames from products to category images. Actually only took about 3 minutes... Anyone need better explanation let me know. Wanted more of the random thing going on...

29 Sep 2010, 2:14 AM
#33
fontaholic avatar

fontaholic

Zen Follower

Join Date:
Jun 2008
Posts:
111
Plugin Contributions:
0

Re: Automatically populate category images from their product images

ooh. aponsa. had never heard of that one before. love it. thanks.

did anyone get the random image code bit to work? i copy and pasted it as is, but no go... i would love a randomizer for category images.

5 Oct 2010, 8:46 PM
#34
fontaholic avatar

fontaholic

Zen Follower

Join Date:
Jun 2008
Posts:
111
Plugin Contributions:
0

Re: Automatically populate category images from their product images

gjh42:

WebMC's randomizing code could also be put in the same place:```php
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;


i've implemented this and it's working now that i got a pesky template issue ironed out. :clap: and i've got two questions/wishes:

is there a way to have it not to display images from products where there are no images? i'm seeing a lot of the 'photo not available' image as my category photos. really, there aren't a ton of unavailable images either...

is there a way to restrict the width of the image displayed? in one of my sections one random image is wide, the other are tall... the wide one runs off the edge into the right sideboxes (see attached) and i don't know if i can control that, short of re-saving that image as a portrait orientation...
5 Oct 2010, 9:55 PM
#35
webmc avatar

webmc

New Zenner

Join Date:
Jul 2010
Location:
Kent UK
Posts:
50
Plugin Contributions:
0

Re: Automatically populate category images from their product images

WebMC:

$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.....

I should of pointed out this code this code wont work for categories which contain subcategories as obviously in zen cart you cant have both products and categories on the same level, and therefore the query wont find any images. But You can still add those in manually....

Also when playing around with code I never intended to have catetory images on product info - if you did you would probably need to place the code there also.....

If you play around with the sql you could reduce the chances of it picking up an empty image......"AND products_image IS NOT NULL" ( I only have .jpg in these because I concatenated this string to the image names in excell and if it was empty would have left that)

5 Oct 2010, 10:10 PM
#36
webmc avatar

webmc

New Zenner

Join Date:
Jul 2010
Location:
Kent UK
Posts:
50
Plugin Contributions:
0

Re: Automatically populate category images from their product images

fontaholic:

is there a way to restrict the width of the image displayed?

That's weird - that usually happens when you have a really thin picture, I think thats going to happen even if you added it manually - you just need to edit the image and make sure it is taller - Ideally square by modifying the canvas size.

I would recommend installing image handler if you havent already (don't quote me on that as I can't verify how well it works throughout the versions but it works well for me...)

failing that you could add max-width in your css somewhere - but that usually gives you unproporitonal results....
(use firebug and check the class if you don't know it)

5 Oct 2010, 11:14 PM
#37
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Automatically populate category images from their product images

Wow. Yes, that's wide:)

Do you have custom settings for these in Configuration > Images?
Small Image Width
Small Image Height

Calculate Image Size

Image - Product Listing Width
Image - Product Listing Height
Image - Product New Listing Width
Image - Product New Listing Height
Image - New Products Width
Image - New Products Height
Image - Featured Products Width
Image - Featured Products Height
Image - Product All Listing Width
Image - Product All Listing Height

As long as you use "proportional images" setting, the images should be shrunk if necessary to fit the dimensions.

5 Oct 2010, 11:30 PM
#38
fontaholic avatar

fontaholic

Zen Follower

Join Date:
Jun 2008
Posts:
111
Plugin Contributions:
0

Re: Automatically populate category images from their product images

i definitely have some custom image sizes in there... i adjusted them when i didn't really know what i was doing, so maybe that's what (some of*) the issue is:

Small Image Width 222
Small Image Height 222
Calculate Image Size true
Image - Product Listing Width 144
Image - Product Listing Height 222
Image - Product New Listing Width 100
Image - Product New Listing Height 80
Image - New Products Width 100
Image - New Products Height 80
Image - Featured Products Width 100
Image - Featured Products Height 80
Image - Product All Listing Width 100
Image - Product All Listing Height 80

my product categories are pretty deep. big bummer that it doesn't display images of upper categories.

5 Oct 2010, 11:35 PM
#39
webmc avatar

webmc

New Zenner

Join Date:
Jul 2010
Location:
Kent UK
Posts:
50
Plugin Contributions:
0

Re: Automatically populate category images from their product images

WebMC:

I should of pointed out this code this code wont work for categories which contain subcategories as obviously in zen cart you cant have both products and categories on the same level, and therefore the query wont find any images. But You can still add those in manually...

Atleast I think thats the case - I gave up testing a while ago (and was only looking at subcategories one level deep) as I dont need this code but there is probably a way round it if someone wanted to take time to expand the code - i might be wrong...

5 Oct 2010, 11:38 PM
#40
fontaholic avatar

fontaholic

Zen Follower

Join Date:
Jun 2008
Posts:
111
Plugin Contributions:
0

Re: Automatically populate category images from their product images

yeah, it makes sense, no products, no images registered.... thanks. i'm no php guru. i know only enough to really mess stuff up and not be able to figure out the issue for months! :unsure: