Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Help with Manufactures Box


Guest

Recommended Posts

Im trying to get my manufactures box to display only all the manufactures in that one current catagory instead of all.

 

Reason i want this is cus the little drop down list only appears in the subcatagories and the the top level catagory.

 

Here is the the original coding of catalog/includes/boxes/manufacturers.php:

 

  $manufacturers_query = tep_db_query("select distinct manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");

 } else {

 $manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");

 }



 if ($number_of_rows = tep_db_num_rows($manufacturers_query)) {

 

Altered code doesnt work but i get no errors:

      if (isset($HTTP_GET_VARS['manufacturers_id'])) {

 $manufacturers_query = tep_db_query("select distinct c.categories_id as id, cd.categories_name as name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where p.products_status = '1' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and p2c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' and p.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "' order by cd.categories_name");

 } else {

 $manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");

 }



 if ($number_of_rows = tep_db_num_rows($manufacturers_query)) {

 

Any coders have any idea how i can pull this off?

 

Thanks.

Link to comment
Share on other sites

I guess I just feel like being a nice guy tonight.

 

Here ya go. Let me know how you like it.

 

<?php

/*

 $Id: manufacturers.php,v 1.19 2003/06/09 22:17:13 hpdl Exp $



 osCommerce, Open Source E-Commerce Solutions

 http://www.oscommerce.com



 Copyright (c) 2003 osCommerce



 Released under the GNU General Public License

*/



 if (isset($HTTP_GET_VARS['cPath'])) { 

	 $cPath_length = strlen($cPath);

  if (($cPath_length != '1') && ($cPath_length != '2')) {

    list($old_cPath, $new_cPath) = split ('[_]', $cPath);

  } else {

    $new_cPath = $cPath;

  }

  

  $cPath_query = tep_db_query("select products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id = '" . $new_cPath . "'");

  if (!$cPath_num_of_rows = tep_db_num_rows($cPath_query)) {

  $manufacturers_query = tep_db_query("select distinct m.manufacturers_id, m.manufacturers_name from MANUFACTURERS m, PRODUCTS_TO_CATEGORIES p2c, PRODUCTS  p, CATEGORIES c where c.parent_id = '" . $new_cPath . "' and p2c.categories_id = c.categories_id and p2c.products_id = p.products_id and p.manufacturers_id = m.manufacturers_id order by m.manufacturers_name");

  }	else { 

   $manufacturers_query = tep_db_query("select distinct m.manufacturers_id, m.manufacturers_name from MANUFACTURERS m, PRODUCTS_TO_CATEGORIES p2c, PRODUCTS  p, CATEGORIES c where c.categories_id = '" . $new_cPath . "' and p2c.categories_id = c.categories_id and p2c.products_id = p.products_id and p.manufacturers_id = m.manufacturers_id order by m.manufacturers_name");

  }

 } else { 

	 $manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name"); 

 } 



 if ($number_of_rows = tep_db_num_rows($manufacturers_query)) {

?>

<!-- manufacturers //-->

         <tr>

           <td>

<?php

   $info_box_contents = array();

   $info_box_contents[] = array('text' => BOX_HEADING_MANUFACTURERS);



   new infoBoxHeading($info_box_contents, false, false);



   if ($number_of_rows <= MAX_DISPLAY_MANUFACTURERS_IN_A_LIST) {

// Display a list

     $manufacturers_list = '';

     while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {

       $manufacturers_name = ((strlen($manufacturers['manufacturers_name']) > MAX_DISPLAY_MANUFACTURER_NAME_LEN) ? substr($manufacturers['manufacturers_name'], 0, MAX_DISPLAY_MANUFACTURER_NAME_LEN) . '..' : $manufacturers['manufacturers_name']);

       if (isset($HTTP_GET_VARS['manufacturers_id']) && ($HTTP_GET_VARS['manufacturers_id'] == $manufacturers['manufacturers_id'])) $manufacturers_name = '<b>' . $manufacturers_name .'</b>';

       $manufacturers_list .= '<a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $manufacturers['manufacturers_id']) . '">' . $manufacturers_name . '</a><br>';

     }



     $manufacturers_list = substr($manufacturers_list, 0, -4);



     $info_box_contents = array();

     $info_box_contents[] = array('text' => $manufacturers_list);

   } else {

// Display a drop-down

     $manufacturers_array = array();

     if (MAX_MANUFACTURERS_LIST < 2) {

       $manufacturers_array[] = array('id' => '', 'text' => PULL_DOWN_DEFAULT);

     }



     while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {

       $manufacturers_name = ((strlen($manufacturers['manufacturers_name']) > MAX_DISPLAY_MANUFACTURER_NAME_LEN) ? substr($manufacturers['manufacturers_name'], 0, MAX_DISPLAY_MANUFACTURER_NAME_LEN) . '..' : $manufacturers['manufacturers_name']);

       $manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'],

                                      'text' => $manufacturers_name);

     }



     $info_box_contents = array();

     $info_box_contents[] = array('form' => tep_draw_form('manufacturers', tep_href_link(FILENAME_DEFAULT, '', 'NONSSL', false), 'get'),

                                  'text' => tep_draw_pull_down_menu('manufacturers_id', $manufacturers_array, (isset($HTTP_GET_VARS['manufacturers_id']) ? $HTTP_GET_VARS['manufacturers_id'] : ''), 'onChange="this.form.submit();" size="' . MAX_MANUFACTURERS_LIST . '" style="width: 100%"') . tep_hide_session_id());

   }



   new infoBox($info_box_contents);



?>

           </td>

         </tr>

<!-- manufacturers_eof //-->

<?php

 }

?>

 

HTH,

-Chris

Chris Sullivan

Link to comment
Share on other sites

Hey thanks a Bunch! Wow great work.

 

Just one thing, i had to change a little bit cus i was getting sql errors.

 

I think this was becuase of some incomplete coding.

 

Here is a piece of your original modified one:

 

     if (!$cPath_num_of_rows = tep_db_num_rows($cPath_query)) { 

      $manufacturers_query = tep_db_query("select distinct m.manufacturers_id, m.manufacturers_name from MANUFACTURERS m, PRODUCTS_TO_CATEGORIES p2c, PRODUCTS  p, CATEGORIES c where c.parent_id = '" . $new_cPath . "' and p2c.categories_id = c.categories_id and p2c.products_id = p.products_id and p.manufacturers_id = m.manufacturers_id order by m.manufacturers_name"); 

    }   else { 

       $manufacturers_query = tep_db_query("select distinct m.manufacturers_id, m.manufacturers_name from MANUFACTURERS m, PRODUCTS_TO_CATEGORIES p2c, PRODUCTS  p, CATEGORIES c where c.categories_id = '" . $new_cPath . "' and p2c.categories_id = c.categories_id and p2c.products_id = p.products_id and p.manufacturers_id = m.manufacturers_id order by m.manufacturers_name"); 

    }

 

Closer look at the sql query:

 

 from MANUFACTURERS m, PRODUCTS_TO_CATEGORIES p2c, PRODUCTS  p, CATEGORIES c where

 

I changes these 2 instances to:

 

from " . TABLE_MANUFACTURERS . " m, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_PRODUCTS . " p, " . TABLE_CATEGORIES . " c where

 

This works for me so if anyone has any errors you could try replacing it with this too.

 

Thanks again :wink:

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...