Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Weird Question - Adding search capability to new_prudcts.php -


Guest

Recommended Posts

Like the topic said, what I really want to do is have 6 products listed on one page on my new_products and just like on the product listing page for customers to be able to click on for example page 2,3,4 and see other new products. Can this be done? Create multiple pages for the new_products listing? Any help would be VERY appreciated, this is the last thing that needs to be done before my shop is finished.

 

 

I experimented by adding something like this to my new_prorducts page but it doesn't seem to work (code was taken from the products_listing page):

 

$listing_split = new splitPageResults($listing_sql, MAX_DISPLAY_SEARCH_RESULTS, 'p.products_id');

 

if ( ($listing_split->number_of_rows > 0) && ( (PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3') ) ) {

Link to comment
Share on other sites

you will have to pass the queries strings into the splitpageresults class. By default the new_products.php module uses the queries directly. So you need to remove the tep_db_query and leave just the string. That string you then pass to the splitpageresults class.

 

So for instance the query code in your new_products.php should look like:

if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
$listing_sql = "select p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS;
 } else {
$listing_sql = "select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . (int)$new_products_category_id . "' and p.products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS;
 }

$listing_split = new splitPageResults($listing_sql, MAX_DISPLAY_SEARCH_RESULTS, 'p.products_id');

 

and then you use the $listing_split->sql_query to fetch the rows.

Link to comment
Share on other sites

Like the topic said, what I really want to do is have 6 products listed on one page on my new_products and just like on the product listing page for customers to be able to click on for example page 2,3,4 and see other new products. Can this be done? Create multiple pages for the new_products listing? Any help would be VERY appreciated, this is the last thing that needs to be done before my shop is finished.

I experimented by adding something like this to my new_prorducts page but it doesn't seem to work (code was taken from the products_listing page):

 

$listing_split = new splitPageResults($listing_sql, MAX_DISPLAY_SEARCH_RESULTS, 'p.products_id');

 

if ( ($listing_split->number_of_rows > 0) && ( (PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3') ) ) {

 

Hi -

 

Which file specifically you are trying to manipulate to do this ?

/includes/modules/new_products.php ?

 

Corrie

Link to comment
Share on other sites

Hi -

 

Which file specifically you are trying to manipulate to do this ?

/includes/modules/new_products.php ?

 

Corrie

 

new_products.php that's right. Thank you enigma for the answer but I am still a little confused. Where do I use the$listing_split->sql_query exactly? I really do appreciate your help!

Link to comment
Share on other sites

new_products.php that's right. Thank you enigma for the answer but I am still a little confused. Where do I use the$listing_split->sql_query exactly? I really do appreciate your help!

 

 

You need to *replace* the existing query with the listing query. There is only one loop in this file - you need to make the replacment in the else loop.

 

Change this :

} else {

$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . (int)$new_products_category_id . "' and p.products_status = '1' and p.products_date_expire > '" . date('Y-m-d') . "' and p.products_image <> 'NULL' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);

}

 

to this :

} else {

$listing_sql = "select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . (int)$new_products_category_id . "' and p.products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS;

}

 

david

Link to comment
Share on other sites

I've tried replacing just what you told me and it gives me an error:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /homepages/18/d93477801/htdocs/includes/functions/database.php on line 99

 

I've inserted my new_products code here so maybe somebody can help me a little bit more! Thank you, you've all been helpful so far.

 

 

 

 

<?php
/*
 $Id: new_products.php,v 2.0 2006/11/13 10:42:00 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 [url="http://www.oscommerce.com"]http://www.oscommerce.com[/url]

 Copyright © 2003 osCommerce

 Released under the GNU General Public License
*/

?>

<!-- new_products //-->
<?php

 if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
   $listing_sql = "select distinct p.products_id, p.products_quantity, p.products_image, p.products_model, p.products_tax_class_id, p.products_weight, if(s.status, s.specials_new_products_price, p.products_price) as products_price, mnf.manufacturers_name, rvw.reviews_rating from " . TABLE_PRODUCTS . " p left join ".TABLE_SPECIALS." s on p.products_id = s.products_id left join ".TABLE_MANUFACTURERS." mnf on p.manufacturers_id = mnf.manufacturers_id left join ".TABLE_REVIEWS." rvw on p.products_id = rvw.products_id where p.products_image !='' and p.products_status = '1' order by pd.products_name limit ".MAX_DISPLAY_NEW_PRODUCTS;
   $new_products_query = tep_db_query($sql);

} else {
$listing_sql = "select distinct p.products_id, p.products_quantity, p.products_image, p.products_model, p.products_tax_class_id, p.products_weight, if(s.status, s.specials_new_products_price, p.products_price) as products_price, mnf.manufacturers_name, rvw.reviews_rating from " . TABLE_PRODUCTS . " p left join ".TABLE_SPECIALS." s on p.products_id = s.products_id left join ".TABLE_MANUFACTURERS." mnf on p.manufacturers_id = mnf.manufacturers_id left join ".TABLE_REVIEWS." rvw on p.products_id = rvw.products_id where p.products_image !='' and p.products_status = '1' order by pd.products_name limit ".MAX_DISPLAY_NEW_PRODUCTS;
}
$listing_split = new splitPageResults($listing_sql, MAX_DISPLAY_SEARCH_RESULTS, 'p.products_id');


$row = 0;
 $col = 0;
 $info_box_contents = array();
 echo '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>';

 while ($new_products = tep_db_fetch_array($new_products_query)) {

 $new_products['products_name'] = tep_get_products_name($new_products['products_id']);

// setup names and variables to be used if no matching results are found
$reviews_rating = $new_products['reviews_rating'];
$manufacturers_name = $new_products['manufacturers_name'];
$products_model = $new_products['products_model'];

if(!$manufacturers_name==null) {
  $manufacturers_name = '<b>' . TABLE_HEADING_MANUFACTURER . '</b><br>' . $manufacturers_name;
} else {
  $manufacturers_name = '<b>' . TABLE_HEADING_MANUFACTURER . ' </b><br>None';
}

  if(!$products_model==null) {
  $products_model = '<b>' . TABLE_HEADING_MODEL . ':</b><br>' . $products_model;
} else {
  $products_model = '<b>' . TABLE_HEADING_MODEL . ': </b><br>None';
}

if(!$reviews_rating==null){
	$reviews_rating = '<img src="images/stars_'. $new_products['reviews_rating'].'.gif" alt="'.$new_products['reviews_rating'] . TABLE_HEADING_TEXT_OF_5_STARS . ' ('.$new_products['products_name'].')" border="0" align="absmiddle">';
} else {
	$reviews_rating = '<span class="smallText"><a href="product_reviews_write.php?products_id='.$new_products['products_id'].'" alt="' . TABLE_HEADING_FIRST_TO_RATE . '"><img src="images/stars_0.gif" alt="' . TABLE_HEADING_FIRST_TO_RATE . '" border="0" align="absmiddle"></a></span>';
}
// setup names and variables to be used if no matching results are found

// only display what is set in 'product listing'
if (IND_PRODUCT_LIST_IMAGE == "Yes") {
	$show['image'] = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . 
	$new_products['products_id']) . '">' . 
	tep_image(DIR_WS_IMAGES . $new_products['products_image'], 
	$new_products['products_name_full'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';

}
if (IND_PRODUCT_LIST_MANUFACTURER == "Yes") {
	$show['manufacturer'] = '
	<tr>
		<td height="17" class="smallText"><br>' . $manufacturers_name . '</td>
	</tr>';
}
if (IND_PRODUCT_LIST_MODEL == "Yes") {
	$show['model'] = '
	<tr>
		<td height="17" class="smallText"><br>' . $products_model . '</td>
	</tr>';
}
  if (IND_PRODUCT_LIST_QUANTITY == "Yes") {
	$show['quantity'] = '
	<tr>
		<td height="17" class="smallText">
			<b><br>' . TABLE_HEADING_QUANTITY . ':<br></b>' . 
			$new_products['products_quantity'] . 
		'</td>
	</tr> ';
}
  if (IND_PRODUCT_LIST_WEIGHT == "Yes") {
	$show['weight'] = '
	<tr>
		<td height="17" class="smallText">
			<b><br>' . TABLE_HEADING_WEIGHT . ':<br></b>' . 
			$new_products['products_weight'] . ' grams
		</td>
	</tr> ';
}
if (IND_PRODUCT_LIST_PRICE == "Yes") {
	$show['price'] = '
	<tr>
		<td height="17" class="smallText">
			<b><br>' . TABLE_HEADING_PRICE . ':<br><font color="#FF5C02">' . 
			$currencies->display_price($new_products['products_price'],
			tep_get_tax_rate($new_products['products_tax_class_id'])) . 
			'</font></b>
		</td>
	</tr> ';
}
  if (IND_PRODUCT_LIST_RATING == "Yes") {
	$show['rating'] = '
	<tr>
		<td height="17" class="smallText">
		<b><br>' . TABLE_HEADING_RATING . ':</b><br>'.$reviews_rating . 
		'</td>
	</tr>';
}
  if (IND_PRODUCT_LIST_DESCRIPTION == "Yes") {
	// GET PROD DESC
	$sql = 'SELECT `products_description` FROM `products_description` WHERE products_id ='.$new_products['products_id'].' && language_id='.(int)$languages_id;
	$description_query = tep_db_query($sql);
	$description = mysql_fetch_array($description_query, MYSQL_ASSOC);        
	$description['products_description'] = substr($description['products_description'], 0, 255);
	$desc_len = strlen($description['products_description']);
	$description['products_description'][$desc_len-3] = 
	$description['products_description'][$desc_len-3] = 
	$description['products_description'][$desc_len-3] = 
   	$show['desc'] = '
	<tr>
		<td colspan="2" style="padding:10px;text-align:none;"><span class="smallText">' . 
		$description['products_description'] . '</span>
		</td>
	</tr>';
 }
if (IND_PRODUCT_LIST_BUY_NOW == "Yes") {
	$show['buy_now'] = '
	<td height="30" width="50%" align="right" style="padding-bottom: 5px;padding-left: -20px;padding-right: 2px">
	<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) .
	'action=buy_now&products_id=' . $new_products['products_id']) . '">' .
	tep_image_button('button_in_cart.gif', IMAGE_BUTTON_BUY_NOW) . '</a>
	</td>';
}
if (IND_PRODUCT_LIST_DETAILS == "Yes") {
	$show['details'] = '
	<td width="10%" height="30" align="left" style="padding-right: -20px;padding-left: 2px;padding-bottom: 5px">
		<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' .
		$new_products['products_id']) . '" class="infoBoxContents">
		 More Info
		</a>
	</td>';
}	
  if (IND_PRODUCT_LIST_NAME == "Yes") {
   	$show['name'] = '
	<tr>
		<td bgcolor="#eeeeee" class="infoBoxHeading" height="" style="padding:2px;">
		 <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' .
		$new_products['products_id']) . '" alt="' . $new_products['products_name_full'] . 
		'" class="centralBox">' . $new_products['products_name'] . '</a>
		</td>
	</tr>';
 }
