Spike_UK Posted February 2, 2004 Share Posted February 2, 2004 Hi, I have am using a slightly modifed AllProds contribution to display every product in my database. Although this achieves my goal, I would prefer this list to be in the same order as the catergories. At the moment the list is like Product Image, Model Number, Product Name, Price If possible I would like to have Product Category, Product Image, Model Number, Product Name, Price OR have the category field as a hidden field that is purely used as a sort. Any ideas?? Here is the code as it stands. <?php /* $Id: allprods.php,v 1.5 2002/09/29 1 osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright © 2002 osCommerce Released under the GNU General Public License */ require('includes/application_top.php'); include(DIR_WS_LANGUAGES . $language . '/' . FILENAME_ALLPRODS); // Set number of columns in listing define ('NR_COLUMNS', 1); // $breadcrumb->add(HEADING_TITLE, tep_href_link(FILENAME_ALLPRODS, '', 'NONSSL')); ?> <!-- header //--> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>"> <?php require(DIR_WS_INCLUDES . 'meta_tags.php'); ?> <title>SWIT - Power Solutions</title> <base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>"> <meta name="description" content="<?php echo META_TAG_DESCRIPTION; ?>" /> <meta name="keywords" content="<?php echo META_TAG_KEYWORDS; ?>" /> <link rel="stylesheet" type="text/css" href="<?php echo DIR_WS_TEMPLATES; ?>stylesheet.css"> <link rel="stylesheet" type="text/css" href="<?php echo DIR_WS_TEMPLATES; ?>stylesheet-org.css"> <link rel="stylesheet" type="text/css" href="<?php echo DIR_WS_TEMPLATES; ?>print.css" media="print"> <?php if ($javascript) { require(DIR_WS_JAVASCRIPT . $javascript); } ?> </head><body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0"> <!-- All TS references added by TemplateShopper.com November 2003 <!-- header //--> <!-- Start of Header --> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr style="background-image: url('images/swit/SWIT-Layout_02.gif');"> <td><img src="images/swit/SWIT-Layout_01.gif" width="433" height="69" alt=""></td> </tr> <tr> <td style="background-image: url('images/swit/SWIT-Layout-2_03.gif');" height="18" align="center" colspan="2"> <!-- Start of Nav --> <table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr class="headerNavigation"> <td class="headerNavigation"> <?php echo $breadcrumb->trail(' » '); ?></td> <td align="right" class="headerNavigation"><?php echo '<a class="headerNavigation" href="' . tep_href_link(FILENAME_DEALERS) . '"> ' . BOX_INFORMATION_DEALERS . '</a> '?></td> </tr> </table> <!-- End of Nav --> </td> </tr> <tr> <td colspan="2"> <!-- Start of Header Dropshadow --> <table width="100%" height="7" border="0" cellpadding="0" cellspacing="0"> <tr> <td style="background-image: url('images/swit/SWIT-Layout2_05.gif');"><img src="images/swit/spacer.gif" width="100" height="7"></td> </tr> </table> <!-- End of Header Dropshadow --> </td> </tr> </table> <!-- End of Header --> <!-- header_eof //--> <!-- body //--> <table border="0" width="100%" cellspacing="3" cellpadding="3"> <tr> <!-- body_text //--> <?php //begin change. We want the same listing for the categories than for the products. // create column list $define_list = array('PRODUCT_LIST_MODEL' => PRODUCT_LIST_MODEL, 'PRODUCT_LIST_NAME' => PRODUCT_LIST_NAME, 'PRODUCT_LIST_MANUFACTURER' => PRODUCT_LIST_MANUFACTURER, 'PRODUCT_LIST_PRICE' => PRODUCT_LIST_PRICE, 'PRODUCT_LIST_QUANTITY' => PRODUCT_LIST_QUANTITY, 'PRODUCT_LIST_WEIGHT' => PRODUCT_LIST_WEIGHT, 'PRODUCT_LIST_IMAGE' => PRODUCT_LIST_IMAGE, 'PRODUCT_LIST_BUY_NOW' => PRODUCT_LIST_BUY_NOW); asort($define_list); $column_list = array(); reset($define_list); while (list($column, $value) = each($define_list)) { if ($value) $column_list[] = $column; } $select_column_list = ''; for ($i=0, $n=sizeof($column_list); $i<$n; $i++) { switch ($column_list[$i]) { case 'PRODUCT_LIST_MODEL': $select_column_list .= 'p.products_model, '; break; case 'PRODUCT_LIST_NAME': $select_column_list .= 'pd.products_name, '; break; case 'PRODUCT_LIST_MANUFACTURER': $select_column_list .= 'm.manufacturers_name, '; break; case 'PRODUCT_LIST_QUANTITY': $select_column_list .= 'p.products_quantity, '; break; case 'PRODUCT_LIST_IMAGE': $select_column_list .= 'p.products_image, '; break; case 'PRODUCT_LIST_WEIGHT': $select_column_list .= 'p.products_weight, '; break; } } // We show everything // $listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' and p.products_id = pd.products_id and p.products_id = p2c.products_id"; // $listing_sql = "select " . $select_column_list . " p.products_id, pc.p.products_price, p.products_tax_class_id from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' and p.products_id = pd.products_id and p.products_id = p2c.products_id"; $listing_sql = "select " . $select_column_list . " p.products_id, p.products_price, p.products_tax_class_id from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where products_status = '1' and p.products_id = pd.products_id and p.products_id = p2c.products_id"; if ( (!isset($_GET['sort'])) || (!ereg('[1-8][ad]', $_GET['sort'])) || (substr($_GET['sort'], 0, 1) > sizeof($column_list)) ) { for ($i=0, $n=sizeof($column_list); $i<$n; $i++) { if ($column_list[$i] == 'PRODUCT_LIST_NAME') { //because we don't display the model but we want it to be default, we fool the sort var and set it to a higher number and set the order by to products model $_GET['sort'] = $i+5 . 'a'; $listing_sql .= " order by p.products_price"; break; } } } else { $sort_col = substr($_GET['sort'], 0 , 1); $sort_order = substr($_GET['sort'], 1); $listing_sql .= ' order by '; switch ($column_list[$sort_col-1]) { case 'PRODUCT_LIST_MODEL': $listing_sql .= "p.products_model " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name"; break; case 'PRODUCT_LIST_NAME': $listing_sql .= "pd.products_name " . ($sort_order == 'd' ? 'desc' : ''); break; case 'PRODUCT_LIST_MANUFACTURER': $listing_sql .= "m.manufacturers_name " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name"; break; case 'PRODUCT_LIST_QUANTITY': $listing_sql .= "p.products_quantity " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name"; break; case 'PRODUCT_LIST_IMAGE': $listing_sql .= "pd.products_name"; break; case 'PRODUCT_LIST_WEIGHT': $listing_sql .= "p.products_weight " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name"; break; case 'PRODUCT_LIST_PRICE': $listing_sql .= "final_price " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name"; break; } } ?> <td width="100%" valign="top"> <table border="0" width="100%" cellspacing="0" cellpadding="8"> <tr> <td align="center"> <form> <input type=button value="Print this Page" onClick="java script:window.print()"> </form> </td> </tr> <tr> <td> <?php include(DIR_WS_MODULES . FILENAME_PRODUCT_LISTING_PRINT); ?> </td> </tr> </table> </td> </tr> </table> <!-- body_eof //--> </body> </html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.