Page 1 of 1

Updating an older NAVBAR module to show manufacturers

Posted: Sat Sep 02, 2023 4:50 pm
by 14Steve14
I am trying to update an older NAVBAR module that shows a dropdown list of the stores manufacturers. I have the module installed and it works, but it throws a few errors. The first error is thrown I believe because of
tep_db_query
on line 6 and the second is caused by
tep_db_fetch_array
on line 11.

I have added the full code below.

Code: Select all

<li class="nav-item dropdown nb-manufacturers">
	<a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?= MODULE_NAVBAR_MANUFACTURERS_TEXT;?></a>

<?php 
$manufacturers_list = '';
$manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from manufacturers order by manufacturers_name");

// Display a list
$manufacturers_list = '<div class="dropdown-menu">';

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

	$manufacturers_name = $manufacturers['manufacturers_name'];

	if (isset($_GET['manufacturers_id']) && ($_GET['manufacturers_id'] == $manufacturers['manufacturers_id'])) {
		$manufacturers_name = '<strong>' . $manufacturers_name .'</strong>';
	}

	$manufacturers_list .= '<a class="dropdown-item" href="' . $GLOBALS['Linker']->build('index.php', 'manufacturers_id=' . $manufacturers['manufacturers_id']) . '">' . $manufacturers_name . '</a>';

}

$manufacturers_list .= '</div>';

echo $manufacturers_list; 
?>

</li>
There may be more errors in there, but those are the two that I can see in the error logs for the site.

Is there anyone that can give me a bit of help, or at least a pointer, on how to cure the errors please. I have look in other modules for similar code but seem to be confusing myself.

Re: Updating an older NAVBAR module to show manufacturers

Posted: Sat Sep 02, 2023 5:13 pm
by burt
The straightforwardest (usually) option is to find a piece of code in Core Phoenix that is closest to what you're trying and "copy" it, changing just enough to suit your new modules needs. In this case, /includes/modules/boxes/bm_manufacturers.php (and corresponding tpl file) seem to fit the bill;

Code: Select all

$manufacturers_query = $GLOBALS['db']->query("SELECT manufacturers_id AS id, manufacturers_name AS text FROM manufacturers ORDER BY manufacturers_name");
and

Code: Select all

<div class="dropdown-menu">
  <?php
  while ($manufacturer = $manufacturers_query->fetch_assoc()) {
    echo '<a class="dropdown-item" href="', $GLOBALS['Linker']->build('index.php', ['manufacturers_id' => $manufacturer['id']]), '">', $manufacturers_name, '</a>';
  }
  ?>
</div>

Re: Updating an older NAVBAR module to show manufacturers

Posted: Sun Sep 03, 2023 10:25 am
by 14Steve14
Thanks Gary @burt for the pointers I eventually got the NAVBAR dropdown working.

I also managed to update the code on another page that shows all the manufacturers and their logos.

Onwards to the next task in the update process.