Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

All_products page listed by Manufacturer


pstrid

Recommended Posts

Trying to make a 'all_manufacturers' page similar to the 'all_products' page but products are listed by manufacturer instead of by category. I am close but having problems with the manufacturers name displying proeprly. Anyone have any ideas. Thanks to all.

 

My code is below...

 

<?php
/*
 $Id: all_products.php,v 3.0 2004/02/21 by Ingo ([email protected])

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

 Copyright (c) 2004 osCommerce

 Released under the GNU General Public License
*/

 require('includes/application_top.php');

 include(DIR_WS_LANGUAGES . $language . '/' . FILENAME_ALL_PRODUCTS);

 $breadcrumb->add(HEADING_TITLE, tep_href_link(FILENAME_ALL_PRODUCTS, '', 'NONSSL'));
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo HEADING_TITLE; ?></title>
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<style type="text/css" media="screen">
<!--
h1 {font-family: Verdana, Arial, sans-serif; font-size: 10px; font-weight: bold; }
h2 {font-family: Verdana, Arial, sans-serif; font-size: 20px; font-weight: bold; }
h1, h2{margin-bottom:0px; margin-top:0px; line-height: 1em;}
-->
</style>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<table border="0" width="100%" cellspacing="3" cellpadding="3">
<tr>
<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
</table></td>
<td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
</tr>
<tr>
<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
</tr>
<tr>
<td><table width="100%" cellspacing="0" cellpadding=0" border="0">
<?php

$language_code = (isset($HTTP_GET_VARS['language']) && tep_not_null($HTTP_GET_VARS['language'])) ? $HTTP_GET_VARS['language'] : DEFAULT_LANGUAGE;

$included_manufacturers_query = tep_db_query("SELECT c.manufacturers_id, c.manufacturers_name FROM " . TABLE_MANUFACTURERS . " c, " . TABLE_MANUFACTURERS_INFO . " cd WHERE c.manufacturers_id = cd.manufacturers_id AND cd.languages_id = FLOOR($languages_id)");

$inc_cat = array();
while ($included_manufacturers = tep_db_fetch_array($included_manufacturers_query)) {
 $inc_cat[] = array (
    'id' => $included_manufacturers['manufacturers_id'],
    'name' => $included_manufacturers['manufacturers_name']);
 }
