Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Browse by Categories


Guest

Recommended Posts

Yan,

 

I'm glad you worked it out successfully.

 

The latest release, v2.5, has 2 SQL files. Only use one of them, depending on either you have never installed this contribution (browse_categories-install.sql) or you have previously installed a former release (browse_categories-update.sql).

 

The SQL statements define a new configuration group, with ID 101, inside the configuration_group table and insert 6 new variable settings inside configuration table, all having the same 101 group ID.

 

This SQL statement is used only for fresh installations, and configures the new group ID:

INSERT INTO configuration_group (
 configuration_group_id, configuration_group_title, configuration_group_description, sort_order, visible)
VALUES
(101, 'Browse by Categories', 'Browse by Categories options', 101, 1);

This SQL statement is used only for existing installations, and removes former variable settings:

DELETE FROM configuration WHERE configuration_key in (
 'DISPLAY_BROWSE_CATEGORIES', 'BROWSE_CATEGORIES_TYPE', 'DISPLAY_BROWSE_SUB_CATEGORIES', 'MAX_BROWSE_CATEGORIES_PER_ROW',
 'POSITION_SUB_CATEGORIES', 'BULLET_BROWSE_SUB_CATEGORIES', 'DISPLAY_SUB_CATEGORIES_COUNT'
);

This SQL statement adds the necessary variable settings, with their default values. These settings can be changed from the configuration section of the administration area, under Browse by Categories option:

INSERT INTO configuration (
 configuration_title, configuration_key, configuration_value, configuration_description,
 configuration_group_id, sort_order, set_function, date_added
) VALUES
 ('Category Icon Mode', 'BRWCAT_ICON_MODE', 'image with caption', 'Choose between Disabled, Text and Image without or with Caption for Current Level Categories Icons.<br /><b>Note</b>: Image Only mode causes the category name to be displayed on top of its sub-category links.', '101', '1', 'tep_cfg_select_option(array(\'off\', \'text\', \'image only\', \'image with caption\'), ', now()),
 ('Sub-Category Link Mode', 'BRWCAT_SUBCAT_MODE', 'right top', 'Choose between Disabled, Bottom or Right position of Sub-Category Links.', '101', '2', 'tep_cfg_select_option(array(\'off\', \'bottom\', \'right top\', \'right middle\', \'right bottom\'), ', now()),
 ('Max number of category Icons per Row', 'BRWCAT_ICONS_PER_ROW', '2', 'Choose how many Current Level Categories to display per row.', '101', '3', null, now()),
 ('Sub-Category Links Bullet', 'BRWCAT_SUBCAT_BULLET', '?', 'Select Bullet character to prefix each Sub Category Link.', '101', '4', null, now()),
 ('Sub-Category Products Count', 'BRWCAT_SUBCAT_COUNTS', '(%s)', 'Define sprintf format to display Sub-Category Products count.<br /><b>Note</b>: Default format is (%s) that causes the products count to be displayed surrounded by parentesis. For more information, read the PHP manual for sprintf function.', '101', '5', null, now()),
 ('Category Name Case', 'BRWCAT_NAME_CASE', 'same', 'Choose between same case, upper case, lower case or title case for Current Level Categories Name.', '101', '6', 'tep_cfg_select_option(array(\'same\', \'upper\', \'lower\', \'title\'), ', now());

Link to comment
Share on other sites

  • Replies 190
  • Created
  • Last Reply

Top Posters In This Topic

  • 2 weeks later...

Thanks for the contribution! I have one problem after I installed it. The "Browse by category" box does not show in the catalog at all. I am using MS2 version 2.2 and the BTS (Basic Template System) mod's installed as well. May I as if that's the reason why it does not show? Please shed some light on this, thanks very much! :)

Best regards,

 

Elmo

Link to comment
Share on other sites

Hey guys,

thanks heaps for this contrib, it's just what i've been hunting for. Though what i am really trying to get is browse by categories without the subcategories listed next to the images.

 

Can anyone help me here?

 

Cheers,

Kieran

___________________________

Kieran

[email protected]

Link to comment
Share on other sites

okay.. a couple of slight probs..

 

when i browse sub categories, i get 2 listings of them.. one put there by oscommerce as per default, and one put there by browse by categories.

 

my other prob is the right menu bar being moved to the bottom left of the page just before the footer when i browse sub category pages.

 

