Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

PHP Question


mreigle

Recommended Posts

I'm still learning PHP and I want to do something that's a little "over my head". I want to add a paragraph over the product listing on my Categories pages. I want the paragraph to pertain to whatever category I am in. I'm using several contributions, so I can't easily implement the categories descriptions contribution.

 

I have the "Ultimate SEO Urls" contribution installed also. With this, it uses the category name in the URL: e.g.: http://www.mydomain.com/sheet-sets-california-king-c-31.html.

 

Is there a way to write an IF statement if the category or file name is == to something, can I echo the text of a file in /includes?

 

I havent got that far in my book yet... heh

Link to comment
Share on other sites

The categories description contribution makes fairly minimal change. It's not a difficult one to install. I'd recommend you go with that one.

 

Otherwise, something like

 

include( 'includes/descriptions/'.$categories['categories_name'].'.php' );

 

You'd create the directory descriptions under includes and in there save php files with the same name as your category.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

The categories description contribution makes fairly minimal change. It's not a difficult one to install. I'd recommend you go with that one.

 

Otherwise, something like

 

include( 'includes/descriptions/'.$categories['categories_name'].'.php' );

 

You'd create the directory descriptions under includes and in there save php files with the same name as your category.

 

That contribution interefers with the meta tags contribution I have installed when I go to edit the category information in admin. There has to be some way to echo a certain file depending on what the category name is or the name of the file it is... right?

Link to comment
Share on other sites

That contribution interefers with the meta tags contribution I have installed when I go to edit the category information in admin. There has to be some way to echo a certain file depending on what the category name is or the name of the file it is... right?

 

Yes.

 

include( 'includes/descriptions/'.$categories['categories_name'].'.php' );

 

You'd create the directory descriptions under includes and in there save php files with the same name as your category.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Sorry I'm not getting this... Here's what I put in /includes/modules/product_listing.php:

 

include( 'includes/descriptions/'.$categories['categories_name'].'.php' );

 

I've created a descriptions directory in includes.

 

I've created a "California King Sheets" and a "sheet_sets_california_king" php file in that directory.

