Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Random Image or Random Products - Category Specific

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #11  
Old 01-20-2006, 08:35 AM
  moneysaver67's Avatar 
moneysaver67 moneysaver67 is offline
 

Advanced Member
  
Join Date: Nov 2005
Posts: 74
 

Default NightFire 50% Answer

Quote:
Originally Posted by NightFire
Got a question about the random images. Is it also possible to include the product title above the random image? And maybe the product price. That would be very nice.

As for the title, that's an easy one...

Go to random_image.tpl and add the following line above (or within) the a href= tag...


Just guessing, but I assumed the rand was returning outside the bounds of $config.Modules.number_of_randomproducts

Sure enough, this occurred as I had expected.
$config.Modules.number_of_randomproducts was set to 3, and occassionaly $rand resulted as 3, but arrays are an option base 0, so 3 is outside of the boundaries. To modify my above temporary fix, I account for this, and subtract 1 if necessary, resulting in the following:

Code:
{assign var="rand" value="0"|mt_rand:$config.Modules.number_of_randomproducts} {if $rand eq $config.Modules.number_of_randomproducts} {math assign="rand" equation="x-1" x=$rand} {/if} {$r_products[$rand].product} <a href=product.php?productid={$r_products[$rand].productid}>{include file="product_thumbnail.tpl" productid=$r_products[$rand].productid image_x=$config.Appearance.thumbnail_width product=$r_products[$rand].product tmbn_url=$r_products[$rand].tmbn_url}</a>
__________________
X-Cart 4.0.16-.19 Gold [unix] / DSEFU
Reply With Quote
  #12  
Old 01-20-2006, 10:10 AM
  TelaFirma's Avatar 
TelaFirma TelaFirma is offline
 

X-Adept
  
Join Date: Nov 2002
Location: North Carolina USA
Posts: 930
 

Default

You are correct about the array and sometimes it will generate a random number outside the array limits. I corrected my post. All that was necessary was to change the assign to :

Code:
{assign var="rand" value="0"|mt_rand:"`$config.Modules.number_of_randomproducts-1`"}

Good catch.
Reply With Quote
  #13  
Old 01-20-2006, 10:42 AM
  NightFire's Avatar 
NightFire NightFire is offline
 

X-Adept
  
Join Date: Jul 2004
Location: The Netherlands
Posts: 561
 

Default

It's working great. Thanks for the fixes.
Another question. The random image is displaying the thumbnail size which is set under the general settings. But is it also possible to change this image size in the random_image.tpl so that it has a custom size? The products wich are displayed in the categories will still have their original size then.


Edit: Found a bug in the random image script. I placed the random image script on the homepage. But when you click on the product you'll be redirected to the product page. But the place where the random image script, is displaying no image availlable and it isn't displaying a product title. And it redirects me to this when I click on it:
www.shopurl.com/shop/image.php?productid=
Hope someone find a solution for this.
__________________
Best regards,
Niki Buitenrust Hettema

X-Cart Gold 4.1.8 (Live & Loaded)
Royal Bhaktapur: Handmade products from Nepal - Pashmina's, scarfs, shawls, stola's and more...
Reply With Quote
  #14  
Old 01-23-2006, 07:09 AM
  moneysaver67's Avatar 
moneysaver67 moneysaver67 is offline
 

Advanced Member
  
Join Date: Nov 2005
Posts: 74
 

Default

Quote:
Originally Posted by NightFire
But the place where the random image script, is displaying no image availlable and it isn't displaying a product title. And it redirects me to this when I click on it:
www.shopurl.com/shop/image.php?productid=
Hope someone find a solution for this.

NightFire,

This is the same error that we were speaking about above (Prev 2 Posts) Please implement the fix to correct this.
__________________
X-Cart 4.0.16-.19 Gold [unix] / DSEFU
Reply With Quote
  #15  
Old 01-25-2006, 12:19 PM
 
sandersdesign sandersdesign is offline
 

Member
  
Join Date: Oct 2005
Posts: 26
 

Default

hi, I seem to be having problems with implementing this mod. please visit http://www.digi-quick.com/error_message.php?access_denied&id=33


home.tpl
Code:
<?php if ($active_modules["Random_Products"]) include $xcart_dir."/modules/Random_Products/random.php"; ?> {include file="modules/Random_Products/random.tpl"} {include file="modules/Random_Products/random_image.tpl"}