$cat_info = array();
for ($i=0; $i<sizeof($inc_cat); $i++)
 $cat_info[$inc_cat[$i]['id']] = array (
   'name'  => $inc_cat[$i]['name'],
   'path'  => $inc_cat[$i]['id'],
   'link'  => '<a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $manufacturers['manufacturers_id']) . '"><nobr>' . $manufacturers_name . '</nobr></a> » ' );

$products_query = tep_db_query("SELECT p.products_id, pd.products_name, pc.manufacturers_id FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " pc WHERE p.products_id = pd.products_id AND p.products_id = pc.products_id AND p.products_status = 1 AND pd.language_id = FLOOR($languages_id) ORDER BY pc.manufacturers_id, pd.products_name");

while($products = tep_db_fetch_array($products_query)) {
 echo
"          <tr>\n" .
'           <td width="33%" class="pageheading"><h1>' . (($memory == $products['manufacturers_id'])? '': $cat_info[$products['manufacturers_id']]['link']) . "</h1></td>\n" .
'           <td class="pageheading"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products['products_id'] . (($language_code == DEFAULT_LANGUAGE) ? '' : ('&language=' . $language_code))) . '"><h1>' . $products['products_name'] . "</h1></a></td>\n" .
"          </tr>\n";
 $memory = $products['manufacturers_id'];
 }
?>
</table></td>
</tr>
<tr>
<td align="right" class="main"><br><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT, '', 'NONSSL') . '">' . tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a>'; ?></td>
</tr>
</table></td>
<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>
</table></td>
</tr>
</table>
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

Link to comment
Share on other sites

This should work.

Corrected some of the sql and the reference to the manufacturers info arrays.

Products without manufacturer will not be listed.

 

HTH

Carine

 

<?php
/*
$Id: all_products_by_manufacturer.php
based on all_products.php ,v 3.0 2004/02/21 by Ingo ([email protected])

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

Copyright (c) 2004 osCommerce

Released under the GNU General Public License
*/

require('includes/application_top.php');

include(DIR_WS_LANGUAGES . $language . '/' . FILENAME_ALL_PRODUCTS);

$breadcrumb->add(HEADING_TITLE, tep_href_link(FILENAME_ALL_PRODUCTS, '', 'NONSSL'));
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo HEADING_TITLE; ?></title>
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<style type="text/css" media="screen">
<!--
h1 {font-family: Verdana, Arial, sans-serif; font-size: 10px; font-weight: bold; }
h2 {font-family: Verdana, Arial, sans-serif; font-size: 20px; font-weight: bold; }
h1, h2{margin-bottom:0px; margin-top:0px; line-height: 1em;}
-->
</style>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<table border="0" width="100%" cellspacing="3" cellpadding="3">
<tr>
<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
</table></td>
<td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
</tr>
<tr>
<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
</tr>
<tr>
<td><table width="100%" cellspacing="0" cellpadding=0" border="0">
<?php

$language_code = (isset($HTTP_GET_VARS['language']) && tep_not_null($HTTP_GET_VARS['language'])) ? $HTTP_GET_VARS['language'] : DEFAULT_LANGUAGE;

$included_manufacturers_query = tep_db_query("SELECT c.manufacturers_id, c.manufacturers_name FROM " . TABLE_MANUFACTURERS . " c WHERE c.manufacturers_id order by c.manufacturers_name");

$inc_cat = array();
while ($included_manufacturers = tep_db_fetch_array($included_manufacturers_query)) {
$inc_cat[] = array (
   'id' => $included_manufacturers['manufacturers_id'],
   'name' => $included_manufacturers['manufacturers_name']);
}
print_r($inc_cat);
$cat_info = array();
for ($i=0; $i<sizeof($inc_cat); $i++)
$cat_info[$inc_cat[$i]['id']] = array (
  'name'  => $inc_cat[$i]['name'],
  'path'  => $inc_cat[$i]['id'],
  'link'  => '<a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $inc_cat[$i]['id']) . '"><nobr>' . $inc_cat[$i]['name'] . '</nobr></a> » ' );

$products_query = tep_db_query("SELECT p.products_id, pd.products_name, p.manufacturers_id FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS ." m WHERE p.manufacturers_id = m.manufacturers_id AND p.products_id = pd.products_id AND p.products_status = 1 AND pd.language_id = " . (int)$languages_id . "  ORDER BY m.manufacturers_name, pd.products_name");

while($products = tep_db_fetch_array($products_query)) {
echo
"          <tr>\n" .
'           <td width="33%" class="pageheading"><h1>' . (($memory == $products['manufacturers_id'])? '': $cat_info[$products['manufacturers_id']]['link']) . "</h1></td>\n" .
'           <td class="pageheading"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products['products_id'] . (($language_code == DEFAULT_LANGUAGE) ? '' : ('&language=' . $language_code))) . '"><h1>' . $products['products_name'] . "</h1></a></td>\n" .
"          </tr>\n";
$memory = $products['manufacturers_id'];
}
?>
</table></td>
</tr>
<tr>
<td align="right" class="main"><br><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT, '', 'NONSSL') . '">' . tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a>'; ?></td>
</tr>
</table></td>
<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>
</table></td>
</tr>
</table>
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Link to comment
Share on other sites

Carine,

Thanks for your help..almost there, but a "funky" result. I bolded the section below that i am not sure why it is appearing. Here's what is displayed when using your code:

 

All Products

 

Array ( [0] => Array ( [id] => 17 [name] => Biop?le ) [1] => Array ( [id] => 10 [name] => Dr. Hauschka ) [2] => Array ( [id] => 12 [name] => Hijas del Sol ) [3] => Array ( [id] => 16 [name] => Lily of the Desert ) [4] => Array ( [id] => 15 [name] => Moncabrer ) [5] => Array ( [id] => 11 [name] => Salud Madrid ) )

Biop?le ? R?bano Negro y Alcachofa

Dr. Hauschka ? Crema de d?a de Cydonia

Crema de d?a Fluida (100ml)

Crema de d?a Fluida (30 ml)

Crema de Rosas

Crema Facial Matizada

Leche Facial Limpiadora

Mascarilla Rejuvenecedora

T?nico Facial

 

Again you help is greatly appreciated. Thanks again.

 

P.S. - I would also like to add a blank line between each section (ie a <td> </td> between Biopole and Dr. Hauschka), any ideas?

Link to comment
Share on other sites

oops, sorry

just remove the line

 

print_r($inc_cat);

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Link to comment
Share on other sites

you can force the spacing by adding a <br> before the manufacturers name and vertically aligning the product name bottom.

so it becomes:

 echo
"          <tr>\n" .
'           <td width="33%" class="pageheading"><h1>' . (($memory == $products['manufacturers_id'])? '': '<br>'.$cat_info[$products['manufacturers_id']]['link']) . "</h1></td>\n" .
'           <td class="pageheading" valign="bottom"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products['products_id'] . (($language_code == DEFAULT_LANGUAGE) ? '' : ('&language=' . $language_code))) . '"><h1>' . $products['products_name'] . "</h1></a></td>\n" .
"          </tr>\n";

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Link to comment
Share on other sites

Does anyone know how I can do the similar thing but have all product page listed by catagories?

 

Thanks!

Yes, install the All Products Page contribution.

 

Carine,

All is working...thanks for your help! One last question, on my all_products page, the category order is sorting by category ID instead of alphabetical by category name. I have tried to change the sort order but haven't had any success. Once again, i need your help :rolleyes:

Here's the relevant code:

$language_code = (isset($HTTP_GET_VARS['language']) && tep_not_null($HTTP_GET_VARS['language'])) ? $HTTP_GET_VARS['language'] : DEFAULT_LANGUAGE;

$included_categories_query = tep_db_query("SELECT c.categories_id, c.parent_id, cd.categories_name FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd WHERE c.categories_id = cd.categories_id AND cd.language_id = FLOOR($languages_id)");

$inc_cat = array();
while ($included_categories = tep_db_fetch_array($included_categories_query)) {
 $inc_cat[] = array (
    'id' => $included_categories['categories_id'],
    'parent' => $included_categories['parent_id'],
    'name' => $included_categories['categories_name']);
 }
$cat_info = array();
for ($i=0; $i<sizeof($inc_cat); $i++)
 $cat_info[$inc_cat[$i]['id']] = array (
   'parent'=> $inc_cat[$i]['parent'],
   'name'  => $inc_cat[$i]['name'],
   'path'  => $inc_cat[$i]['id'],
   'link'  => '' );

for ($i=0; $i<sizeof($inc_cat); $i++) {
 $cat_id = $inc_cat[$i]['id'];
 while ($cat_info[$cat_id]['parent'] != 0){
   $cat_info[$inc_cat[$i]['id']]['path'] = $cat_info[$cat_id]['parent'] . '_' . $cat_info[$inc_cat[$i]['id']]['path'];
   $cat_id = $cat_info[$cat_id]['parent'];
   }
 $link_array = split('_', $cat_info[$inc_cat[$i]['id']] ['path']);
 for ($j=0; $j<sizeof($link_array); $j++) {
   $cat_info[$inc_cat[$i]['id']]['link'] .= ' <a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $cat_info[$link_array[$j]]['path']) . '"><nobr>' . $cat_info[$link_array[$j]]['name'] . '</nobr></a> » ';
   }
 }

$products_query = tep_db_query("SELECT p.products_id, pd.products_name, pc.categories_id FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " pc WHERE p.products_id = pd.products_id AND p.products_id = pc.products_id AND p.products_status = 1 AND pd.language_id = FLOOR($languages_id) ORDER BY pc.categories_id, pd.products_name");

while($products = tep_db_fetch_array($products_query)) {
 echo
"          <tr>\n" .
'           <td width="33%" class="pageheading"><h1>' . (($memory == $products['categories_id'])? '': '<br>'. $cat_info[$products['categories_id']]['link']) . "</h1></td>\n" .
'           <td class="pageheading" valign="bottom"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products['products_id'] . (($language_code == DEFAULT_LANGUAGE) ? '' : ('&language=' . $language_code))) . '"><h1>' . $products['products_name'] . "</h1></a></td>\n" .
"          </tr>\n";
 $memory = $products['categories_id'];
 }
?>

Link to comment
Share on other sites

sorry, can't help you further with it now, it can be done in sql only if you have 1 level of categories, to re-sort the products based on multiple category levels requires more extensive changes for which I don't have the time to investigate now.

 

maybe you can ask in the support thread for this contribution (supposing there is one) if someone did this already.

 

Carine

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...