Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Random Catagorys Image


azer

Recommended Posts

here is the thread support

 

if you call the function:

 

get_random_cat_image(CATEGORY_ID)

 

you'll recive an random image of one nested produkt. If theres no produkt in that category, there will be searched in all sub-categorys until an produkt is found.

 

If theres no produkt found, it wil retun 'empty.gif'

MS2

Link to comment
Share on other sites

could you tell me or write in the contrib page what is the fix that u added ?

 

by the way is there any way to fix this problem

 

1.i f got a category witouht image , and 6 sub categories with only 2 containing a product with image , can you change your algorythm so that that it would show randomly only the images of product existing , and not showing the "nopic" photo if he randomly chose a category with product haing no image shown ?

 

The script would then always show an image for the category even if there is 100 sub categories , and only one product with an image , and if really no subcategories got any product with image then it shows the nopic.jpg photo ... :rolleyes: a

 

2. when i category containing product with and without image and in their description links to video embedded , then the shop crash blank page :(

 

hope there could be improvement

MS2

Link to comment
Share on other sites

1.i f got a category witouht image , and 6 sub categories with only 2 containing a product with image , can you change your algorythm so that that it would show randomly only the images of product existing , and not showing the "nopic" photo if he randomly chose a category with product haing no image shown ?

 

This should work in the version 1.3, added to day.

 

3. how can we change the path for he empty image using variable like DIR_FS_CATALOG ?

 

Should work, but i did' not try.

 

Greats

Link to comment
Share on other sites

for the product with no pic that contain a embeded link to a video , any idea what can be the problem ?

 

and i couldnt edit my previous post so here is it modified :

 

seems that the code is really better , i got less often the empty image shown than before but why it still sometimes show the empy.jpg image when there are 750 product with image in the subcategories and only 30 whithout image ? I renember of incresing the value of a variable for making the script search more for a pic even if it takes longer sometime to get the image ... if it s a loop then maybe the loop can be stopped as soon as the image is found ... any idea ?

 

and for the define for the emty image that should do it.

Edited by azer

MS2

Link to comment
Share on other sites

  • 2 months later...

Excelent Contribution!!!!

Is there any way to change the probability that the random image selected were more frecuently for the products with best sellers. I mind for example:

 

Category 1

SubCat 1a

Prod-A------>100 solds ------>probability of this image 100x3/100=3

Prod-B------> 50 solds ------->probability of this image 50x3/100=1,5

SubCat 1b

Prod-C------> 10 solds------->probability of this image 10x3/100=0,3

 

Its a little confusing and propably need a math concepts. But with this kind of selectivity you can have an atractiv showcase without allways the same image but the more atractive or desired product, so more probability clicks on it.

 

Only is a sugestion.

But if you want I can study the way to do that calcs for choose with more probability the images with best sellers.

Link to comment
Share on other sites

Hello!!!

 

I have changed the query's function of get_random_cat_image to that:

$produkt_query = tep_db_query( "select distinct p.products_image as img ".

"from products p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c ".

"where p.products_id = pd.products_id and ".

"p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and '" . $category_id . "' in (c.categories_id, c.parent_id) ".

"order by pd.products_viewed desc, pd.products_name limit 10");

 

Then the showcase is a selection of the most viwed products images, and causes more impact.

 

But there is a little problem: I have some products repeted on some categories and sometimes the images are repeated. How can I do to solve that?

Sorry but maybe is a little dummy question because I'm a newbie at php.

 

Thank you.

Link to comment
Share on other sites

  • 10 months later...

Im having a strange problem with this contrib, it all appears to be working except when certain categories are enabled it halts on the category above it and willl not display any other categories below.

 

I.E Automotive

cat A (enabled) -> Shows in list

cat B (enabled) -> Shows in list

cat C (enabled) -> does not show

cat D (enabled) -> does not show

 

bit if i disable cat C

 

cat A (enabled) -> Shows in list

cat B (enabled) -> Shows in list

cat C (Disabled) -> does not show

cat D (enabled) -> Shows in list

 

I have checked for illegal characters in category names and product names and all seem ok

 

If somebody has any ideas i would be greatful

Link to comment
Share on other sites

  • 11 months later...

I have installed this contrib as it is exactly what I was look for to handle the categories images, but I get the "Call to undefined function get_random_cat_image()" on the page all the time. I have put the random_cat_images.php file in the includes dir and edited the index.php exactly as described. I'm a bit of a noob to this so have no idea how to resolve. Any suggestions would be gratefully received.

 

Thanks in advance.

Link to comment
Share on other sites

  • 1 year later...

I have installed it and it works like a charm!

 

Thank you for adding this feature to oscommerce - keeps the site looking fresh.

 

I do need help with one thing.

 

I have just used Easy Populate to upload 2500+ products to the shop. (Nice!)

The upload included all of the filenames for the images.

The images will be uploaded one at a time as the pictures are taken!!

The products are all flagged as inactive.

 

Is there a way to have the Random Catagory Image script - only show ACTIVE products?

 

Maybe a small change to the way the images are retrieved from the database?

 

It will let me take the site live a lot sooner if I can continue to show random catagory images from ACTIVE products only.

 

Thank you in advance for your help.

 

Robin

Edited by beatznbleepz
Link to comment
Share on other sites

  • 9 months later...

I have installed this contrib as it is exactly what I was look for to handle the categories images, but I get the "Call to undefined function get_random_cat_image()" on the page all the time. I have put the random_cat_images.php file in the includes dir and edited the index.php exactly as described. I'm a bit of a noob to this so have no idea how to resolve. Any suggestions would be gratefully received.

 

Thanks in advance.

 

 

I know this thread is old but the reason why the fatal error happens is because of the short open php tag <? instead of <?php at the start of includes/random_cat_images.php incase anyone wonders why you also see the raw contents of that file on index.php in XAMPP or similar as I solved this earlier today myself.

Edited by chrish123
Link to comment
Share on other sites

  • 8 months later...

Hi, Im wondering how to add the ability to select the random image only from active products? I think it can be done by modifying $produkt_query to include only products_status with a value of 1 , but Im unsure of the MySql syntax. Here is the entire file from the contribution, can anyone help ?

 

Here is the specific query I was thinking needs to be modified.

$produkt_query = tep_db_query( "select p.products_image as img from products p ".
  "LEFT OUTER JOIN products_to_categories ptc ON ".
  "p.products_id = ptc.products_id ".
  "WHERE LENGTH(p.products_image) > 0 ".
  "AND ptc.categories_id = ".$category_id);

 

and the next piece is the entire contribution, in case there is more to this than I realize.

 

Thank you

 

<?
/***********************************************/
/*    Random Category Images v 1.3  /
/*    coded    /
/*		 by Bo Biene   /
/***********************************************/
define('EMPTY_CAT_IMAGE', 'empty.gif');

function get_random_cat_image($category_id, $count = 0)
{
srand ((double)microtime()*1000000);
$retun_val;
if($category_id > 0 && tep_count_products_in_category_without_sub($category_id) > 0 && $count < 10)
{

 $randInt = rand(1,10);
 $randStart = $randInt -1;
 $produkt_query = tep_db_query( "select p.products_image as img from products p ".
  "LEFT OUTER JOIN products_to_categories ptc ON ".
  "p.products_id = ptc.products_id ".
  "WHERE LENGTH(p.products_image) > 0 ".
  "AND ptc.categories_id = ".$category_id);

 while($result = tep_db_fetch_array($produkt_query))
 {
  $retun_val = $result['img'];
  if(rand(1,10) > 8)
   break;
 }

 if(!(tep_not_null($retun_val)) &&  tep_has_category_subcategories($category_id))
 {
  $retun_val = get_random_cat_image_from_child($category_id,$count);
 }

}
else if($category_id > 0 && tep_has_category_subcategories($category_id) && $count < 10)
{

 $retun_val = get_random_cat_image_from_child($category_id,$count);
}
else
{
 $retun_val = EMPTY_CAT_IMAGE;
}

return $retun_val;
}
function get_random_cat_image_from_child($category_id,$count = 0)
{
$retun_val;
$category_query = tep_db_query("select categories_id as ID from ". TABLE_CATEGORIES ." WHERE parent_id = ". $category_id ." LIMIT 0,". rand(1,10) );
while($ids = tep_db_fetch_array($category_query))
{
 $id = $ids['ID'];

 $retun_val = get_random_cat_image($id, $count++);
 if((tep_not_null($retun_val)) && $retun_val != EMPTY_CAT_IMAGE)
  break;
}
return $retun_val;
}
//Changed from osCommerce
 function tep_count_products_in_category_without_sub($category_id, $include_inactive = false)
 {
   $products_count = 0;
   if ($include_inactive == true) {
  $products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$category_id . "'");
   } else {
  $products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p.products_status = '1' and p2c.categories_id = '" . (int)$category_id . "'");
   }
   $products = tep_db_fetch_array($products_query);
   return $products['total'];
}

?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...