Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Recommended Posts

Posted (edited)

Hi, I've been using oscommerce for about a year and never had the need to ask help, but I've run into my first hurdle. I'm just having trouble understanding the depth of oscommerce's PHP programming.

 

Anyway, my situation is that I'm currently using PRODUCT_LISTING.php with only ONE product per page (This means when you browse a category, you see product 1 then click next, product 2 then click next.. etc). I now require the PRODUCT_LISTING.php to act like PRODUCT_INFO.php.

 

-When i first decided to do this, I thought... easy! I could just copy the buy now code from product_info.php and bring it through to product_listing.php.

- And also get the product attributes sql query from product_info.php and bring it into product_listing.php

 

Well this job is apparently a lot harder than i thought. Due to my limited knowledge of php everytime i import the query it wont work. I have also tried searching for contributions... and there is ONE that does this (because it allows you to use a checkbox and select multiple products for purchase from the index.php/product_listing.php), but that contribution comes with a stack of additionl unrequired stuff, and because my product_listing appears to already have a contribution on it i cant work it out).

 

There are no simple contributions or tech notes i can locate on this topic.

 

Any help would be really, really, really appreciated. Thanks guys.

 

Anyway, to to reiterate what i want. I want my product_listing.php i am going to paste below to show product attributes and buy now buttons (from product_info.php). Below I have pasted so that we have a reference point for conversation. *** Please note. My product_listing.php may have been edited from the standard, but i am willing to revert to standard product_listing.php and start again if required.

 

