michelew Posted August 2, 2004 Posted August 2, 2004 Probably something you should now when you work with php. I'm having trouble to figure out how cpath works, more precisely if I have: .../catalog/index.php?cPath=21_35 Where in the code of index.php do I find the way 21_35 is being matched to categorie 21 and subcategory 35 of the database. Which calculation in which query (if a query is involved) refers to these id's. The reason why I need to know this is because I added an id to the link, which would give: .../catalog/index.php?cPath=21_35_1 This refers to an extra field I added to the table "products_to_categories". If you think what I explain is incomplete or not clear, feel free to ask details. Thank you for reading and eventually answering this question. Mich?le
241 Posted August 2, 2004 Posted August 2, 2004 The initial part is done in catalog/includes/application_top.php // calculate category path if (isset($HTTP_GET_VARS['cPath'])) { $cPath = $HTTP_GET_VARS['cPath']; } elseif (isset($HTTP_GET_VARS['products_id']) && !isset($HTTP_GET_VARS['manufacturers_id'])) { $cPath = tep_get_product_path($HTTP_GET_VARS['products_id']); } else { $cPath = ''; } if (tep_not_null($cPath)) { $cPath_array = tep_parse_category_path($cPath); $cPath = implode('_', $cPath_array); $current_category_id = $cPath_array[(sizeof($cPath_array)-1)]; } else { $current_category_id = 0; } this is then used in index.php to work out if category depth is top categoy or sub category. // the following cPath references come from application_top.php $category_depth = 'top'; if (isset($cPath) && tep_not_null($cPath)) { $categories_products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'"); $cateqories_products = tep_db_fetch_array($categories_products_query); if ($cateqories_products['total'] > 0) { $category_depth = 'products'; // display products } else { $category_parent_query = tep_db_query("select count(*) as total from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$current_category_id . "'"); $category_parent = tep_db_fetch_array($category_parent_query); if ($category_parent['total'] > 0) { $category_depth = 'nested'; // navigate through the categories } else { $category_depth = 'products'; // category has no products, but display the 'no products' message } } } also used here <?php if ($category_depth == 'nested') { $category_query = tep_db_query("select cd.categories_name, c.categories_image from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = '" . (int)$current_category_id . "' and cd.categories_id = '" . (int)$current_category_id . "' and cd.language_id = '" . (int)$languages_id . "'"); $category = tep_db_fetch_array($category_query); ?> and here <?php if (isset($cPath) && strpos('_', $cPath)) { // check to see if there are deeper categories within the current category $category_links = array_reverse($cPath_array); for($i=0, $n=sizeof($category_links); $i<$n; $i++) { $categories_query = tep_db_query("select count(*) as total from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$category_links[$i] . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "'"); $categories = tep_db_fetch_array($categories_query); if ($categories['total'] < 1) { // do nothing, go through the loop } else { $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.categories_image, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$category_links[$i] . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' order by sort_order, cd.categories_name"); break; // we've found the deepest category the customer is in } } } else { $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.categories_image, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$current_category_id . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' order by sort_order, cd.categories_name"); } $number_of_categories = tep_db_num_rows($categories_query); $rows = 0; while ($categories = tep_db_fetch_array($categories_query)) { $rows++; $cPath_new = tep_get_path($categories['categories_id']); $width = (int)(100 / MAX_DISPLAY_CATEGORIES_PER_ROW) . '%'; echo ' <td align="center" class="smallText" width="' . $width . '" valign="top"><a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">' . tep_image(DIR_WS_IMAGES . $categories['categories_image'], $categories['categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) . '<br>' . $categories['categories_name'] . '</a></td>' . "\n"; if ((($rows / MAX_DISPLAY_CATEGORIES_PER_ROW) == floor($rows / MAX_DISPLAY_CATEGORIES_PER_ROW)) && ($rows != $number_of_categories)) { echo ' </tr>' . "\n"; echo ' <tr>' . "\n"; } } with a statement here for the listings } elseif ($category_depth == 'products' || isset($HTTP_GET_VARS['manufacturers_id'])) { // create column list No longer giving free advice. Please place deposit in meter slot provided. Individual: [=] SME: [==] Corporation: [===] If deposit does not fit one of the slots provided then you are asking too much! Is your Osc dated try Phoenix raising oscommerce from the ashes.
michelew Posted August 2, 2004 Author Posted August 2, 2004 Great Steve! What a complete answer. Thanks. Mich?le
tapaule Posted September 29, 2004 Posted September 29, 2004 For some reason I am having a problem around this issue. Seems that some categories I added are not displaying properly on index.php, but they are fine in the categories box. That is, the catalog box shows the sub-categories properly, but when selecting a category with certain sub-categories index.php says "There are no products to list in this category." when there are several sub-categories. I know this is directly related to applicaiton_top.php, specifically this query: "select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'" as is does not return a total greater than 0, so it diplays products (which there are none, just subcategories. I am stumped as to why it doesn't work correctly, as the data in the products_to_categories table seems to relate everything correctly. Any advice is greatly appreciated! Tom
Jerah Posted October 6, 2004 Posted October 6, 2004 For some reason I am having a problem around this issue. Seems that some categories I added are not displaying properly on index.php, but they are fine in the categories box. That is, the catalog box shows the sub-categories properly, but when selecting a category with certain sub-categories index.php says "There are no products to list in this category." when there are several sub-categories. Having the same problem here, but it appears only with one category.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.