If this is your first visit, check our documentation. To post, register or login.
Forums / Setting Up Your Zen Cart Products / Setting Up Categories, Products, Attributes / Category Linking problem on Main Page (Suspected Reading of Database)

Category Linking problem on Main Page (Suspected Reading of Database)

Locked

Started by denbuzz on 29 Oct 2009, 2:33 AM · Views: 1,800

Results 1 to 1 of 1
This thread is locked. New replies are disabled.
29 Oct 2009, 2:33 AM
#1
denbuzz avatar

denbuzz

New Zenner

Join Date:
Oct 2009
Posts:
11
Plugin Contributions:
0

Post #1 by denbuzz

Dear Zenners,

I have a problem to trouble you all. I am currently a new Zen cart user on 1.3.8a Being bad in designing and programming, I edited a template for myself selling general tools products. In doing so, I wanted to allow for categories, sub categories and sub sub categories to be listed and indented in a different color group. I made use of a programming code who did something like this and this is the result of my tpl_categories.php file:

<?php
/**
 * Side Box Template
 *
 * @package templateSystem
 * @copyright Copyright 2003-2006 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: tpl_categories.php 4162 2006-08-17 03:55:02Z ajeh $
 */
  $content = "";

  $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">' . "\n";
  for ($i=0;$i<sizeof($box_categories_array);$i++)
  {  
	$cPath_array = explode('_', $box_categories_array[$i]['path']);
	$level = count($cPath_array);
	  
    switch(true)
	{
// to make a specific category stand out define a new class in the stylesheet example: A.category-holiday
// uncomment the select below and set the cPath=3 to the cPath= your_categories_id
// many variations of this can be done
//      case ($box_categories_array[$i]['path'] == 'cPath=3'):
//        $new_style = 'category-holiday level'.$level;
//        break;
      case ($box_categories_array[$i]['top'] == 'true'):
        $new_style = 'category-top-level'.$level;
        break;
      case ($box_categories_array[$i]['has_sub_cat']):
        $new_style = 'category-subs-level'.$level;
        break;
      default:
        $new_style = 'category-products-level'.$level;
      }
	  
	  
	if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1))
	{
		// skip if this is for the document box (==3)
	}
	  else
	  {
	  /*#### Wel*/
	  if ($i == 0) { $top = 'no-dots'; } else { $top = ''; }
/*	  $content .= '<div class="categories-top-list">';*/
	  if ($new_style == 'category-top-level'.$level) { $open_tag = '<div class="categories-top-list ' . $top . '">'; } else {$open_tag = '';}
	  /*#### /Wel*/

      $content .= $open_tag . '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
      /*$content .= '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';*/

      if ($box_categories_array[$i]['current']) {
        if ($box_categories_array[$i]['has_sub_cat']) {
          $content .= '<span class="category-subs-parent-level'.$level.'">' . $box_categories_array[$i]['name'] . '</span>';
        } else {
          $content .= '<span class="category-subs-selected-level'.$level.'">' . $box_categories_array[$i]['name'] . '</span>';
        }
      } else {
        $content .= $box_categories_array[$i]['name'];
      }

      if ($box_categories_array[$i]['has_sub_cat']) {
        $content .= CATEGORIES_SEPARATOR;
      }
      $content .= '</a>';

      if (SHOW_COUNTS == 'true') {
        if ((CATEGORIES_COUNT_ZERO == '1' and $box_categories_array[$i]['count'] == 0) or $box_categories_array[$i]['count'] >= 1) {
          $content .= '<span class="sub-count">' . CATEGORIES_COUNT_PREFIX . $box_categories_array[$i]['count'] . CATEGORIES_COUNT_SUFFIX . '</span>';
        }
      }
	  /*#### Wel*/
	  if ($new_style == 'category-top-level'.$level) { $close_tag = '</div>'; } else { $close_tag = ''; };
	  /*#### /Wel*/
	  $content .= $close_tag . "\n";
	  /*$content .= '' . "\n";*/
    }
  }

  if (SHOW_CATEGORIES_BOX_SPECIALS == 'true' or SHOW_CATEGORIES_BOX_PRODUCTS_NEW == 'true' or SHOW_CATEGORIES_BOX_FEATURED_PRODUCTS == 'true' or SHOW_CATEGORIES_BOX_PRODUCTS_ALL == 'true') {
// display a separator between categories and links
    if (SHOW_CATEGORIES_SEPARATOR_LINK == '1') {
      $content .= '<hr id="catBoxDivider" />' . "\n";
    }
    if (SHOW_CATEGORIES_BOX_SPECIALS == 'true') {
      $show_this = $db->Execute("select s.products_id from " . TABLE_SPECIALS . " s where s.status= 1 limit 1");
      if ($show_this->RecordCount() > 0) {
        $content .= '<a class="category-links-level'.$level.'" href="' . zen_href_link(FILENAME_SPECIALS) . '">' . CATEGORIES_BOX_HEADING_SPECIALS . '</a>' . '' . "\n";
      }
    }
    if (SHOW_CATEGORIES_BOX_PRODUCTS_NEW == 'true') {
      // display limits
//      $display_limit = zen_get_products_new_timelimit();
      $display_limit = zen_get_new_date_range();

      $show_this = $db->Execute("select p.products_id
                                 from " . TABLE_PRODUCTS . " p
                                 where p.products_status = 1 " . $display_limit . " limit 1");
      if ($show_this->RecordCount() > 0) {
        $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_PRODUCTS_NEW) . '">' . CATEGORIES_BOX_HEADING_WHATS_NEW . '</a>' . '' . "\n";
      }
    }
    if (SHOW_CATEGORIES_BOX_FEATURED_PRODUCTS == 'true') {
      $show_this = $db->Execute("select products_id from " . TABLE_FEATURED . " where status= 1 limit 1");
      if ($show_this->RecordCount() > 0) {
        $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_FEATURED_PRODUCTS) . '">' . CATEGORIES_BOX_HEADING_FEATURED_PRODUCTS . '</a>' . '' . "\n";
      }
    }
    if (SHOW_CATEGORIES_BOX_PRODUCTS_ALL == 'true') {
      $content .= '<a class="category-links-level'.$level.'" href="' . zen_href_link(FILENAME_PRODUCTS_ALL) . '">' . CATEGORIES_BOX_HEADING_PRODUCTS_ALL . '</a>' . "\n";
    }
  }
  $content .= '</div>';