<?php
/*
 $Id: product_listing.php,v 1.1.1.1 2003/02/20 01:03:54 ptosh Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

// VIEW_OPTION SESSION REGISTER

 if (isset($HTTP_GET_VARS['listing'])) {
$_SESSION['view'] = $HTTP_GET_VARS['listing'];
$view = $HTTP_GET_VARS['listing'];
 } else if (tep_session_is_registered('view')) {
$view = $_SESSION['view'];
 } else if (!tep_session_is_registered('view')) {
$view = 'side';
tep_session_register('view');
 }

 switch($view){
case 'vertical':
  $max_display_search_result = MAX_DISPLAY_SEARCH_RESULTS;
  break;
case 'side':
  $max_display_search_result = MAX_DISPLAY_SEARCH_RESULTS;
  break;
 }

 if (isset($HTTP_GET_VARS['PLsort'])) {
$_SESSION['PLsort'] = $HTTP_GET_VARS['PLsort'];
$PLsort = $HTTP_GET_VARS['PLsort'];
 } else if (tep_session_is_registered('PLsort')) {
$PLsort = $_SESSION['PLsort'];
 } else if (!tep_session_is_registered('PLsort')) {
$PLsort = '4a';
tep_session_register('PLsort');
 }

 switch ($PLsort) {
case '4a':
$sort_suffix = "order by p.products_date_added desc";
break;
 }

 $original_sort_location = strpos($listing_sql, 'order by');
 $listing_sql_corrected = substr($listing_sql, 0, $original_sort_location - 1) . $sort_suffix;

?>

<table border="0" width="100%" cellspacing="0" cellpadding="0">
 <?php


 $listing_split = new splitPageResults($listing_sql_corrected, $max_display_search_result, 'p.products_date_added');

 if ( ($listing_split->number_of_rows > 0) && ( (PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3') ) ) {
?>
 <tr>
<td><table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
	<td class="smallText"> <?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?> 1</td>
	<td align="right" class="smallText"> <?php echo TEXT_RESULT_PAGE; ?> <?php echo $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?> </td>
  </tr>
</table></td>
 </tr>
 <tr>
<td><?php echo tep_draw_separator(); ?></td>
 </tr>
 <?php
 }
?>
 <tr>
<td><?php
 if ($listing_split->number_of_rows > 0) {
switch($view){
############################
#	  Image + Text		#
############################
case 'vertical':
$listing_query = tep_db_query($listing_split->sql_query);
echo '<table border="0" width="100%" cellspacing="0" cellpadding="0">'."\n";
while ($listing = tep_db_fetch_array($listing_query)) {
//price
	if (tep_not_null($listing['specials_new_products_price'])) {
		$price = '<s>' .  $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</s>  <span class="productSpecialPrice">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span> ';
		 } else {
		$price = $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . ' ';
	}
  //buynow
   if($listing['products_quantity'] > 0) {
	   $BUY_NOW = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']) . '">' . tep_image_button('button_buy_now.gif', TEXT_BUY . $listing['products_name'] . TEXT_NOW) . '</a> ';
	   } else {
   	  $BUY_NOW = STOCK_MARK_PRODUCT_OUT_OF_STOCK;
   }
  //stylesheet.css
  if (($row/2) == floor($row/2)) {
	$_class = "productListing-even";
  } else {
	$_class = "productListing-odd";
  }

  $row++;
	echo '<tr class="'.$_class.'">';
	echo '<td align="center" class="productListing-data"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></td>';
	echo '<td align="center" class="productListing-data"> '.$listing['products_model'].' </td>';
	echo '<td class="productListing-data"> <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">'.$listing['products_name'].'</a> </td>';
	echo '<td align="center" class="productListing-data">'.$BUY_NOW.' </td>';
	echo '<td align="right" class="productListing-data"> '.$price.' </td>';
	echo '</tr>';
}
echo '</table>';
 break;
############################
#	  Image			   #
############################
case 'side':
default:
$listing_query = tep_db_query($listing_split->sql_query);
echo '<table border="0" width="100%" cellspacing="0" cellpadding="0">'."\n";
 echo   '<tr>'."\n";
  $row = 0;
  $col = 0;

while ($listing = tep_db_fetch_array($listing_query)) {
//price
	if (tep_not_null($listing['specials_new_products_price'])) {
		$price = '<s>' .  $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</s>  <span class="productSpecialPrice">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span> ';
		 } else {
		$price = $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . ' ';
	}
  //buynow
   if($listing['products_quantity'] > 0) {
	   $BUY_NOW = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']) . '">' . tep_image_button('button_buy_now.gif', TEXT_BUY . $listing['products_name'] . TEXT_NOW) . '</a> ';
	   } else {
   	  $BUY_NOW = STOCK_MARK_PRODUCT_OUT_OF_STOCK;
   }

  $row++;
  $col++;
	echo '<td class="pageHeading3" align="center" width="33%" valign="top"><div align=center>

<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . 

tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></div><div align=left><br><b>' .


tep_get_categories_name($cPath) . '</b></div>' . '



<table border="0" width="100%" cellspacing="0" cellpadding="0">
	  <tr>
		<td width="75%" class="pageHeading3" valign="top">' . $listing['products_name'] . '</td>
		<td width="25%" class="pageHeading3" align="right" valign="top">' . $price . '<br></td>
		</tr>
</table>

<table width="100%" border=0 cellpadding=0 cellspacing=0><tr><td class="smallText2" width="100%"> 	
</td><td align=right valign=top><br>' .

	'<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' .

	'<img border=0 src="images/more_info.gif">' . 

	'</a>' .


'<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']) . '">' . '<img border=0 src="images/buy_now.gif"></a>' .

	'</td></tr></table><br>' .



	'</td>';
			   if ($col > 2) {
				  echo '</tr>'."\n".'<tr>'."\n";
				  $col = 0;
				  $row ++;
			   }
}
	  echo '</tr>';
echo '</table>';
break;
}

echo '	</td>' . "\n" .
	 '  </tr>' . "\n";
 } else {
?>
<tr class="productListing-odd">
<td class="smallText"> <?php echo (isset($HTTP_GET_VARS['manufacturers_id']) ? TEXT_NO_PRODUCTS2 : TEXT_NO_PRODUCTS); ?> </td>
 </tr>
 <?php
 }
?>
 <?php
 if ( ($listing_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3')) ) {
?>
<table border="0" width="375" cellspacing="0" cellpadding="2" class="infoBoxContents">
 <tr>
<td align="center"><?php echo $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></td>
 </tr>
</table>
<?php
 }
?>

 

 

--------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------

I think what i need inside there is:

--------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------

 

 

<?php
$products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "'");
$products_attributes = tep_db_fetch_array($products_attributes_query);
if ($products_attributes['total'] > 0) {
?>
	  <table border="0" cellspacing="0" cellpadding="0" align="right">
		<tr>
		  <td class="main" colspan="2"><br><?php echo TEXT_PRODUCT_OPTIONS; ?></td>
		</tr>
<?php
  $products_options_name_query = tep_db_query("select distinct popt.products_options_id, popt.products_options_name from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "' order by popt.products_options_name");
  while ($products_options_name = tep_db_fetch_array($products_options_name_query)) {
	$products_options_array = array();
	$products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "'");
	while ($products_options = tep_db_fetch_array($products_options_query)) {
	  $products_options_array[] = array('id' => $products_options['products_options_values_id'], 'text' => $products_options['products_options_values_name']);
	  if ($products_options['options_values_price'] != '0') {
		$products_options_array[sizeof($products_options_array)-1]['text'] .= ' (' . $products_options['price_prefix'] . $currencies->display_price($products_options['options_values_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) .') ';
	  }
	}

	if (isset($cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']])) {
	  $selected_attribute = $cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']];
	} else {
	  $selected_attribute = false;
	}
?>
		<tr>
		  <td class="main"><?php echo $products_options_name['products_options_name'] . ':'; ?>
		  <?php echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); ?></td>
		</tr>
<?php
  }
?>

 

--------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------

So when i try this it never works! If i could take a guess at what i dont understand, it would be the absence of global variables or something which is causing a sql query not to function properly. Any help would be great, thanks people.

 

 

I'm not necessarily asking for a handout, just a few nudges in the right direction, I'm not a php pro but i think i can get the gist with a hand-up.

 

Kind Regards

 

Jeremy

Edited by impactdesigns

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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...