// only display what is set in 'product listing'

// start the indivdual box
$tbl_product = '
 <table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0" style="border: 0px solid #333366;padding:0px;">' . 
	  $show['name'] . 
	  '<tr>
	  	<td bgcolor="#FFFFFF">
		  <table width="100%" border="0" cellspacing="0" cellpadding="0">
	        <tr>
			  <td align="center" style="padding:3px;">' . $show['image'] . '</td>
			  <td height="125%" valign="top">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">' . 
				 $show['name'] .
				  $show['manufacturer'] . 
				  $show['model'] .
				  $show['quantity'] .					   
				  $show['weight'] .
				  $show['price'] .
 					  $show['rating'] .
				'</table>
			  </td>
			</tr>' . 
			$show['desc'] . 
			'<tr>' . 
			  $show['details'] .
			  $show['buy_now'] . 
			'</tr>
		  </table>
		</td>
	  </tr>
	</table>';
// end the indivdual box



$info_box_contents[$row][$col] = array('align' => 'center', 
'params' => 'class="smallText" width="33%" valign="top"',
                                          'text' => $tbl_product);

   $col ++;
   if ($col >= IND_PRODUCT_LIST_COL_NUM) {
     $col = 0;
     $row ++;
   }
 }

 new centralBox($info_box_contents);
 //echo $info_box_contents[0][0]['text'];


?>


Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...