X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Random Image or Random Products - Category Specific (https://forum.x-cart.com/showthread.php?t=17659)

moneysaver67 01-20-2006 08:35 AM

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>


TelaFirma 01-20-2006 10:10 AM

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.

NightFire 01-20-2006 10:42 AM

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.

moneysaver67 01-23-2006 07:09 AM

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.

sandersdesign 01-25-2006 12:19 PM

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>


balinor 01-25-2006 12:22 PM

Look at the install instructions again....you have some php referenced in home.tpl when it should be in home.php.

sandersdesign 01-25-2006 01:48 PM

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.

balinor 01-25-2006 01:51 PM

That is exatly what this does?

moneysaver67 01-28-2006 09:56 AM

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

moneysaver67 01-28-2006 09:58 AM

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'");

...



All times are GMT -8. The time now is 07:08 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.