?>

After solving the side box formatting however, I am faced with some problems. My categories displayed in the main page has very bad handling with the display of products and their sub categories and sub sub categories.

From this picture, I am actually under the fastening tool sub category. But my main page is showing all the Top Categories.
Picture 1:

From this picture, I clicked on one of the categories from the main page but I ended up in another category with the sub categories listed under there. (See bread crumbds Testing & Measurement :: Adhesives & Fastening.

If i used the side box to do my navigation, everything works fine. But the minute i navigate using the main page, everything goes awry.

I believe its the way the main page is reading cpath from the database and populating cos of the web source. I apologise not being able to show the website over the net as its being developed locally and I dont have a database up yet in the server. But here is the code showing the side box and main page's content.

<div class="leftBoxContainer" id="information" style="width: 150px">
<div class="sidebox-header-left "><h3 class="leftBoxHeading " id="informationHeading">Information</h3></div>
<div id="informationContent" class="sideBoxContent">
<ul style="margin: 0; padding: 0; list-style-type: none;">
<li><a href="http://www.example.com/zencart/index.php?main_page=shippinginfo">Shipping & Returns</a></li>
<li><a href="http://www.example.com/zencart/index.php?main_page=privacy">Privacy Notice</a></li>
<li><a href="http://www.example.com/zencart/index.php?main_page=conditions">Conditions of Use</a></li>
<li><a href="http://www.example.com/zencart/index.php?main_page=contact_us">Contact Us</a></li>

<li><a href="http://www.example.com/zencart/index.php?main_page=site_map">Site Map</a></li>
<li><a href="http://www.example.com/zencart/index.php?main_page=gv_faq">Gift Certificate FAQ</a></li>
<li><a href="http://www.example.com/zencart/index.php?main_page=discount_coupon">Discount Coupons</a></li>
<li><a href="http://www.example.com/zencart/index.php?main_page=unsubscribe">Newsletter Unsubscribe</a></li>
</ul>
</div></div>
<!--// eof: information //-->
</div></td>
    <td id="columnCenter" valign="top">
<!-- bof  breadcrumb -->
    <div id="navBreadCrumb">  <a href="http://www.example.com/zencart/">Home</a> :: 

  <a href="http://www.example.com/zencart/index.php?main_page=index&cPath=65">Adhesives, Screws & Fastening</a> :: 
Fastening Tools
</div>
<!-- eof breadcrumb -->


<!-- bof upload alerts -->
<!-- eof upload alerts -->

<div class="centerColumn" id="indexCategories">
<h1 id="indexCategoriesHeading">Fastening Tools</h1>

<!-- BOF: Display grid of available sub-categories, if any -->

    <div class="categoryListBoxContents" style="width:33%;"><a href="http://www.example.com/zencart/index.php?main_page=index&cPath=cPath=73_97"><img src="images/pixel_trans.gif" alt="Abrasives" title=" Abrasives " width="1" height="1" /><br />Abrasives</a></div>
    <div class="categoryListBoxContents" style="width:33%;"><a href="http://www.example.com/zencart/index.php?main_page=index&cPath=cPath=73_65"><img src="images/pixel_trans.gif" alt="Adhesives, Screws & Fastening" title=" Adhesives, Screws & Fastening " width="1" height="1" /><br />Adhesives, Screws & Fastening</a></div>
    <div class="categoryListBoxContents" style="width:33%;"><a href="http://www.example.com/zencart/index.php?main_page=index&cPath=cPath=73_67"><img src="images/pixel_trans.gif" alt="Air, Hydraulic and Power Tools" title=" Air, Hydraulic and Power Tools " width="1" height="1" /><br />Air, Hydraulic and Power Tools</a></div>
<br class="clearBoth" />

    <div class="categoryListBoxContents" style="width:33%;"><a href="http://www.example.com/zencart/index.php?main_page=index&cPath=cPath=73_66"><img src="images/pixel_trans.gif" alt="Canvas & Boards" title=" Canvas & Boards " width="1" height="1" /><br />Canvas & Boards</a></div>

    <div class="categoryListBoxContents" style="width:33%;"><a href="http://www.example.com/zencart/index.php?main_page=index&cPath=cPath=73_95"><img src="images/pixel_trans.gif" alt="Castor & Wheels" title=" Castor & Wheels " width="1" height="1" /><br />Castor & Wheels</a></div>
    <div class="categoryListBoxContents" style="width:33%;"><a href="http://www.example.com/zencart/index.php?main_page=index&cPath=cPath=73_76"><img src="images/pixel_trans.gif" alt="Drilling, Welding and Cutting" title=" Drilling, Welding and Cutting " width="1" height="1" /><br />Drilling, Welding and Cutting</a></div>
<br class="clearBoth" />

    <div class="categoryListBoxContents" style="width:33%;"><a href="http://www.example.com/zencart/index.php?main_page=index&cPath=cPath=73_68"><img src="images/pixel_trans.gif" alt="Hand Tools & Sockets" title=" Hand Tools & Sockets " width="1" height="1" /><br />Hand Tools & Sockets</a></div>
    <div class="categoryListBoxContents" style="width:33%;"><a href="http://www.example.com/zencart/index.php?main_page=index&cPath=cPath=73_74"><img src="images/pixel_trans.gif" alt="Household Usage" title=" Household Usage " width="1" height="1" /><br />Household Usage</a></div>
    <div class="categoryListBoxContents" style="width:33%;"><a href="http://www.example.com/zencart/index.php?main_page=index&cPath=cPath=73_71"><img src="images/pixel_trans.gif" alt="Industrial Consumables" title=" Industrial Consumables " width="1" height="1" /><br />Industrial Consumables</a></div>

<br class="clearBoth" />

    <div class="categoryListBoxContents" style="width:33%;"><a href="http://www.example.com/zencart/index.php?main_page=index&cPath=cPath=73_96"><img src="images/pixel_trans.gif" alt="Light Machinery" title=" Light Machinery " width="1" height="1" /><br />Light Machinery</a></div>
    <div class="categoryListBoxContents" style="width:33%;"><a href="http://www.example.com/zencart/index.php?main_page=index&cPath=cPath=73_77"><img src="images/pixel_trans.gif" alt="Material Handling" title=" Material Handling " width="1" height="1" /><br />Material Handling</a></div>
    <div class="categoryListBoxContents" style="width:33%;"><a href="http://www.example.com/zencart/index.php?main_page=index&cPath=cPath=73_70"><img src="images/pixel_trans.gif" alt="Materials" title=" Materials " width="1" height="1" /><br />Materials</a></div>
<br class="clearBoth" />

    <div class="categoryListBoxContents" style="width:33%;"><a href="http://www.example.com/zencart/index.php?main_page=index&cPath=cPath=73_69"><img src="images/pixel_trans.gif" alt="Paints & Drawing" title=" Paints & Drawing " width="1" height="1" /><br />Paints & Drawing</a></div>

    <div class="categoryListBoxContents" style="width:33%;"><a href="http://www.example.com/zencart/index.php?main_page=index&cPath=cPath=73_75"><img src="images/pixel_trans.gif" alt="Pipes & Tubes" title=" Pipes & Tubes " width="1" height="1" /><br />Pipes & Tubes</a></div>
    <div class="categoryListBoxContents" style="width:33%;"><a href="http://www.example.com/zencart/index.php?main_page=index&cPath=cPath=73_72"><img src="images/pixel_trans.gif" alt="Safety Equipment" title=" Safety Equipment " width="1" height="1" /><br />Safety Equipment</a></div>
<br class="clearBoth" />

    <div class="categoryListBoxContents" style="width:33%;"><a href="http://www.example.com/zencart/index.php?main_page=index&cPath=cPath=73_73"><img src="images/pixel_trans.gif" alt="Testing & Measurement" title=" Testing & Measurement " width="1" height="1" /><br />Testing & Measurement</a></div>
<br class="clearBoth" />
 
<!-- EOF: Display grid of available sub-categories -->

Would appreciate it if any one can help me to modify the codes or point out where I went wrong.

Thank you.