Jump to content

Featured/Random Product


Guest AlienX

Recommended Posts

Guest AlienX

Greetings!

I hope this is the right place to ask this question...

I am currently customizing my store, and what I want to do is to put the Featured Product in between the Welcome Message (at the Home Page) and Latest Products. I tried editing the file index.tpl under the styleTemplates/content folder and made it as shown below:

<!-- BEGIN: index -->

<div class="boxContent">

<!-- span class="txtContentTitle">{HOME_TITLE}</span>

<br / -->

{HOME_CONTENT}<br />

{RANDOM_PROD}<br />

{}

</div>

<!-- BEGIN: latest_prods -->

	<div class="boxContent">

	<span class="txtContentTitle">{LANG_LATEST_PRODUCTS}</span>

		<div style="margin-top: 10px;">

		<!-- BEGIN: repeat_prods -->

			<div class="latestProds">

				<a href="index.php?act=viewProd&amp;productId={VAL_PRODUCT_ID}"><img src="{VAL_IMG_SRC}" alt="{VAL_PRODUCT_NAME}" border="0" title="{VAL_PRODUCT_NAME}" /></a>

				<br />

				<a href="index.php?act=viewProd&amp;productId={VAL_PRODUCT_ID}" class="txtFeaturedproduct">{VAL_PRODUCT_NAME}</a>

				<br /> 

				<span class="txtOldPriceWord">Reg: {TXT_PRICE}</span>

				<br />

				<span class="txtSale">Now: {TXT_SALE_PRICE}</span>

			</div>

		<!-- END: repeat_prods -->

		<br clear="all" />

		</div>

		<br clear="all" />

		

		

	</div>

<!-- END: latest_prods -->

<!-- END: index -->

But nothing is displayed.

Any help will be greatly appreciated. Thanks in advanced!

God bless you all!

.alienx

Link to comment
Share on other sites

I've seen this request before somewhere ;) Had no time to answer. I come here to take a quick break from actual work, but wow so busy with too much work can't always take a moment to answer especially not when there is no good answer. :sourcerer:

What you are attempting to do is not easily done. The random prods are coded as a box, and therefore assigned to global/index.tpl, not to content/index.tpl, that is why the tag will not work in there.

Putting random prod above welcome message, or below latestt prods, is easily done in global/index.tpl but putting it between the two is probematic. That's why you are not getting much respoonse on your posts about this.

Link to comment
Share on other sites

Guest AlienX

Ok... I made it! :huh:

And for those who might as well need it here's what I did...

1. Open the file skins/your_skin/styleTemplates/content/index.tpl and add the following lines in between </div> of {HOME_CONTENT} and <!-- BEGIN: latest_prod -->

<!-- BEGIN: random_prod -->

<div class="boxTitleRight">{LANG_RANDOM_PRODUCT}</div>

<div class="boxContentLeft" style="text-align: center">

	<a href="index.php?act=viewProd&amp;productId={RP_PRODUCT_ID}" title="{RP_PRODUCT_NAME}"><img src="{RP_IMG_SRC}" alt="{RP_PRODUCT_NAME}" border="0" title="{RP_PRODUCT_NAME}" /></a>

	<br />

	<span class="txtCopy"><a href="index.php?act=viewProd&amp;productId={RP_PRODUCT_ID}" title="{RP_PRODUCT_NAME}" class="txtDefault">{RP_PRODUCT_NAME}</a></span>

</div>

<!-- END: random_prod -->




2. Now, open the file includes/content/index.inc.php and place the following code after the line $index->assign("HOME_CONTENT",stripslashes($home['copy']));




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

$seed = mt_rand(1,10000);



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

	

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



} else {



	$whereClause = "";



}



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

 

if($randProd==TRUE){



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

			

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

		

		}

	

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

	$index->assign("RP_PRODUCT_ID",$randProd[0]['productId']);

	$index->assign("RP_PRODUCT_NAME",validHTML($randProd[0]['name']));

	

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

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

	} else {

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

	}

	

	$index->parse("index.random_prod");



} else {



	//DO NOTHING

	

}

3. Save your modifications, and now you're done. View your home page and see what happens!

Works for me... There are some lines that I doubt should still be there, any comment to make the code neater and more efficient will be greatly appreciated. Hope this will help others here. And thanks for the reply/replies.

God bless you all!

Best regards,

.alienx

Link to comment
Share on other sites

  • 2 months later...

Good Job Only Thing is That How to make it Show Like 6 or 9 Product not only One and also how to Remove That Bg under Featuerd Product and To Write same way its for Latest Pruduct to make it For Featured Producet without the Bg border this is good..

Ok... I made it! :o

And for those who might as well need it here's what I did...

1. Open the file skins/your_skin/styleTemplates/content/index.tpl and add the following lines in between </div> of {HOME_CONTENT} and <!-- BEGIN: latest_prod -->

<!-- BEGIN: random_prod -->

<div class="boxTitleRight">{LANG_RANDOM_PRODUCT}</div>

<div class="boxContentLeft" style="text-align: center">

	<a href="index.php?act=viewProd&amp;productId={RP_PRODUCT_ID}" title="{RP_PRODUCT_NAME}"><img src="{RP_IMG_SRC}" alt="{RP_PRODUCT_NAME}" border="0" title="{RP_PRODUCT_NAME}" /></a>

	<br />

	<span class="txtCopy"><a href="index.php?act=viewProd&amp;productId={RP_PRODUCT_ID}" title="{RP_PRODUCT_NAME}" class="txtDefault">{RP_PRODUCT_NAME}</a></span>

</div>

<!-- END: random_prod -->




2. Now, open the file includes/content/index.inc.php and place the following code after the line $index->assign("HOME_CONTENT",stripslashes($home['copy']));




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

$seed = mt_rand(1,10000);



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

	

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



} else {



	$whereClause = "";



}



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

 

if($randProd==TRUE){



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

			

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

		

		}

	

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

	$index->assign("RP_PRODUCT_ID",$randProd[0]['productId']);

	$index->assign("RP_PRODUCT_NAME",validHTML($randProd[0]['name']));

	

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

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

	} else {

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

	}

	

	$index->parse("index.random_prod");



} else {



	//DO NOTHING

	

}

3. Save your modifications, and now you're done. View your home page and see what happens!

Works for me... There are some lines that I doubt should still be there, any comment to make the code neater and more efficient will be greatly appreciated. Hope this will help others here. And thanks for the reply/replies.

God bless you all!

Best regards,

.alienx

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