Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Problem with "Show Subs" contribution


mitjan

Recommended Posts

Installed this contribution (i'm using oscommerce-2.2ms1). Everything is fine but when one is on subcategory page there is something wrong with main category links:

 

The generated path is like this default.php?cPath=21_22_21

but it should be like this default.php?cPath=21

 

You can see it here

http://www.astrologija.org/trgovina/defaul...php?cPath=21_22

(wrong links are bolded in left column).

 

Here is the code (catalog/includes/boxes/categories.php):

<?php

/*

 $Id: show_subcategories.php,v 1.0 2003/01/08 10:37:00 Exp $



 osCommerce, Open Source E-Commerce Solutions

 http://www.oscommerce.com/



 Based on: main_categories.php Ver. 1.0 by Gustavo Barreto



 History: 1.0 Creation



 Released under the GNU General Public License



*/



// Preorder tree traversal

 function preorder($cid, $level, $foo, $cpath)

 {

   global $categories_string, $HTTP_GET_VARS;



// Display link

   if ($cid != 0) {

     for ($i=0; $i<$level; $i++)

       $categories_string .=  '  ';

     $categories_string .= '<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath

=' . $cpath . $cid) . '">';

// 1.6 Are we on the "path" to selected category?

     $bold = strstr($HTTP_GET_VARS['cPath'], $cpath . $cid . '_') ||  $HTTP_GET_VARS['cPath'] == $cpath . $cid;

// 1.6 If yes, use <b>

     if ($bold)

       $categories_string .=  '<b>';

     $categories_string .=  $foo[$cid]['name'];

     if ($bold)

       $categories_string .=  '</b>';

     $categories_string .=  '</a>';

// 1.4 SHOW_COUNTS is 'true' or 'false', not true or false

     if (SHOW_COUNTS == 'true') {

       $products_in_category = tep_count_products_in_category($cid);

       if ($products_in_category > 0) {

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

       }

     }

     $categories_string .= '<br>';

   }



// Traverse category tree- this is for older snapshots pre-November 2002

/*    foreach ($foo as $key => $value) {

     if ($foo[$key]['parent'] == $cid) {

//        print "$key, $level, $cid, $cpath<br>";

       preorder($key, $level+1, $foo, ($level != 0 ? $cpath . $cid . '_' : ''))
;

     } */

// Function used for post November 2002 snapshots

 function tep_show_category($counter) {

   global $foo, $categories_string, $id;



   for ($a=0; $a<$foo[$counter]['level']; $a++) {

     $categories_string .= "  ";

   }

   }

 }



?>

<!-- show_subcategories //-->

         <tr>

           <td>

           <TABLE WIDTH=135 BORDER=0 CELLPADDING=0 CELLSPACING=0>

<TR>

<TD COLSPAN=3 class="infoBoxHeading"><img src="images/infobox/2oddelki.gif" border="0" alt="Oddelki" width="135" height="60" hspace="0" vspace="0"></TD>

</TR>

<TR>

<TD>



<?php

global $css_class;

global $cell_padding;

$css_class = "infoBoxContents";

$cell_padding = "5";

$info_box_contents_info = array();





/*

//////////

// Display box heading

//////////

 $info_box_contents = array();

 $info_box_contents[] = array('align' => 'left', 'text'  => BOX_HEADING_CATEGORIES);

 new infoBoxHeading($info_box_contents, true, false);

 */





//////////

// Get categories list

//////////

// 1.2 Test for presence of status field for compatibility with older versions

//  $status = tep_db_num_rows(tep_db_query('describe categories status')); used for older snapshots

$status = tep_db_num_rows(tep_db_query('describe ' .  TABLE_CATEGORIES . ' status'));





 $query = "select c.categories_id, cd.categories_name, c.parent_id, c.categories_image

           from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd

           where c.categories_id = cd.categories_id";

// 1.3 Can't have 'where' in an if statement!

 if ($status >0)

   $query.= " and c.status = '1'";

 $query.= " and cd.language_id='" . $languages_id ."'

           order by sort_order, cd.categories_name";



 $categories_query = tep_db_query($query);





// Initiate tree traverse

 $categories_string = '';

 preorder(0, 0, $foo, '');



//////////

// Display box contents

//////////

 $info_box_contents = array();

 $row = 0;

 $col = 0;

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

  if ($categories['parent_id'] == 0) {

   $cPath_new = tep_get_path($categories['categories_id']);$text_subcategories = '';

   $subcategories_query = tep_db_query($query);

    while ($subcategories = tep_db_fetch_array($subcategories_query)) {

               if ($subcategories['parent_id'] == $categories['categories_id'])

{

               $cPath_new_sub = "cPath="  . $categories['categories_id'] . "_" . $subcategories['categories_id'];



               $text_subcategories .= '<a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new_sub, 'NONSSL') . '"><br>' . $subcategories['categories_name'] . '</a>' . " ";

               } // if

    } // While Interno

   $info_box_contents[$row] = array('align' => 'left',

                                          'params' => 'class="smallText" width="135" valign="top"',

                                          'text' => '<a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new, 'NONSSL') . '"><b>' . $categories['categories_name'] . '</b></a>' . $text_subcategories);

   $col ++;

   if ($col > 0) {

     $col = 0;

     $row ++;

   }

  }

 }

 $info_box_contents[] = array('align' => 'left',

                              'text'  => '<small><a href="' . tep_href_link(FILENAME_ALLPRODS, '', 'NONSSL') . '"><img src="images/puscica2.gif" border="0" alt="" width="4" height="12" hspace="0" vspace="0" align="absbottom"> ' . BOX_INFORMATION_ALLPRODS . '</a></small>');



 new infoBox($info_box_contents);

?>

           

</TD>

</TR>

</TABLE>

</td>

         </tr>

<!-- show_subcategories_eof //-->

 

Can anybody help, please???

Mitja

Link to comment
Share on other sites

  • 2 months later...
You can see it here

http://www.astrologija.org/trgovina/defaul...php?cPath=21_22

(wrong links are bolded in left column).

 

Mitjan, looking at your site now it seems as if you've figured out how to fix this bug. I've been having the same problem with the code. Could you share with us how you fixed it? It would be great if you could post your fixed categories.php code here for the rest of us!

 

Thanks!

 

-

Mike

Link to comment
Share on other sites

  • 2 weeks later...

Hm, dont remember what i did.

 

Here is my categories.php, hope its usefull:

 

<?php

/*

 $Id: show_subcategories.php,v 1.0 2003/01/08 10:37:00 Exp $



 osCommerce, Open Source E-Commerce Solutions

 http://www.oscommerce.com/



 Based on: main_categories.php Ver. 1.0 by Gustavo Barreto



 History: 1.0 Creation



 Released under the GNU General Public License



*/



// Preorder tree traversal

 function preorder($cid, $level, $foo, $cpath)

 {

   global $categories_string, $HTTP_GET_VARS;



// Display link

   if ($cid != 0) {

     for ($i=0; $i<$level; $i++)

       $categories_string .=  ' ';

     $categories_string .= '<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $cpath . $cid) . '">';

// 1.6 Are we on the "path" to selected category?

     $bold = strstr($HTTP_GET_VARS['cPath'], $cpath . $cid . '_') ||  $HTTP_GET_VARS['cPath'] == $cpath . $cid;

// 1.6 If yes, use <b>

     if ($bold)

       $categories_string .=  '<b>';

     $categories_string .=  $foo[$cid]['name'];

     if ($bold)

       $categories_string .=  '</b>';

     $categories_string .=  '</a>';

// 1.4 SHOW_COUNTS is 'true' or 'false', not true or false

     if (SHOW_COUNTS == 'true') {

       $products_in_category = tep_count_products_in_category($cid);

       if ($products_in_category > 0) {

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

       }

     }

     $categories_string .= '<br>';

   }



// Traverse category tree- this is for older snapshots pre-November 2002

/*    foreach ($foo as $key => $value) {

     if ($foo[$key]['parent'] == $cid) {

//        print "$key, $level, $cid, $cpath<br>";

       preorder($key, $level+1, $foo, ($level != 0 ? $cpath . $cid . '_' : ''))
;

     } */

// Function used for post November 2002 snapshots

 function tep_show_category($counter) {

   global $foo, $categories_string, $id;



   for ($a=0; $a<$foo[$counter]['level']; $a++) {

     $categories_string .= "  ";

   }

   }

 }



?>

<!-- show_subcategories //-->

         <tr>

           <td>

           <TABLE WIDTH=135 BORDER=0 CELLPADDING=0 CELLSPACING=0>

<TR>

<TD COLSPAN=3 class="infoBoxHeading"><img src="images/infobox/2oddelki.gif" border="0" alt="Oddelki" width="135" height="60" hspace="0" vspace="0"></TD>

</TR>

<TR>

<TD>



<?php

global $css_class;

global $cell_padding;

$css_class = "infoBoxContents";

$cell_padding = "5";

$info_box_contents_info = array();





/*

//////////

// Display box heading

//////////

 $info_box_contents = array();

 $info_box_contents[] = array('align' => 'left', 'text'  => BOX_HEADING_CATEGORIES);

 new infoBoxHeading($info_box_contents, true, false);

 */





//////////

// Get categories list

//////////

// 1.2 Test for presence of status field for compatibility with older versions

//  $status = tep_db_num_rows(tep_db_query('describe categories status')); used for older snapshots

$status = tep_db_num_rows(tep_db_query('describe ' .  TABLE_CATEGORIES . ' status'));





 $query = "select c.categories_id, cd.categories_name, c.parent_id, c.categories_image

           from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd

           where c.categories_id = cd.categories_id";

// 1.3 Can't have 'where' in an if statement!

 if ($status >0)

   $query.= " and c.status = '1'";

 $query.= " and cd.language_id='" . $languages_id ."'

           order by sort_order, cd.categories_name";



 $categories_query = tep_db_query($query);





// Initiate tree traverse

 $categories_string = '';

 preorder(0, 0, $foo, '');



//////////

// Display box contents

//////////

 $info_box_contents = array();

 $row = 0;

 $col = 0;

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

  if ($categories['parent_id'] == 0) {

   $cPath_new = "cPath="  .$categories['categories_id'];$text_subcategories = '';

   $subcategories_query = tep_db_query($query);

    while ($subcategories = tep_db_fetch_array($subcategories_query)) {

               if ($subcategories['parent_id'] == $categories['categories_id'])

{

               $cPath_new_sub = "cPath="  . $categories['categories_id'] . "_" . $subcategories['categories_id'];



               $text_subcategories .= '<a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new_sub, 'NONSSL') . '"><br>' . $subcategories['categories_name'] . '</a>' . " ";

               } // if

    } // While Interno

   $info_box_contents[$row] = array('align' => 'left',

                                          'params' => 'class="smallText" width="135" valign="top"',

                                          'text' => '<a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new, 'NONSSL') . '"><b>' . $categories['categories_name'] . '</b></a>' . $text_subcategories);

   $col ++;

   if ($col > 0) {

     $col = 0;

     $row ++;

   }

  }

 }

 $info_box_contents[] = array('align' => 'left',

                              'text'  => '<small><a href="' . tep_href_link(FILENAME_ALLPRODS, '', 'NONSSL') . '"><img src="images/puscica1.gif" border="0" alt="" width="6" height="12" hspace="0" vspace="0" align="middle"> ' . BOX_INFORMATION_ALLPRODS . '</a></small>');



 new infoBox($info_box_contents);

?>

           

</TD>

</TR>

</TABLE>

</td>

         </tr>

<!-- show_subcategories_eof //-->

Mitja

Link to comment
Share on other sites

  • 4 weeks later...

I had the same problem. Thanks for posting your code! Mine was different in the Dispaly Box Contents section and this line of yours is what fixed it for me:

 

$cPath_new = "cPath="  .$categories['categories_id'];$text_subcategories = '';

 

-shaun

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...