(the name of the category I'm trying to add is "California King", the file name is "sheet_sets_california_king.php"

 

I'm getting the following error:

 

Warning: main(): Failed opening 'includes/descriptions/.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/precious/public_html/includes/modules/product_listing.php on line 179

 

Obviously, it's not finding the file by the correct name in /descriptions/

 

How do I implement it so it uses a different description file for each category?

Link to comment
Share on other sites

You need to insert this code where you want this to happen:

 

$category_query = tep_db_query("select cd.categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " cd where cd.categories_id = '" . (int)$current_category_id . "' and cd.language_id = '" . (int)$languages_id . "'");
$category = tep_db_fetch_array($category_query);
include( 'includes/descriptions/'.$categories['categories_name'].'.php' );

 

You must name your include files after your category name. If your category name is "California King", then "California King Sheets" won't work. Your file name must be "California King" since that's what the code is looking for.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

I've created a file named California King Sheets in /includes/descriptions. That is the exact name of the category. Here is the contents of my product_listing.php page (the page I want to include the descriptions page)

 

<?php
/*
 $Id: product_listing.php,v 1.44 2003/06/09 22:49:59 hpdl Exp $

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

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/
 $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') ) ) {
?>

<table border="0" width="100%" cellspacing="0" cellpadding="2">
 <tr>
<td class="smallText"><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></td>
<td class="smallText" align="right"><?php echo TEXT_RESULT_PAGE . ' ' . $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></td>
 </tr>
</table>
<?php
 }

 $list_box_contents = array();

 for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
switch ($column_list[$col]) {
  case 'PRODUCT_LIST_MODEL':
	$lc_text = TABLE_HEADING_MODEL;
	$lc_align = '';
	break;
  case 'PRODUCT_LIST_NAME':
	$lc_text = TABLE_HEADING_PRODUCTS;
	$lc_align = '';
	break;
  case 'PRODUCT_LIST_MANUFACTURER':
	$lc_text = TABLE_HEADING_MANUFACTURER;
	$lc_align = '';
	break;
  case 'PRODUCT_LIST_PRICE':
	$lc_text = TABLE_HEADING_PRICE;
	$lc_align = 'right';
	break;
  case 'PRODUCT_LIST_QUANTITY':
	$lc_text = TABLE_HEADING_QUANTITY;
	$lc_align = 'right';
	break;
  case 'PRODUCT_LIST_WEIGHT':
	$lc_text = TABLE_HEADING_WEIGHT;
	$lc_align = 'right';
	break;
  case 'PRODUCT_LIST_IMAGE':
	$lc_text = TABLE_HEADING_IMAGE;
	$lc_align = 'center';
	break;
  case 'PRODUCT_LIST_BUY_NOW':
	$lc_text = TABLE_HEADING_BUY_NOW;
	$lc_align = 'center';
	break;
}

if ( ($column_list[$col] != 'PRODUCT_LIST_BUY_NOW') && ($column_list[$col] != 'PRODUCT_LIST_IMAGE') ) {
  $lc_text = tep_create_sort_heading($HTTP_GET_VARS['sort'], $col+1, $lc_text);
}

$list_box_contents[0][] = array('align' => $lc_align,
								'params' => 'class="productListing-heading"',
								'text' => ' ' . $lc_text . ' ');
 }

 if ($listing_split->number_of_rows > 0) {
$rows = 0;
$column = 0;
$bonus_message = $listing['products_id'];

$category_query = tep_db_query("select cd.categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " cd where cd.categories_id = '" . (int)$current_category_id . "' and cd.language_id = '" . (int)$languages_id . "'");
$category = tep_db_fetch_array($category_query);
include( 'includes/descriptions/'.$categories['categories_name'].'.php' );

echo '	'.$bonus_message.'

		  <table cellspacing=0 cellpadding=0>
		   <tr><td background=images/m27.gif width=444 height=36 class=bc><b>      Category : '.$breadcrumb->trail(' » ').'</b></td></tr>
		   <tr><td height=15></td></tr>
		  </table>

		  <table cellspacing=0 cellpadding=0>
		   <tr>
';

$listing_query = tep_db_query($listing_split->sql_query);
while ($listing = tep_db_fetch_array($listing_query)) {
  $product_contents = array();
  $rows++;
  if (($rows/2) == floor($rows/2)) {
	$list_box_contents[] = array('params' => 'class="productListing-even"');
  } else {
	$list_box_contents[] = array('params' => 'class="productListing-odd"');
  }

  $cur_row = sizeof($list_box_contents) - 1;

  for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
	$lc_align = '';

	switch ($column_list[$col]) {
	  case 'PRODUCT_LIST_MODEL':
		$lc_align = '';
		$lc_text = ' ' . $listing['products_model'] . ' ';
		break;
	  case 'PRODUCT_LIST_NAME':
		$lc_align = '';
		if (isset($HTTP_GET_VARS['manufacturers_id'])) {
		  $lc_text = '<a class=ml3 href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';
		} else {
		  $lc_text = '<a class=ml3 href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';
		}
		break;
	  case 'PRODUCT_LIST_MANUFACTURER':
		$lc_align = '';
		$lc_text = ' <a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $listing['manufacturers_id']) . '">' . $listing['manufacturers_name'] . '</a> ';
		break;
	  case 'PRODUCT_LIST_PRICE':
		$lc_align = 'right';
		if (tep_not_null($listing['specials_new_products_price'])) {
		  $lc_text = '<span style="color:#7F7F7F;font-size:12px"> <s>' .  $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</s></span><span class=t15>  ' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . ' </span>';
		} else {
		  $lc_text = '<span> ' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . ' </span>';
		}
		break;
	  case 'PRODUCT_LIST_QUANTITY':
		$lc_align = 'right';
		$lc_text = ' ' . $listing['products_quantity'] . ' ';
		break;
	  case 'PRODUCT_LIST_WEIGHT':
		$lc_align = 'right';
		$lc_text = ' ' . $listing['products_weight'] . ' ';
		break;
	  case 'PRODUCT_LIST_IMAGE':
		$lc_align = 'center';
		if (isset($HTTP_GET_VARS['manufacturers_id'])) {
		  $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, ' class=br') . '</a>';
		} else {
		  $lc_text = ' <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, ' class=br') . '</a> ';
		}
		break;
	  case 'PRODUCT_LIST_BUY_NOW':
		$lc_align = 'center';
		$lc_text = '<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', IMAGE_BUTTON_BUY_NOW) . '</a> ';
		break;
	}

	$list_box_contents[$cur_row][] = array('align' => $lc_align,
										   'params' => 'class="productListing-data"',
										   'text'  => $lc_text);
	$product_contents[] = $lc_text;	   
  }


  echo '
			   <td width=147 valign=top>
				<table cellspacing=0 cellpadding=0 width=120 align=center>
				 <tr><td colspan=2 align=center>'.$product_contents[0].'<br></td></tr>
				 <tr><td align=center colspan=2 valign=middle height=43><b>'.$product_contents[1].'</b></td></tr>
				 <tr><td class=bc1 align=right>'.$product_contents[2].'</td></tr>
				 <tr><td height=7 colspan=2></td></tr>
				 <tr><td colspan=2><a href="'.tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $listing['products_id']) . '">' . tep_image_button('small_view.gif', IMAGE_BUTTON_BUY_NOW) . '</a> <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_in_cart.gif', IMAGE_BUTTON_BUY_NOW) . '</a></td></tr>
				</table>				   
			   </td>
  ';
  $column ++;
  if ($column >= 3) {
	$rows ++;
	$column = 0;
	echo '			
		   </tr>
		  </table>
		  <table cellspacing=0 cellpadding=0>		
		   <tr><td height=24></td></tr>
		   <tr><td><img src=images/m35.gif width=443 height=1></td></tr>
		   <tr><td height=16></td></tr>
		  </table>
		  <table cellspacing=0 cellpadding=0>
		   <tr>
		 ';
  } else echo '<td width=0></td>';



}

echo '
			</tr>
		   </table>
	  ';

//new productListingBox($list_box_contents);
 } else {
$list_box_contents = array();

$list_box_contents[0] = array('params' => 'class="productListing-odd"');
$list_box_contents[0][] = array('params' => 'class="productListing-data"',
							   'text' => TEXT_NO_PRODUCTS);

echo '<div class=PageHeading>';
		   if ( (ALLOW_CATEGORY_DESCRIPTIONS == 'true') && (tep_not_null($category['categories_heading_title'])) ) {
			 echo $category['categories_heading_title'];
		   } else {
			 echo HEADING_TITLE;
		   };
echo '</div>';
new productListingBox($list_box_contents);
 }

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

<table border="0" width="100%" cellspacing="0" cellpadding="2">
 <tr><td height=20></td></tr>

 <?php if ( (ALLOW_CATEGORY_DESCRIPTIONS == 'true') && (tep_not_null($category['categories_description'])) ) { ?>
  <tr>
		<td align="left" colspan="2" class="category_desc"><?php echo $category['categories_description']; ?></td>
  </tr>
  <?php } ?>
  <tr><td height=20></td></tr>
 <tr>
<td class="smallText"><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></td>
<td class="smallText" align="right"><?php echo TEXT_RESULT_PAGE . ' ' . $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></td>
 </tr>
</table>

<?php
 }
?>

 

Here is the error i get:

 

Warning: main(includes/descriptions/.php): failed to open stream: No such file or directory in /home/precious/public_html/includes/modules/product_listing.php on line 80

 

Warning: main(includes/descriptions/.php): failed to open stream: No such file or directory in /home/precious/public_html/includes/modules/product_listing.php on line 80

 

Warning: main(): Failed opening 'includes/descriptions/.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/precious/public_html/includes/modules/product_listing.php on line 80

 

 

 

It's not finding the php file. The file is definitely there. Am I doing something wrong?

Link to comment
Share on other sites

It looks like I missed another table that needed to be added! I forgot to add the "products" table!

 

After I added the new entry to the new database, the new product magically appeared!

 

Thanks for all your help everybody! lol

Link to comment
Share on other sites

	$category_query = tep_db_query("select cd.categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " cd where cd.categories_id = '" . (int)$current_category_id . "' and cd.language_id = '" . (int)$languages_id . "'");
$category = tep_db_fetch_array($category_query);
include( 'includes/descriptions/'.$category['categories_name'].'.php' );

 

1. The code I gave has a slight error. It should be $category['categories_name'].

 

2. Don't include the file in product_listing.php unless you really need to (and I suspect you don't). Include it in index.php just before the include( FILENAME_PRODUCTS_LISTING ).

 

3. Doing #2 will fix the path problem. If you keep the include in product_listing.php, then the include path will be

 

include( '../descriptions/'.$category['categories_name'].'.php' );

 

If you do #2, you do not need to change the path as in #3.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

	$category_query = tep_db_query("select cd.categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " cd where cd.categories_id = '" . (int)$current_category_id . "' and cd.language_id = '" . (int)$languages_id . "'");
$category = tep_db_fetch_array($category_query);
include( 'includes/descriptions/'.$category['categories_name'].'.php' );

 

1. The code I gave has a slight error. It should be $category['categories_name'].

 

2. Don't include the file in product_listing.php unless you really need to (and I suspect you don't). Include it in index.php just before the include( FILENAME_PRODUCTS_LISTING ).

 

3. Doing #2 will fix the path problem. If you keep the include in product_listing.php, then the include path will be

 

include( '../descriptions/'.$category['categories_name'].'.php' );

 

If you do #2, you do not need to change the path as in #3.

 

HELL YES! It works! It's alive! Itttt's aliiiiveeee!

 

Man I wish this board had karma. Thank you! lookin good: http://www.preciousbedding.com/sheet-sets-...-king-c-31.html

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...