random.php
Code:
<?php # # $Id: random.php,v 1.00.0.0 0 TelaFirma $ # # Random Products # if (!defined('XCART_SESSION_START')) { header("Location: ../../"); die("Access denied"); } if (!is_numeric($config["Modules"]["number_of_randomproducts"])) $config["Modules"]["number_of_randomproducts"] = 0; # # Get products data for current category and store it in an array # $cat = intval($cat); if ($cat) { $category_data = func_query_first("SELECT categoryid_path FROM $sql_tbl[categories] USE INDEX (PRIMARY) WHERE categoryid='$cat'"); $result = func_query("SELECT categoryid FROM $sql_tbl[categories] USE INDEX (pam) WHERE categoryid_path LIKE '$category_data[categoryid_path]/%' AND avail='Y'"); $cat_ids = array(); if (is_array($result)) { foreach($result as $k=>$v) { $cat_ids[] = $v["categoryid"]; } } else $cat_ids[] = $cat; $str = " AND $sql_tbl[products_categories].categoryid IN (".implode(",", $cat_ids).")"; } $order_by = "RAND()"; $search_query = $str; # # Search the products # $randoms = func_search_products($search_query, @$user_account["membership"], $order_by, $config["Modules"]["number_of_randomproducts"]); $smarty->assign("r_products",$randoms); ?>


random.tpl

Code:
{capture name=dialog} {if $r_products ne ""} {include file="customer/main/products.tpl" products=$r_products} {/if} {/capture} {include file="dialog.tpl" content=$smarty.capture.dialog extra="width=100%"}

random_image.tpl
Code:
{assign var="rand" value="0"|mt_rand:"`$config.Modules.number_of_randomproducts-1`"} {$r_products[$rand].product} <a href=product.php?productid={$r_products[$rand].productid}> {include file="product_thumbnail.tpl" productid=$r_products[$rand].productid image_x=$config.Appearance.thumbnail_width product=$r_products[$rand].product tmbn_url=$r_products[$rand].tmbn_url}</a>
__________________
www.sandersdesign.net
X-Cart Gold v4.0.16, Unix
Reply With Quote
  #16  
Old 01-25-2006, 12:22 PM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default

Look at the install instructions again....you have some php referenced in home.tpl when it should be in home.php.
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #17  
Old 01-25-2006, 01:48 PM
 
sandersdesign sandersdesign is offline
 

Member
  
Join Date: Oct 2005
Posts: 26
 

Default

thanks balinor, I've got it to work now.

only thing is that it's not really what I was looking for. I was trying to figure out a way adapt the 'Featured Products' tools so that it only shows random products from specified categories. Has such a mod been developed.

Thanks for any help.
__________________
www.sandersdesign.net
X-Cart Gold v4.0.16, Unix
Reply With Quote
  #18  
Old 01-25-2006, 01:51 PM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default

That is exatly what this does?
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #19  
Old 01-28-2006, 09:56 AM
  moneysaver67's Avatar 
moneysaver67 moneysaver67 is offline
 

Advanced Member
  
Join Date: Nov 2005
Posts: 74
 

Default What about disabled categories?

TelaFirma,

This is a sweet Mod, Tela! Wanted to point out that another thing that I also noticed is that the random image returned sometimes returns images from DISABLED categores. This is not ideal, at least for our shop.

I'm sure I could correct this, but reviewing func_search_products within func.php didn't lead me to any 'smoking gun' right off the bat, anyhow...

Don't know if you were aware of this...
__________________
X-Cart 4.0.16-.19 Gold [unix] / DSEFU
Reply With Quote
  #20  
Old 01-28-2006, 09:58 AM
  moneysaver67's Avatar 
moneysaver67 moneysaver67 is offline
 

Advanced Member
  
Join Date: Nov 2005
Posts: 74
 

Default

Quote:
Originally Posted by sandersdesign
I was trying to figure out a way adapt the 'Featured Products' tools so that it only shows random products from specified categories.

Isn't it just a matter of placing this on one of your category pages?

Code:
# # Get products data for current category and store it in an array # $cat = intval($cat); if ($cat) { $category_data = func_query_first("SELECT categoryid_path FROM $sql_tbl[categories] USE INDEX (PRIMARY) WHERE categoryid='$cat'"); $result = func_query("SELECT categoryid FROM $sql_tbl[categories] USE INDEX (pam) WHERE categoryid_path LIKE '$category_data[categoryid_path]/%' AND avail='Y'"); ...
__________________
X-Cart 4.0.16-.19 Gold [unix] / DSEFU
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 01:03 AM.

   

 
X-Cart forums © 2001-2020