Jump to content

Featured Product


Guest GoodLiteCandles

Recommended Posts

Guest GoodLiteCandles

Right now on my cart the featured product randomizes and a different image/item shows up each time the page changes/refreshes.

What I want is to specify one featured product and have it stay there until I take it off or change it to a new item that I want featured.

Is this possible? And how do I do this?

Also, when I dont want a featured product at the moment do I just take it out of the index.tpl and put it back in when I want a featured product again?

I'd appreciate any input you can give me. Thanks.

Link to comment
Share on other sites

You're right, "featured product" actually means "random product" . . . no way to specifiy a static product without changing the code.

To temporarily remove, just place the HTML comment tags ( <!-- and --> ) befor and after the Featured product variable {RANDOM_PROD} in global/index.tpl:

<!-- RANDOM_PROD -->

Just remove the comment tags to turn it back on.

Link to comment
Share on other sites

I love easy solutions!

In /includes/boxes/randomProd.inc.php

Insert the following "whereClause" before the DB Select line as such:

#############################################################################

## Manually specified product for "Featured Product"

## Simply put the id of the product in the variable assignment below:

$whereClause = "productId = '##'";



$randProd= $db->select("SELECT name, image, productId FROM ".$glob['dbprefix']."CubeCart_inventory ".$whereClause." ORDER BY RAND(".$seed.") LIMIT 1");

You'll see an IF > THEN > ELSE statement above this that sets the whereClause...leave it alone. Put the lines between the IF block and the $randProd = lines.

That will take care of it for you. :)

Link to comment
Share on other sites

Guest GoodLiteCandles

MySQL Error Occured

1064: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '= '3' ORDER BY RAND(2107) LIMIT 1' at line 1

QUERY = SELECT name, image, productId FROM CubeCart_inventory productId = '3' ORDER BY RAND(2107) LIMIT 1

That's the error I got.

I copied the code exactly where you told me to. And then i changed the ## to 3. I got the 3 from the id in my view items screen. Was that correct to do?

Link to comment
Share on other sites

Guest GoodLiteCandles

Okay it doesnt give me any errors now (yay!)

But it still changes the product each time I click on a category link or a specific product.

Link to comment
Share on other sites

Guest GoodLiteCandles

We're getting closer.

That works when I open the cart and am on the homepage or when I click the homepage link. It always loads the product I specified.

But when I click on each product caregory link, the Featured Product changes to a product in the link's category.

Is there a way to just set up that with each link I click, the featured product stays the same.

I only want one featured product.

Thanks.

Link to comment
Share on other sites

Hmmm....it shouldn't do that. Paste your randomProd.inc.php in a box here (you can leave off the comment header if you like). I'll look to see if there's anything out of place. :w00t:

Link to comment
Share on other sites

Guest GoodLiteCandles

Thank you so much for helping me.

Here's the code...

<?php

if(!isset($config)){

	echo "<html>\r\n<head>\r\n<title>Forbidden 403</title>\r\n</head>\r\n<body><h3>Forbidden 403</h3>\r\nThe document you are requesting is forbidden.\r\n</body>\r\n</html>";

	exit;

}



mt_srand ((double) microtime() * 1000000); 

$seed = mt_rand(1,10000);



if(isset($_GET['catId'])){

	

	$whereClause = "WHERE cat_id=".$db->mySQLSafe($_GET['catId']);



} else {



$whereClause = "WHERE productId = '7'";





}



$randProd= $db->select("SELECT name, image, productId FROM ".$glob['dbprefix']."CubeCart_inventory ".$whereClause);

 

if($randProd==TRUE){



  if(($val = prodAltLang($randProd[0]['productId'])) == TRUE){

  	

  	$randProd[0]['name'] = $val['name'];

  

  }



	$box_content=new XTemplate ("skins/".$config['skinDir']."/styleTemplates/boxes/randomProd.tpl");

	

	$box_content->assign("LANG_RANDOM_PRODUCT",$lang['front']['boxes']['featured_prod']);

	$box_content->assign("PRODUCT_ID",$randProd[0]['productId']);

	$box_content->assign("PRODUCT_NAME",$randProd[0]['name']);

	

	if(!empty($randProd[0]['image'])){

  $box_content->assign("IMG_SRC","images/uploads/thumbs/thumb_".$randProd[0]['image']);

	} else {

  $box_content->assign("IMG_SRC","skins/".$config['skinDir']."/styleImages/thumb_nophoto.gif");

	}

	

	$box_content->parse("random_prod");

	

	$box_content = $box_content->text("random_prod");



} else {



	$box_content = "";

	

}

?>

Link to comment
Share on other sites

I thought this was your problem....

if(isset($_GET['catId'])){



$whereClause = "WHERE cat_id=".$db->mySQLSafe($_GET['catId']);



} else {



$whereClause = "";



}



#############################################################################

## Manually specified product for "Featured Product"

## Simply put the id of the product in the variable assignment below:

$whereClause = "WHERE productId = '7'";



$randProd= $db->select("SELECT name, image, productId FROM ".$glob['dbprefix']."CubeCart_inventory ".$whereClause);

You weren't supposed to touch the existing if / else statement but add my code below it. I thought I was right the first time. :D

:w00t:

Link to comment
Share on other sites

Ok, I figure that qualifies as Idiot of the Month... I was putting in my Product Code Number, Not the ID number! It was working correctly as the Product Code is 5 digits long, and the ID numbers are in the double digits only, so it was saying, "Hey, no such product, we don't show it!" Took me a few to figure out what was happening, but I'm persistent...

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