URL to my prob: http://www.test1234.arach.net.au/oscommerc...dex.php?cPath=1

 

I would be most grateful to any assistance you can provide?

 

Cheers,

Kieran

___________________________

Kieran

[email protected]

Link to comment
Share on other sites

  • 3 weeks later...

Elmo,

 

I'm sorry I can't help you much on this. I don't use BTS or any other Template System, so I don't know if that can be the cause of problem or not.

 

Have you configured the settings on the database, through the Administration? Do you see the sub-category icons when you click on a top level category?

 

Try to capture the lines of code in index.php (MS2) that present the new products at top-level and the sub-category icons. Maybe I can help you out, or someone else that uses BTS can shed some light.

 

:)

Edited by straider
Link to comment
Share on other sites

Hi Strider,

 

Thanks very much for your reply! I tried different ways including adding the necessary codes to index_default.tpl.php (supposed to be added to index.php but since I have BTS so I tried to see if that work. And it did not work. The following is my index_default.tpl.php:

 

    <table border="0" width="100%" cellspacing="0" cellpadding="0">
     <tr>
       <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
         <tr>
                       <td class="pageHeading">
            <?php 
              if ( (ALLOW_CATEGORY_DESCRIPTIONS == 'true') && (tep_not_null($category['categories_heading_title'])) ) {
                echo $category['categories_heading_title'];
              } else {
                echo HEADING_TITLE;
              }
            ?>
  <?php if ( (ALLOW_CATEGORY_DESCRIPTIONS == 'true') && (tep_not_null($category['categories_description'])) ) { ?>
  <tr>
           <td align="left" colspan="2" class="category_desc"><?php echo $category['categories_description']; ?></td>
  </tr>
  <?php } ?>
           </td>
           <td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_default.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
         </tr>

          </table></td>
     </tr>
     <tr>
       <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
     </tr>
     <tr>
       <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
         <tr>
           <td class="main"><?php echo tep_customer_greeting(); ?></td>
         </tr>
         <tr>
           <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
         </tr>
         <tr>
           <td class="main"><?php include(DIR_WS_LANGUAGES . $language . '/' . FILENAME_DEFINE_MAINPAGE); ?></td>
         </tr>
         <tr>
           <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
         </tr>
         <tr>
           <td><br><?php include(DIR_WS_MODULES . FILENAME_DEFAULT_SPECIALS); ?></td>
         </tr>
         <tr>
           <td><br><?php include(DIR_WS_MODULES . FILENAME_NEW_PRODUCTS); ?></td>
         </tr>













         <!-- DWD Contribution -> Remove: Browse by Categories v2.2. //-->
         <!--
         <tr>
           <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
             <tr>
         //-->
         <!-- DWD Contribution End. //-->
<?php
   // DWD Contribution -> Remove: Browse by Categories v2.2.
//     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";
//       }
//     }
   // DWD Contribution End.

// needed for the new products module shown below
   $new_products_category_id = $current_category_id;
?>
         <!-- DWD Contribution -> Remove: Browse by Categories v2.2. !-->
         <!--
             </tr>
           </table></td>
         </tr>
         //-->
         <!-- DWD Contribution End. //-->

         
















<!-- BEGIN latest news -->
<tr>
  <td><br><?php define('LATEST_NEWS_BOX', "classic");
                include(DIR_WS_MODULES . FILENAME_LATEST_NEWS); ?></td>
</tr>
<!-- END latest news -->





<?php
   include(DIR_WS_MODULES . FILENAME_UPCOMING_PRODUCTS);
?>
       </table></td>
     </tr>
   </table>

Best regards,

 

Elmo

Link to comment
Share on other sites

elmo,

 

Two things:

1. if you didn't have the commented code uncommented before then you don't need to add it. I'm saying this because usually that code appears before the Specials and What's New content boxes. I see that you wish to add the Browse by Categories after those two content boxes. And that's ok. Meaning: don't add the lines starting with // after

// DWD Contribution -> Remove: Browse by Categories v2.2.

because you may not have them at all in your source code file.

2. the problem seems to be that you're not including the Browse by Categories module. I can't find the lines with

         <!-- DWD Contribution -> Add: Browse by Categories v2.0. !-->
        <tr>
          <td><?php $browse_category_id = $current_category_id; include(DIR_WS_MODULES . FILENAME_BROWSE_CATEGORIES); ?></td>
        </tr>
        <!-- DWD Contribution End. !-->

Include this code before Latest News or where you wish the Browse by Categories content box to appear. Please, see this post for more information.

 

That should do it.

Edited by straider
Link to comment
Share on other sites

  • 2 weeks later...

I was wondering where and what file i could past this code"<?php $browse_category_id = $current_category_id; include(DIR_WS_MODULES . FILENAME_BROWSE_CATEGORIES); ?>" so that the Categories only show up on the main page when a user conects to the site.......For instance i only want to display all the categories only when the user is on the main catalog page and not when they browse further into subcategories.....I am using the catalog-2.2-MS2 version......Also how can i make all subcatergoreis to appear within other subcatergories.....I.E Cars and trucks>>new>>parts

Link to comment
Share on other sites

dasoccerbomb,

 

In index.php, you must add twice those code lines: one right after the section where you comment out several lines of code and the other several lines below those code lines. The first added code lines are for when the visitor is browsing at a sub-category level, and replaces the previous commented out code lines. The second added code lines are for when the visitor enters the catalog.

 

By knowing this, you don't need to add the first code lines after the commented out ones, which will cause the content box of browse by categories not to appear after the visitor clicks in one of the top level categories, and for that matter will not appear again unless the visitor goes back to the start of the catalog.

 

It's up to you to either comment out or not the lines of code for the sub-categories icons. The lines that the installation states to be commented out are meant to show to the visitor the sub-category icons of the current selected category, and for what I understand you don't want this to happen, neither with Browse by Categories neither with the original index.php. Follow only the changes for lines between 300 and 314, not any other former changes. And comment out the lines 99 to 109. Hope this is helpful.

 

About your other question, sorry but that was never designed and the module is not capable of displaying an entire category hierarchy as it is. It would require a recurrent loop to grab the sub-categories of each category, starting at top level, and that was never a feature for this module to present. Maybe someone else cares to code this feature, I can discuss it but I don't have the spare time right now to design and code it.

 

Thanks.

Link to comment
Share on other sites

Great work!

 

This contribution gives me the opportunity to redesign my site, and to ged rid of the category-box in the left-column.

 

Just two problems to solve: It is possible to come back from the 2th level to the 1st level, but what can I do to get from the product's list to the subcategory and from the product to the product's list. There is no "back"-tab or something like that.

 

Has anyone an idea?

 

Klaus Carls

 

www.uhren-carls.de

Link to comment
Share on other sites

Hello there. Great contribution. It installed really easy. I want to adjust the box so that it doesn't sit within the box. How do I go about doing that? I just want to get rid of the title bar and border.

 

Here is the example: www.dottipotts.com/store

 

Thanks so much for your help.

 

Cheers,

 

David

Link to comment
Share on other sites

akasharkbow,

 

To get rid of the title bar, just comment out these lines of code inside browse_categories.php under your /catalog/includes/modules:

    $content_box_contents = array();
   $content_box_contents[] = array('align' => 'left',
                                   'text'  => $browse_category_heading);

   new contentBoxHeading($content_box_contents, true, true);

 

The box border is controlled through standard osCommerce (tep) functions, that handle all the box displaying issues. The link that you post shows a "common" box model, with title heading and box border. I'm not sure about what you mean, when you wrote

I want to adjust the box so that it doesn't sit within the box.

 

How can I be of more assistance?

Link to comment
Share on other sites

belray,

 

That's a great question. Never thought about it.

 

When I coded Browse by Categories, based on Main Categories, I was aiming at fully replacing the Categories InfoBox, and I'm very used to using the breadcrum trail.

I imagine that many visitors have no clue about the breadcrum trail and its functionality, therefor they use their Browser back button.

 

In the online shops I've been working, I have a rather different Product Info page, with links to either other products of the same category or other products of the same manufacturer. I totally removed the former InfoBoxes for Manufacturers, Categories and Reviews. I don't know if I'm allowed to do this in the forum, but visit my doCommerce Demo Site, with content only in portuguese, and go to a product's page info and see what I mean.

 

So, to finally answer your question, from "my product info pages" the visitor can easily backtrack to the product's category or use the breadcrum trail. But indeed, there's no way to backtrack from the product listing of a category to the parent category, that would be practical to add. It's not in the scope of this contribution, nevertheless it should be added to product listing pages.

 

Since the system knows the category path (cPath=1_5, for instance) and there's a function to get the parent category, it's just a matter of coding some few lines that get the category parent ID, build the cPath to it and call the main page (index.php - MS2 - or default.php - MS1). This code can get you started:

    //DWD Comment: Select parent category of current level.
   $parent_query = "select c.categories_id, cd.categories_name, c.parent_id
                      from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
                     where c.parent_id = cd.categories_id
                       and cd.language_id ='" . $languages_id . "'
                       and c.categories_id = '" . $browse_category_id . "'";
   $arr_parent_category_query = tep_db_query($parent_query);
   $parent_category = tep_db_fetch_array($arr_parent_category_query);

   if ($parent_category['parent_id'] > 0) {
     //DWD Fix -> Change: Browse to parent category link from 3rd level categories to 2nd level category.
     //DWD Comment: azer Bug Request Link -> http://www.oscommerce.com/forums/index.php?showtopic=65657&view=findpost&p=299469
     $content_box_text_parent = '<a href="' . tep_href_link(FILENAME_DEFAULT . '?cPath=' . $parent_category['parent_id'], '', 'NONSSL') . '">' . TEXT_BROWSE_PARENT_CATEGORY . $parent_category['categories_name'] . '</a>';
     //DWD Fix End.
   } else if ($browse_category_id > 0) {
     $content_box_text_parent = '<a href="' . tep_href_link(FILENAME_DEFAULT, '', 'NONSSL') . '">' . TEXT_BROWSE_TOP_CATEGORY . '</a>';
   } else {
     // Top Category Level is 0, don't print back text.
   }

Does anyone else have a better suggestion?

 

I'll code the necessary lines if there's a demand for this feature.

Link to comment
Share on other sites

dasoccerbomb,

 

Another great feature. I never really liked the former Main Categories layout for sub-category links beneath the category icon. But I never had any ideas on how to improve it.

 

With CSS, please correct me if I'm assuming too much, an element can be given the display property of block or inline. Those sub-category links should use a style that is either set to display: inline; (as it is currently) or set to display: block; (as in the site example you provided). Then it's just a matter of controlling the sub-category link position, which is already done: either to the right of the category icon or below it.

 

But for now, a simple hack does the trick. Replace this code:

            //DWD Comment: Separate the current sub-category link from the next one.
           //DWD Comment: Separator depends on the sub-category mode.
           if ($arr_sub_category_mode[0] == 'right') {
             $sub_category_links .= '<br>';
           } else {
             $sub_category_links .= ' ';
           } // Inner If: Build Sub Category Links when Position is RIGHT.

with this one:

            //DWD Comment: Separate the current sub-category link from the next one.
           //DWD Comment: Separator depends on the sub-category mode.
           $sub_category_links .= '<br>';

Hope this helps you out. I never done it because several online shops will have many sub-categories for each category, and I don't like the layout. But that's my opinion and for other sites this layout can also be a "killer". Great tip.

Link to comment
Share on other sites

I'm starting here a list of features to be added to the next release of Browse by Categories v2.6. I ask all users and other people interested in this subject to post your own ideas and features that you want/need to be added.

 

Thanks to dasoccerbomb and to belray, this is the initial list of features:

  • Parent Category Link in Product Listing - Aims to present a more practical navigation to visitors, by providing a link to the parent category of the curretn category product listing.
  • Apply CSS display:inline or display:block to Sub-Category Links - Aims to allow better control over the way the sub-category links are displayed. At present, when positioned below the category icon (image/text), the sub-category links follow one another, instead of occupying a new line.

By using CSS, with display:block and width:100%, the online shop webmaster has an easier control over the displaying of the sub-category links, which is currently very basic. AFAIK, both Mozilla and IE handle well display:block although IE requires the additional width:100%.

 

Looking forward to hear from you all.

Link to comment
Share on other sites

Hello there. I am modifying the index page so that it pulls the sub categories rather then the main category.

 

You can see a demo here: http://www.dottipotts.com/store/

 

I only have two main categories with everything nested under it. That is why I want to pull the sub categories. I got it going. Right now it has the sub categories images listed below each other. I would rather have them sitting side by side in a table set up. I would love it if I could have it in a table with three rows.

 

Eg.

 

Category One

Image 1 | Image 2 | Image 3

Image 4 | Image 5 | Image 6

Image 7 | Image 8 | Image 9

 

Category Two

Image 1 | Image 2 | Image 3

Image 4 | Image 5 | Image 6

Image 7 | Image 8 | Image 9

 

Any help that you can give would be greatly appreciated.

 

Cheers,

 

David

Link to comment
Share on other sites

akasharkbow,

 

That's an entire new layout. Lemme try to help you out kickstarting it, unless you have the time to wait for a new release, after I finish compiling a list of features-wish for Browse by Categories v2.6.

 

Note: I'm not sure that you can fit 3 images on a row, with your sub-category images dimensions. They're a bit too wide for a 1024x768 resolution, if you want to have 3 per row, no?

 

First of all, change this

            $sub_category_links .= BRWCAT_SUBCAT_BULLET .
                                  ' <a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new_sub, 'NONSSL') . '">' .
                                  $sub_categories['categories_name'] . '</a>';

with this

            $sub_category_links .= BRWCAT_SUBCAT_BULLET .
                                  ' <a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new_sub, 'NONSSL') . '">' .
                                  $sub_categories['categories_image'] . '</a>';

You may prefer to remove the BRWCAT_SUBCAT_BULLET. You should set the layout to be BRWCAT_ICON_MODE as 'text', BRWCAT_SUBCAT_MODE as 'bottom' and BRWCAT_ICONS_PER_ROW equal to '1'. This will cause all sub-category icons to appear side by side, which may disrupt your osCommerce appearance with horizontal scroll. To fix this, you need to a use a counter very much in the same way I use BRWCAT_ICONS_PER_ROW, to control how many sub-category icons to display per row, before you add a '<br />'. This doesn't use $content_box_contents[$row][$col], but should work for now.

 

My best try at this moment is to replace this code

            //DWD Comment: Separate the current sub-category link from the next one.
           //DWD Comment: Separator depends on the sub-category mode.
           if ($arr_sub_category_mode[0] == 'right') {
             $sub_category_links .= '<br>';
           } else {
             $sub_category_links .= ' ';
           } // Inner If: Build Sub Category Links when Position is RIGHT.

with this

            //DWD Comment: Separate the current sub-category link from the next one.
           //DWD Comment: Separator depends on the sub-category mode.            
           if ($arr_sub_category_mode[0] == 'right') {
             $sub_category_links .= '<br>';
           } else {
             if ($sub_icons_per_row < 3) {
               $sub_category_links .= ' ';
               $sub_icons_per_row = 1;
             } else {
               $sub_category_links .= '<br>';
               $sub_icons_per_row++;                
             }
           } // Inner If: Build Sub Category Links when Position is RIGHT.

Remember, the value 3 here should be set to the value of sub-category icons to display per each row that you want. (It's hardcoded, to avoid messing around with the database. You can also set a value in configure.php, if you prefer).

To make this work, just replace the code

        if (tep_db_num_rows($arr_sub_categories_query) > 0) {
         while ($sub_categories = tep_db_fetch_array($arr_sub_categories_query)) {

with this

        if (tep_db_num_rows($arr_sub_categories_query) > 0) {
         $sub_icons_per_row = 1;
         while ($sub_categories = tep_db_fetch_array($arr_sub_categories_query)) {

to reset the value of the counter.

 

Try it out and report back, please.

Link to comment
Share on other sites

Features Request for Browse by Categories v2.6.

  • Parent Category Link in Product Listing - Aims to present a more practical navigation to visitors, by providing a link to the parent category of the current category product listing. Kudos: belray.
  • Apply CSS display:inline or display:block to Sub-Category Links - Aims to allow better control over the way the sub-category links are displayed. At present, when positioned below the category icon (image/text), the sub-category links follow one another, instead of occupying a new line. Kudos: dasoccerbomb.
  • New Layout - Set BRWCAT_ICON_MODE = 'text', BRWCAT_SUBCAT_MODE ='bottom' and BRWCAT_ICONS_PER_ROW = 1. It requires new configuration settings: to control the number of sub-category icons per row and to enable/disable the content box title. Kudos: akasharkbow.

Looking forward to hear from you all.

Link to comment
Share on other sites

This new layout, suggested by akasharkbow, launches a new concept.

 

Instead of Browsing by Categories, it should be named Browsing by Sub-Categories or something. If I understand it correctly, the top-level categories of osCommerce should be set with the description of all sub-categories group. Such as this example:

Top-Level Category Titles: Browse by Price Range, Browse by Age Range, Browse by Theme, ...

Sub-Level category Titles: 100?..200?, 200?..500?, 500?..1000?, 5yrs..10yrs, 10yrs..15yrs, Child, Adult, Male, Female, Cats, Dogs, ...

 

A good-looking layout doesn't have a content box title (could be enabled/disabled, but if enabled must be set with top-level category title) and should enable/disable the content box border. The $content_box_contents[$row][$col] features of osCommerce should be used for the sub-category icons only, in this case.

 

This is indeed a great layout, for online shops that set their products by several different categories. I just think, at this moment, that a good code for this layout should be done through a new contribution, maybe based on Browse by Categories, but under a different name. The code shouldn't be mixed, because the module is already too big to be easily maintained. The new module should be switched through a configuration setting between Browse by Categories and Browse by Sub-Categories Groups.

 

Any comments?

Link to comment
Share on other sites

Interesting topic. What I decided to do origionally was to copy the file "browse_categories.php" and renamed it "browse_categories_index.php". I then adjusted the code so that the index page would only pull from the new file.

 

Though probably not the mose efficient, it allowed me to play away and mess up the index page while the rest of the site still stayed excatally right.

 

I will try your new code and let you know. how it turned out.

 

Cheers,

 

David

Link to comment
Share on other sites

I added in the code but I couldn't get it to work. I am not sure if something is canceling something else out so I posted my code below.

 

I thought about your suggestion about having images three across. You are right, that wouldn't work so two across is perfect.

 

Again, thanks for your help.

 

David

 

/*
*tab-width=2
*indent=2
*width=132
*/
?>

<!-- browse_categories !-->
<?php
 require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_BROWSE_CATEGORIES);

 //DWD Comment: Select Heading Text for Content Box based on current category.
 if ( (!isset($browse_category_id)) || ($browse_category_id == '0') ) {
   $browse_category_id = 0;
   $browse_category_heading = BOX_HEADING_BROWSE_TOP_CATEGORIES;
 } else {
   $browse_category_heading = BOX_HEADING_BROWSE_SUB_CATEGORIES;
 } // Checks to see if current category level is top or sub.

 //DWD Comment: Select all categories of current level.
 $categories_query = "select c.categories_id, cd.categories_name, c.categories_image
                        from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
                       where c.categories_id = cd.categories_id
                         and cd.language_id ='" . $languages_id . "'
                         and c.parent_id = '" . $browse_category_id . "'
                       order by c.sort_order, cd.categories_name";
 $arr_current_categories_query = tep_db_query($categories_query);

 //DWD Comment: Only show content box if there are categories at this level.
 if ((tep_db_num_rows($arr_current_categories_query) > 0) and (BRWCAT_ICON_MODE != 'off')) {

   //DWD Comment: Select parent category of current level.
   $parent_query = "select c.categories_id, cd.categories_name, c.parent_id
                      from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
                     where c.parent_id = cd.categories_id
                       and cd.language_id ='" . $languages_id . "'
                       and c.categories_id = '" . $browse_category_id . "'";
   $arr_parent_category_query = tep_db_query($parent_query);
   $parent_category = tep_db_fetch_array($arr_parent_category_query);

   if ($parent_category['parent_id'] > 0) {
     //DWD Fix -> Change: Browse to parent category link from 3rd level categories to 2nd level category.
     //DWD Comment: azer Bug Request Link -> http://www.oscommerce.com/forums/index.php?showtopic=65657&view=findpost&p=299469
     $content_box_text_parent = '<a href="' . tep_href_link(FILENAME_DEFAULT . '?cPath=' . $parent_category['parent_id'], 

'', 'NONSSL') . '">' . TEXT_BROWSE_PARENT_CATEGORY . $parent_category['categories_name'] . '</a>';
     //DWD Fix End.
   } else if ($browse_category_id > 0) {
     $content_box_text_parent = '<a href="' . tep_href_link(FILENAME_DEFAULT, '', 'NONSSL') . '">' . 

TEXT_BROWSE_TOP_CATEGORY . '</a>';
   } else {
     // Top Category Level is 0, don't print back text.
   }

   $content_box_contents = array();
   $content_box_contents[] = array('align' => 'left',
                                   'text'  => $browse_category_heading);

   new contentBoxHeading($content_box_contents, true, true);

   $content_box_contents = array();
   $content_box_contents[][] = array('align'  => 'left',
                                     'params' => 'class="smallText" valign="top" colspan=2"',
                                     'text'   => $content_box_text_parent);

   $row = 1;
   $col = 0;
   while ($current_categories = tep_db_fetch_array($arr_current_categories_query)) {
     $cPath_cur = tep_get_path($current_categories['categories_id']);

     //DWD Comment: Apply Category Name Case setting to current category name.
     if (BRWCAT_NAME_CASE == 'same') {
       $current_category_name = $current_categories['categories_name'];
     } else {
       if (BRWCAT_NAME_CASE == 'upper') {
         $current_category_name = strtoupper($current_categories['categories_name']);
       } else if (BRWCAT_NAME_CASE == 'lower') {
         $current_category_name = strtolower($current_categories['categories_name']);
       } else if (BRWCAT_NAME_CASE == 'title') {
         $current_category_name = ucwords($current_categories['categories_name']);
       } else {
         //DWD Comment: Unknown Category Name Case.
       }
     }

     //DWD Comment: Select all Sub-Categories of Top-Category (Parent ID equal to Category ID).
     if (BRWCAT_SUBCAT_MODE != 'off') {
       //DWD Comment: Sort rows by Sort Order and then Name.
       $sub_query = "select c.categories_id, cd.categories_name, c.categories_image
                       from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
                      where c.categories_id = cd.categories_id
                        and cd.language_id='" . $languages_id . "'
                        and c.parent_id ='" . $current_categories['categories_id'] . "'
                      order by c.sort_order, cd.categories_name";
       $arr_sub_categories_query = tep_db_query($sub_query);

       //DWD Comment: Split Sub-Category Mode in bottom or right/valign.
       $arr_sub_category_mode = explode(' ', BRWCAT_SUBCAT_MODE);

       //DWD Comment: Build Sub Category Links.
       $sub_category_links = '';
      if (tep_db_num_rows($arr_sub_categories_query) > 0) {
        $sub_icons_per_row = 1;
        while ($sub_categories = tep_db_fetch_array($arr_sub_categories_query)) {
           $cPath_new_sub = $cPath_cur . '_' . $sub_categories['categories_id'];
           //DWD Fix -> Change: Use Bullet Setting from Configuration Table.
           //DWD Comment: azer Feature Request Link -> 

http://www.oscommerce.com/forums/index.php?showtopic=65657&view=findpost&p=299576
           $sub_category_links .= ' <a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new_sub, 'NONSSL') . '">' .
                                  tep_image(DIR_WS_IMAGES . $sub_categories['categories_image'], $sub_category_name, 

SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) . '</a><BR><a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new_sub, 

'NONSSL') . '">' .
                                  $sub_categories['categories_name'] . '</A>';
           //DWD Fix End.

           //DWD Comment: Spaceboy Feature Request Link -> 

http://www.oscommerce.com/forums/index.php?showtopic=65657&view=findpost&p=298901
           //DWD Comment: Feature Request Link -> 

http://www.oscommerce.com/forums/index.php?showtopic=65657&view=findpost&p=299903
           if (BRWCAT_SUBCAT_COUNTS != '') {
             $products_in_category = tep_count_products_in_category($sub_categories['categories_id']);
             if ($products_in_category > 0) {
               $sub_category_links .= sprintf(' ' . BRWCAT_SUBCAT_COUNTS, $products_in_category);
             }
           }
           //DWD Fix End.

          //DWD Comment: Separate the current sub-category link from the next one.
          //DWD Comment: Separator depends on the sub-category mode.            
          if ($arr_sub_category_mode[0] == 'right') {
            $sub_category_links .= '<br>';
          } else {
            if ($sub_icons_per_row < 3) {
              $sub_category_links .= ' ';
              $sub_icons_per_row = 1;
            } else {
              $sub_category_links .= '<br>';
              $sub_icons_per_row++;                
            }
          } // Inner If: Build Sub Category Links when Position is RIGHT.
         } // While Loop: Fetch all Query Rows. Each row is a Sub Category of current level Category.
       } // Middle If: Build Sub Category Links if they exist.
     } // Outer If: Build Sub Category Links if enabled by Configuration Settings.

     if ($arr_sub_category_mode[0] == 'right') {
       $table_cell_width = (100 / 1 / 2) . '%';
     } else {
       $table_cell_width = (100 / 1) . '%';
     }

     //DWD Comment: BRWCAT_ICON_MODE is set on Control Panel: Configuration->My Store.
     //DWD Comment: If Mode is set as image only then the category name will be displayed on top of sub-category links.
     //DWD Comment: azer Feature Request Link -> 

http://www.oscommerce.com/forums/index.php?showtopic=65657&view=findpost&p=299469
     //DWD Comment: Feature Request Link -> http://www.oscommerce.com/forums/index.php?showtopic=65657&view=findpost&p=299903
     if (BRWCAT_ICON_MODE == 'text') {
       $content_box_contents[$row][$col] = array('align'  => 'center',
                                                 'params' => 'class="smallText" valign="top" width="' . $table_cell_width . 

'"',
                                                 'text'   => '<a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_cur, 

'NONSSL') . '"><b>' .
                                                             $current_category_name . '</b></a>');
     } else if (BRWCAT_ICON_MODE == 'image only') {
       $content_box_contents[$row][$col] = array('align'  => 'center',
                                                 'params' => 'class="smallText" valign="top" width="' . $table_cell_width . 

'"',
                                                 'text'   => '<a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_cur, 

'NONSSL') . '">' .
                                                             tep_image(DIR_WS_IMAGES . 

$current_categories['categories_image'],
                                                                       $current_category_name,
                                                                       SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) .
                                                             '</a>');
       $sub_category_links = '<a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_cur, 'NONSSL') . '"><b>' .
                             $current_category_name . '</b></a><br>' . $sub_category_links;
     } else if (BRWCAT_ICON_MODE == 'image with caption') {
       $content_box_contents[$row][$col] = array('align'  => 'center',
                                                 'params' => 'class="smallText" valign="top" width="' . $table_cell_width . 

'"',
                                                 'text'   => '<a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_cur, 

'NONSSL') . '">' .
                                                             tep_image(DIR_WS_IMAGES . $sub_categories['categories_image'],
                                                                       $current_category_name,
                                                                       SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) .
                                                             '</a><br><a href="' . tep_href_link(FILENAME_DEFAULT, 

$cPath_cur, 'NONSSL') . '"><b>' .
                                                             $current_category_name . '</b></a>');
     } else {
       // Unknown Browse by Categories Content Box Type.
     } // Checks Type of Content Box for Browse by Categories.

     if ($arr_sub_category_mode[0] == 'right') {
       $content_box_contents[$row][$col + 1] = array('align'  => 'left',
                                                     'params' => 'class="smallText" valign="' . $arr_sub_category_mode[1] . 

'" width="' . $table_cell_width . '"',
                                                     //DWD Fix -> Change: Show blank table cell when category has no 

sub-categories.
                                                     //DWD Comment: azer Bug Request Link -> 

http://www.oscommerce.com/forums/index.php?showtopic=65657&view=findpost&p=299469
                                                     'text'   => ($sub_category_links == '' && BRWCAT_SUBCAT_MODE != 'off') 

? ' ' : $sub_category_links);
                                                     //DWD Fix End.
       $col = $col + 2;
       if ($col >= BRWCAT_ICONS_PER_ROW * 2) {
         $col = 0;
         $row++;
       }
     } else {
       $content_box_contents[$row + 1][$col] = array('align'  => 'left',
                                                     'params' => 'class="smallText" valign="top" width="' . 

$table_cell_width . '"',
                                                     //DWD Fix -> Change: Show blank table cell when category has no 

sub-categories.
                                                     //DWD Comment: azer Bug Request Link -> 

http://www.oscommerce.com/forums/index.php?showtopic=65657&view=findpost&p=299469
                                                     'text'   => ($sub_category_links == '' && BRWCAT_SUBCAT_MODE != 'off') 

? ' ' : $sub_category_links);
                                                     //DWD Fix End.
       $col++;
       if ($col >= BRWCAT_ICONS_PER_ROW) {
         $col = 0;
         $row = $row + 2;
       }
     } // Inner If: Set Content Box contents based on Sub Categories Position
   } // While Loop: Grab all current level Categories.

   new contentBox($content_box_contents);
 } // Check if there are categories at this level.
?>
<!-- browse_categories_eof !-->

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.

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...