Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Changing Categories to Search Links


captaintim

Recommended Posts

Hi, our site is a classical CD shop and there are lots of entries that need to go under more than one category - Beethoven Piano Sonatas need to go under Beethoven and Piano and preferably the artist playing them aswell - that makes 3, and sometimes there are more categories.

 

This makes uploading CDs time consuming, because we will have to cross-check the product listing numbers to make sure each CD is displayed in the right place for each category.

 

I was wondering if it might be possible to change the 'categories' to links with set search criteria, so that if you click on Beethoven, the system will search for all Beethoven CDs in stock, on the fly. The idea being that CDs need only be entered in one place and the search criteria will bring back the relevant results for the user. I would think this is pretty easy to figure out, but we would like to keep the drop-down structure that the categories menu puts in place if possible which could make things more complicated.

 

I'm very new to oscommerce, so apologies if this doesn't make sense.

 

Thanks in advance.

Link to comment
Share on other sites

Thanks for this. I'm afraid I'm not really sure how it works - would you be able to shed any further light. This is the text from the file you suggested.

 

<?php

/*

$Id: categories.php,v 1.25 2003/07/09 01:13:58 hpdl Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

 

function tep_show_category($counter) {

global $tree, $categories_string, $cPath_array;

 

for ($i=0; $i<$tree[$counter]['level']; $i++) {

$categories_string .= " ";

}

 

$categories_string .= '<a href="';

 

if ($tree[$counter]['parent'] == 0) {

$cPath_new = 'cPath=' . $counter;

} else {

$cPath_new = 'cPath=' . $tree[$counter]['path'];

}

 

$categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">';

 

if (isset($cPath_array) && in_array($counter, $cPath_array)) {

$categories_string .= '<b>';

}

 

// display category name

$categories_string .= $tree[$counter]['name'] . ( $tree[$counter]['new_prods'] > 0 ? " <font color='#CC3333'><b><i>".$tree[$counter]['new_prods']." New</i></b></font>" : "" );

 

if (isset($cPath_array) && in_array($counter, $cPath_array)) {

$categories_string .= '</b>';

}

 

// if (tep_has_category_subcategories($counter)) {

// $categories_string .= '->';

// }

 

$categories_string .= '</a>';

 

// if (SHOW_COUNTS == 'true') {

// $products_in_category = tep_count_products_in_category($counter);

// if ($products_in_category > 0) {

// $categories_string .= ' (' . $products_in_category . ')';

// }

// }

 

$categories_string .= '<br>';

 

if ($tree[$counter]['next_id'] != false) {

tep_show_category($tree[$counter]['next_id']);

}

}

?>

<!-- categories //-->

<tr>

<td>

<?php

 

error_log("*** Start of categories.php ***\n", 3, STORE_PAGE_PARSE_TIME_LOG);

 

$info_box_contents = array();

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

 

new infoBoxHeading($info_box_contents, false, false);

 

$categories_string = '';

$tree = array();

 

$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id, SUM( ( p.products_date_available >= DATE_SUB( CURDATE(),INTERVAL " . TSR_DIAS_PRODUCTO_NUEVO . " DAY ) and ( p.products_status='1' ) ) ) as 'categories_new_prods' from (" . TABLE_CATEGORIES . " c left join " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c on c.categories_id = p2c.categories_id) left join " . TABLE_PRODUCTS . " p on p2c.products_id = p.products_id, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' group by c.categories_id order by sort_order, cd.categories_name");

while ($categories = tep_db_fetch_array($categories_query)) {

$tree[$categories['categories_id']] = array('name' => $categories['categories_name'],

'parent' => $categories['parent_id'],

'level' => 0,

'path' => $categories['categories_id'],

'next_id' => false, 'new_prods' => $categories['categories_new_prods']);

 

if (isset($parent_id)) {

$tree[$parent_id]['next_id'] = $categories['categories_id'];

}

 

$parent_id = $categories['categories_id'];

 

if (!isset($first_element)) {

$first_element = $categories['categories_id'];

}

}

 

//------------------------

if (tep_not_null($cPath)) {

error_log("*** categrories.php cPath = $cPath ***\n", 3, STORE_PAGE_PARSE_TIME_LOG);

 

$aParents = array(); //Lista de Categorías "Padre" (con subcategorías)

 

$rstParents = tep_db_query("SELECT DISTINCT c.parent_id FROM " . TABLE_CATEGORIES . " c ");

while ($rstParent_row = tep_db_fetch_array($rstParents)) {

$aParents[$rstParent_row['parent_id']] = $rstParent_row['parent_id'];

}

 

$new_path = '';

reset($cPath_array);

while (list($key, $value) = each($cPath_array)) {

unset($parent_id);

unset($first_id);

$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id, SUM( ( p.products_date_available >= DATE_SUB( CURDATE(),INTERVAL " . TSR_DIAS_PRODUCTO_NUEVO . " DAY ) and ( p.products_status='1' ) ) ) as 'categories_new_prods' from (" . TABLE_CATEGORIES . " c left join " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c on c.categories_id = p2c.categories_id) left join " . TABLE_PRODUCTS . " p on p2c.products_id = p.products_id, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' group by c.categories_id order by sort_order, cd.categories_name");

 

if (tep_db_num_rows($categories_query)) {

$new_path .= $value;

while ($row = tep_db_fetch_array($categories_query)) {

$tree[$row['categories_id']] = array('name' => $row['categories_name'],

'parent' => $row['parent_id'],

'level' => $key+1,

'path' => $new_path . '_' . $row['categories_id'],

'next_id' => false, 'new_prods' => $row['categories_new_prods']);

 

if (isset($parent_id)) {

$tree[$parent_id]['next_id'] = $row['categories_id'];

}

 

$parent_id = $row['categories_id'];

 

if (!isset($first_id)) {

$first_id = $row['categories_id'];

}

 

$last_id = $row['categories_id'];

 

if ( $aParents[$row['categories_id']]==$row['categories_id'] ) {

//Si se encontró en la lista de "Padres", determinar cuantos CDs nuevos tiene.

$rstNewCDs = tep_db_query("SELECT SUM( ( p.products_date_available >= DATE_SUB( CURDATE(),INTERVAL " . TSR_DIAS_PRODUCTO_NUEVO . " DAY ) AND ( p.products_status='1' ) ) ) AS 'categories_new_prods' FROM (" . TABLE_CATEGORIES . " c LEFT JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c ON c.categories_id = p2c.categories_id) LEFT JOIN " . TABLE_PRODUCTS . " p ON p2c.products_id = p.products_id, " . TABLE_CATEGORIES_DESCRIPTION . " cd WHERE c.parent_id = '" . (int)$parent_id . "' AND c.categories_id = cd.categories_id AND cd.language_id='" . (int)$languages_id ."'");

$rstNewCDs_Row = tep_db_fetch_array($rstNewCDs);

if ( $rstNewCDs_Row['categories_new_prods'] > 0 ) //Si es mayor que cero entonces lo muestra.

$tree[$parent_id]['new_prods'] = $rstNewCDs_Row['categories_new_prods'];

}

 

}

 

$tree[$last_id]['next_id'] = $tree[$value]['next_id'];

$tree[$value]['next_id'] = $first_id;

$new_path .= '_';

} else {

break;

}

}

}

tep_show_category($first_element);

 

$info_box_contents = array();

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

 

new infoBox($info_box_contents);

error_log("*** End of categories.php ***", 3, STORE_PAGE_PARSE_TIME_LOG);

 

?>

</td>

</tr>

<!-- categories_eof //-->

Link to comment
Share on other sites

$categories_string .= '<a href="';

if ($tree[$counter]['parent'] == 0) {
$cPath_new = 'cPath=' . $counter;
} else {
$cPath_new = 'cPath=' . $tree[$counter]['path'];
}

$categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">';

 

try replacing this with:

 

$categories_string .= '<a href="';

$s_name = $tree[$counter]['name'];

$categories_string .= 'advanced_search_result.php?keywords='. $s_name . '">';

 

make a backup first, I'm not sure if it works...

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...