Jump to content

Move "latest Products" Into Its Own Box.


Guest Compucast

Recommended Posts

Guest Compucast

I've inherited a partially built CubeCart store from another (now former) employee who said he was a CubeCart expert but really wasn't. To save face, and keep the customer happy, I need a quick fix. I'm a long-time web programmer, and have worked with several other cart/template systems - but this is my first Cube experience. Any help would be greatly appreciated.

The design calls for "featured products" to appear at the bottom of every page in the store. I've decided that repurposing the "latest products" is the best way to achieve this quickly. (if someone else can suggest a better way, I'm certainly open)

Following the helpful directions in some other posts about creating CUSTOM_BOX - I have done the following:

1) added to /index.php:

include("includes/boxes/latest.inc.php");

$body->assign("LATEST",$box_content)

2) created includes/boxes/latest.inc.php - adding the SQL query, and everything in the "if($config['showLatestProds']==1 && $latestProducts==TRUE){" block from the content/index.inc.php file - which is how "latest" gets its data...

<?php

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



$latestProducts = $db->select("SELECT productId, image, price, name, sale_price FROM ".$glob['dbprefix']."CubeCart_inventory WHERE `showFeatured` = 1 ORDER BY productId DESC LIMIT ".$config['noLatestProds']);



if($config['showLatestProds']==1 && $latestProducts==TRUE){

		for($i=0;$i<count($latestProducts);$i++){

				if(($val = prodAltLang($latestProducts[$i]['productId'])) == TRUE){

								$latestProducts[$i]['name'] = $val['name'];

				}

				if(file_exists($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$latestProducts[$i]['image'])){

						$box_content->

assign("VAL_IMG_SRC",$GLOBALS['rootRel']."images/uploads/thumbs/thumb_".$latestProducts[$i]['image']);

				} else {

						$box_content->

assign("VAL_IMG_SRC",$GLOBALS['rootRel']."skins/".$config['skinDir']."/styleImages/thumb_nophoto.gif");

				}

				$box_content->assign("LANG_LATEST_PRODUCTS",$lang['front']['index']['latest_products']);

		

				if(salePrice($latestProducts[$i]['price'], $latestProducts[$i]['sale_price'])==FALSE){

						$box_content->assign("TXT_PRICE",priceFormat($latestProducts[$i]['price']));

				} else {

						$box_content->assign("TXT_PRICE","<span class='txtOldPrice'>".priceFormat($latestProducts[$i]['price'])."</span>");

				}

				$salePrice = salePrice($latestProducts[$i]['price'], $latestProducts[$i]['sale_price']);

				$box_content->assign("VAL_WIDTH", $config['gdthumbSize']+75);

				$box_content->assign("TXT_SALE_PRICE", priceFormat($salePrice));

				$box_content->assign("VAL_PRODUCT_ID",$latestProducts[$i]['productId']);

				$box_content->assign("VAL_PRODUCT_NAME",validHTML($latestProducts[$i]['name']));

		}

}

$box_content->parse("latest_prods");

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

$box_content.=count($latestProducts); // debugging output

?>




3) created a styleTemplates/boxes/latest.tpl file, consisting of the BEGIN ... END of "latest_prods" - ripped directly from the index.tpl file...


<!-- BEGIN: latest_prods -->

		<div class="boxContent">

		<span class="txtContentTitle">Featured Products & Specials</span>

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

				<!-- BEGIN: repeat_prods -->

						<div class="latestProds">

								<a href="index.php?act=viewProd&productId={VAL_PRODUCT_ID}"><img src="{VAL_IMG_SRC}" alt="{VAL_PRODUCT_NAME}" bor$

								<br />

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

								<br />

								{TXT_PRICE} <span class="txtSale">{TXT_SALE_PRICE}</span>

						</div>

				<!-- END: repeat_prods -->

				<br clear="all" />

				</div>

				<br clear="all" />

		</div>

<!-- END: latest_prods -->




4) Inserted the appropriate {LATEST} macro where I want the new box to appear - in globals/index.tpl


...

<div id="display">

{PAGE_CONTENT}

</div>

...

<div id="r-featured"><br>

{LATEST}

</div>

I can in fact see that $latestProducts in fact gets results from the SQL - the number of latest products is displayed. But no products actually appear in my new box. I left the existing code in the "index.inc.php" - and it is still working.

So I'm sure that I'm missing some minor but important detail. Can anyone point me in the right direction?

Link to comment
Share on other sites

Guest Compucast

You've gone into the ACP and made the appropriate entries on the General Settings page for "Latest Products" and "Number of Popular Items" and so forth? And you have turned off "Show Stock"?

Even though it didn't seem likely to change anything, based on your post I played with those settings. Unfortunately that's not the quick fix for me. It was worth a shot though. Thank you.

Since it may help to illustrate, I have attached a screen capture (cropped and highly compressed) showing what I see. The "Latest Products" area is part of the global index.tpl (stock CubeCart) and shows two sample products. It works great. The "Featured Products & Specials" is my custom box, and doesn't show any products. The "2" underneath the left side of that box is the debugging output, saying "there are 2 products that should be appearing" - but they are not visible.

The debugging code (printing out the number of products) behaves as expected - in fact, I can do something a little more drastic in the latest.inc.php:

print "<pre>";

print_r($latestProducts);

exit;




This shows exactly the results I would expect from the query...


Array

(

	[0] => Array

		(

			[productId] => 2

			[image] => ellipsoid.png

			[price] => 9.99

			[name] => Another Test

			[sale_price] => 0.00

		)



	[1] => Array

		(

			[productId] => 1

			[image] => cylinder.png

			[price] => 10.00

			[name] => Test Product

			[sale_price] => 6.99

		)



)

But the "final" results don't appear in my custom box. It's like the template isn't getting "filled in" the way I would expect. Like I said, I'm sure this is a simple thing.

Link to comment
Share on other sites

  • 3 weeks later...
Guest Compucast

The problem has been resolved. When I cut-and-pasted into latest.inc.php, I omitted a very important line...

$box_content->parse("latest_prods.repeat_prods");

So basically, the template didn't get called up for each product in the list - which was exactly the behavior I was seeing.

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