Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

A categories box which only shows the subcategories of selected category?


Recommended Posts

I hope someone can point me in the right direction for this.

 

Basically, because i'm seting up my main categories as follows:

 

Mens, Ladies, Kids, accessories etc

 

I have made a custom navbar module where i've put these categories into a navbar in the header.

 

I've removed the normal categories box from the columns.


What i want to do is basically have a dynamic categories box which will list the subcategories of the currently selected top level category.

 

So for example, ive selected "Mens".

 

in the categories box will be all of the subcategories ONLY for the men's category.

 

And the same will apply whenever you select a different top level category from my navbar.

 

Would I need to create a new class to achieve this?

 

 

thanks

 

Link to comment
Share on other sites

ok, i managed to find an older version of what im trying to do.

 

this is from an old non BS version.

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2010 osCommerce

  Released under the GNU General Public License
*/

  class bm_subcategories {
    var $code = 'bm_subcategories';
    var $group = 'boxes';
    var $title;
    var $description;
    var $sort_order;
    var $enabled = false;
    var $pages;
    
    function bm_subcategories() {
      $this->title = MODULE_BOXES_SUBCATEGORIES_TITLE;
      $this->description = MODULE_BOXES_SUBCATEGORIES_DESCRIPTION;

      if ( defined('MODULE_BOXES_SUBCATEGORIES_STATUS') ) {
        $this->sort_order = MODULE_BOXES_SUBCATEGORIES_SORT_ORDER;
        $this->enabled = (MODULE_BOXES_SUBCATEGORIES_STATUS == 'True');
        $this->pages = MODULE_BOXES_SUBCATEGORIES_DISPLAY_PAGES;
        $this->group = ((MODULE_BOXES_SUBCATEGORIES_CONTENT_PLACEMENT == 'Left Column') ? 'boxes_column_left' : 'boxes_column_right');
      }
    }

    function tep_show_category($counter) {
      global $tree, $categories_string, $cPath_array;

        if ((int)$tree[$counter]['parent'] > 0) {
            for ($i=0; $i<$tree[$counter]['level']; $i++) {
                $categories_string .= "  ";
            }
            $categories_string .= '<a href="';
            $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 .= '<strong>';
            }
            // display category name
            $categories_string .= $tree[$counter]['name'];
            
            if (isset($cPath_array) && in_array($counter, $cPath_array)) {
                $categories_string .= '</strong>';
            }
            
            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) {
        $this->tep_show_category($tree[$counter]['next_id']);
        }

    }

    function getData() {
      global $categories_string, $tree, $languages_id, $cPath, $cPath_array;

      $categories_string = '';
      $tree = array();

      $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_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);

        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)) {
        $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 from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_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);

              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'];
            }
            $tree[$last_id]['next_id'] = $tree[$value]['next_id'];
            $tree[$value]['next_id'] = $first_id;
            $new_path .= '_';
          } else {
            break;
          }
        }
      }

      $this->tep_show_category($first_element);
      
      // category without subcategory hides boxe
      if ( $cPath != 0 && isset($last_id) ) {
      $data = '<div class="ui-widget infoBoxLeftContainer">' .
              ' <div class="ui-widget-content infoBoxContents">' . $categories_string . '</div>' .
              '</div>';
      }else{
      $data ='';
      }

      return $data;
    }

    function execute() {
      global $SID, $oscTemplate;

      if ((USE_CACHE == 'true') && empty($SID)) {
        $output = tep_cache_categories_box();
      } else {
        $output = $this->getData();
      }

      $oscTemplate->addBlock($output, $this->group);
    }

    function isEnabled() {
      return $this->enabled;
    }

    function check() {
      return defined('MODULE_BOXES_SUBCATEGORIES_STATUS');
    }

    function install() {
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Sub Categories Module', 'MODULE_BOXES_SUBCATEGORIES_STATUS', 'True', 'Do you want to add the module to your shop?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Content Placement', 'MODULE_BOXES_SUBCATEGORIES_CONTENT_PLACEMENT', 'Left Column', 'Should the module be loaded in the left or right column?', '6', '1', 'tep_cfg_select_option(array(\'Left Column\', \'Right Column\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_BOXES_SUBCATEGORIES_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Display in pages.', 'MODULE_BOXES_SUBCATEGORIES_DISPLAY_PAGES', 'all', 'select pages where this box should be displayed. ', '6', '0','tep_cfg_select_pages(' , now())");
    }

    function remove() {
      tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

    function keys() {
      return array('MODULE_BOXES_SUBCATEGORIES_STATUS', 'MODULE_BOXES_SUBCATEGORIES_CONTENT_PLACEMENT', 'MODULE_BOXES_SUBCATEGORIES_SORT_ORDER','MODULE_BOXES_SUBCATEGORIES_DISPLAY_PAGES');
    }
  }
?>

im just not sure where to start on editing the category_tree.php file in BS oscommerce.

Link to comment
Share on other sites

Extend your category tree class, don't overwrite it, then modify your bm_categories module...this is how I did mine, you probably just need the getBranch and _buildBranch method and delete the rest. Also, empty out the _construct as that was for my own hack...(node was for defining a cat node for the megamenu bar...status--i don't show off season categories...shortcode--a temp fix to show marketing images in the mega menu...delete everything that's related to them). Hope this point u in the right direction...

 

cat tree class file...

<?php
/**
 * osCommerce Online Merchant
 *
 * @[member='copyright'] Copyright (c) 2014 osCommerce; http://www.oscommerce.com
 *
 * Author: Clustersolutions
 *
 * @[member='licensed2kill'] GNU General Public License; http://www.oscommerce.com/gpllicense.txt
 */

  class category_tree_status_mod extends category_tree {
    protected $shortcode = false;

    public function __construct($parent = false) {
      global $languages_id;

      static $_category_tree_data;

      if ( isset($_category_tree_data) ) {
        $this->_data = $_category_tree_data;
      } else {

        $categories_query = tep_db_query("select c.categories_id, c.parent_id, c.categories_image, c.node, c.shortcode, cd.categories_name from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = cd.categories_id and c.categories_status = 1 and cd.language_id = '" . (int)$languages_id. "' order by c.parent_id, c.sort_order, cd.categories_name");

        while ( $categories = tep_db_fetch_array($categories_query) ) {
          $this->_data[$categories['parent_id']][$categories['categories_id']] = array('name' => $categories['categories_name'],
                                                                                       'image' => $categories['categories_image'],
                                                                                       'node' => $categories['node'],
                                                                                       'shortcode' => $categories['shortcode']);
        }

        $_category_tree_data = $this->_data;
      }
      if ($parent) parent::__construct();
    }


    function getLeaves($category_id, &$array = array()) {
      foreach ($this->_data as $parent => $categories) {
        if ($parent == $category_id) {
          foreach ($categories as $id => $info) {
            if (!$this->getLeaves($id) && !$info['shortcode']) $array[] = $id; //shortcode not a category...
            $this->getLeaves($id, $array);
          }
        }
      }
      return $array;
    }

    function getNodes($category_id, &$array = array()) {
      foreach ($this->_data as $parent => $categories) {
        if ($parent == $category_id) {
          foreach ($categories as $id => $info) {
            if ($info['node']) $array[] = $id;
            $this->getNodes($id, $array);
          }
        }
      }
      return $array;
    }

    protected function _buildBranch($parent_id, $level = 0) {
      global $current_category_id;
      $result = ((($level === 0) && ($this->parent_group_apply_to_root === true)) || ($level > 0)) ? $this->parent_group_start_string : null;

      if ( isset($this->_data[$parent_id]) ) {
        foreach ( $this->_data[$parent_id] as $category_id => $category ) {
          if (!$this->shortcode) {
            if ($category['shortcode']) continue;
          }
          if ( $this->breadcrumb_usage === true ) {
            $category_link = $this->buildBreadcrumb($category_id);
          } else {
            $category_link = $category_id;
          }

          $result .= $this->child_start_string;

          if ( isset($this->_data[$category_id]) ) {
            $result .= $this->parent_start_string;
          }

          if ( $level === 0 ) {
            $result .= $this->root_start_string;
          }

          if ( ($this->follow_cpath === true) && in_array($category_id, $this->cpath_array) ) {
            $link_title = $this->cpath_start_string . $category['name'] . $this->cpath_end_string;
          } else {
            $link_title = $category['name'];
          }
          if ($category['shortcode']) {
            $result .= $link_title . '</a>';
          } else {
            $result .= '<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $category_link) . '"' . ($category_id == $current_category_id ? ' class="active-category"' : '') . '>';
            $result .= str_repeat($this->spacer_string, $this->spacer_multiplier * $level);
            $result .= $link_title . '</a>';
          }

          if ( $level === 0 ) {
            $result .= $this->root_end_string;
          }


          if ( isset($this->_data[$category_id]) ) {
            $result .= $this->parent_end_string;
          }


          if ( isset($this->_data[$category_id]) && (($this->max_level == '0') || ($this->max_level > $level+1)) ) {
            if ( $this->follow_cpath === true ) {
              if ( in_array($category_id, $this->cpath_array) ) {
                $result .= $this->_buildBranch($category_id, $level+1);
              }
            } else {
              $result .= $this->_buildBranch($category_id, $level+1);
            }
          }

          $result .= $this->child_end_string;
        }
      }

      $result .= ((($level === 0) && ($this->parent_group_apply_to_root === true)) || ($level > 0)) ? $this->parent_group_end_string : null;

      return $result;
    }

    function getBranch($category_id) {
      return $this->_buildBranch($category_id);
    }

    function setShortCode($status = false) {
      return $this->shortcode = $status;
    }

  }

?>
                                                                                                  

bm_nav_categories file...focus on the execute method...

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2014 osCommerce

  Author: Clustersolutions

  Released under the GNU General Public License
*/

  class bm_nav_categories {
    var $code = 'bm_nav_categories';
    var $group = 'boxes';
    var $title;
    var $description;
    var $sort_order;
    var $enabled = false;

    function bm_nav_categories() {
      $this->title = MODULE_BOXES_NAV_CATEGORIES_TITLE;
      $this->description = MODULE_BOXES_NAV_CATEGORIES_DESCRIPTION;

      if ( defined('MODULE_BOXES_NAV_CATEGORIES_STATUS') ) {
        $this->sort_order = MODULE_BOXES_NAV_CATEGORIES_SORT_ORDER;
        $this->enabled = (MODULE_BOXES_NAV_CATEGORIES_STATUS == 'True');

        $this->group = ((MODULE_BOXES_NAV_CATEGORIES_CONTENT_PLACEMENT == 'Left Column') ? 'boxes_column_left' : 'boxes_column_right');
      }
    }

    function execute() {
      global $oscTemplate, $cPath_array, $OSCOM_CategoryTree;

      //require(DIR_WS_CLASSES . 'category_tree_status_mod.php');
      //$OSCOM_CategoryTree = new category_tree_status_mod();

      if (!empty($cPath_array)) {
        $OSCOM_CategoryTree->setSpacerString('  ', 0);
        $OSCOM_CategoryTree->setParentGroupString('<ul class="list-unstyled col-sm-12">', '</ul>', true);
        $node = $OSCOM_CategoryTree->getData($cPath_array[0]);
        $category_tree = $OSCOM_CategoryTree->getBranch($cPath_array[0]);

        ob_start();
        include(DIR_WS_MODULES . 'boxes/templates/nav_categories.php');
        $data = ob_get_clean();

        $oscTemplate->addBlock($data, $this->group);
      }
    }

    function isEnabled() {
      return $this->enabled;
    }

    function check() {
      return defined('MODULE_BOXES_NAV_CATEGORIES_STATUS');
    }

    function install() {
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Categories Module', 'MODULE_BOXES_NAV_CATEGORIES_STATUS', 'True', 'Do you want to add the module to your shop?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Content Placement', 'MODULE_BOXES_NAV_CATEGORIES_CONTENT_PLACEMENT', 'Left Column', 'Should the module be loaded in the left or right column?', '6', '1', 'tep_cfg_select_option(array(\'Left Column\', \'Right Column\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_BOXES_NAV_CATEGORIES_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
    }

    function remove() {
      tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

    function keys() {
      return array('MODULE_BOXES_NAV_CATEGORIES_STATUS', 'MODULE_BOXES_NAV_CATEGORIES_CONTENT_PLACEMENT', 'MODULE_BOXES_NAV_CATEGORIES_SORT_ORDER');
    }
  }

?>

Link to comment
Share on other sites

 

Extend your category tree class, don't overwrite it, then modify your bm_categories module...this is how I did mine, you probably just need the getBranch and _buildBranch method and delete the rest. Also, empty out the _construct as that was for my own hack...(node was for defining a cat node for the megamenu bar...status--i don't show off season categories...shortcode--a temp fix to show marketing images in the mega menu...delete everything that's related to them). Hope this point u in the right direction...

 

cat tree class file...

<?php
/**
 * osCommerce Online Merchant
 *
 * @[member='copyright'] Copyright (c) 2014 osCommerce; http://www.oscommerce.com
 *
 * Author: Clustersolutions
 *
 * @[member='licensed2kill'] GNU General Public License; http://www.oscommerce.com/gpllicense.txt
 */

  class category_tree_status_mod extends category_tree {
    protected $shortcode = false;

    public function __construct($parent = false) {
      global $languages_id;

      static $_category_tree_data;

      if ( isset($_category_tree_data) ) {
        $this->_data = $_category_tree_data;
      } else {

        $categories_query = tep_db_query("select c.categories_id, c.parent_id, c.categories_image, c.node, c.shortcode, cd.categories_name from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = cd.categories_id and c.categories_status = 1 and cd.language_id = '" . (int)$languages_id. "' order by c.parent_id, c.sort_order, cd.categories_name");

        while ( $categories = tep_db_fetch_array($categories_query) ) {
          $this->_data[$categories['parent_id']][$categories['categories_id']] = array('name' => $categories['categories_name'],
                                                                                       'image' => $categories['categories_image'],
                                                                                       'node' => $categories['node'],
                                                                                       'shortcode' => $categories['shortcode']);
        }

        $_category_tree_data = $this->_data;
      }
      if ($parent) parent::__construct();
    }


    function getLeaves($category_id, &$array = array()) {
      foreach ($this->_data as $parent => $categories) {
        if ($parent == $category_id) {
          foreach ($categories as $id => $info) {
            if (!$this->getLeaves($id) && !$info['shortcode']) $array[] = $id; //shortcode not a category...
            $this->getLeaves($id, $array);
          }
        }
      }
      return $array;
    }

    function getNodes($category_id, &$array = array()) {
      foreach ($this->_data as $parent => $categories) {
        if ($parent == $category_id) {
          foreach ($categories as $id => $info) {
            if ($info['node']) $array[] = $id;
            $this->getNodes($id, $array);
          }
        }
      }
      return $array;
    }

    protected function _buildBranch($parent_id, $level = 0) {
      global $current_category_id;
      $result = ((($level === 0) && ($this->parent_group_apply_to_root === true)) || ($level > 0)) ? $this->parent_group_start_string : null;

      if ( isset($this->_data[$parent_id]) ) {
        foreach ( $this->_data[$parent_id] as $category_id => $category ) {
          if (!$this->shortcode) {
            if ($category['shortcode']) continue;
          }
          if ( $this->breadcrumb_usage === true ) {
            $category_link = $this->buildBreadcrumb($category_id);
          } else {
            $category_link = $category_id;
          }

          $result .= $this->child_start_string;

          if ( isset($this->_data[$category_id]) ) {
            $result .= $this->parent_start_string;
          }

          if ( $level === 0 ) {
            $result .= $this->root_start_string;
          }

          if ( ($this->follow_cpath === true) && in_array($category_id, $this->cpath_array) ) {
            $link_title = $this->cpath_start_string . $category['name'] . $this->cpath_end_string;
          } else {
            $link_title = $category['name'];
          }
          if ($category['shortcode']) {
            $result .= $link_title . '</a>';
          } else {
            $result .= '<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $category_link) . '"' . ($category_id == $current_category_id ? ' class="active-category"' : '') . '>';
            $result .= str_repeat($this->spacer_string, $this->spacer_multiplier * $level);
            $result .= $link_title . '</a>';
          }

          if ( $level === 0 ) {
            $result .= $this->root_end_string;
          }


          if ( isset($this->_data[$category_id]) ) {
            $result .= $this->parent_end_string;
          }


          if ( isset($this->_data[$category_id]) && (($this->max_level == '0') || ($this->max_level > $level+1)) ) {
            if ( $this->follow_cpath === true ) {
              if ( in_array($category_id, $this->cpath_array) ) {
                $result .= $this->_buildBranch($category_id, $level+1);
              }
            } else {
              $result .= $this->_buildBranch($category_id, $level+1);
            }
          }

          $result .= $this->child_end_string;
        }
      }

      $result .= ((($level === 0) && ($this->parent_group_apply_to_root === true)) || ($level > 0)) ? $this->parent_group_end_string : null;

      return $result;
    }

    function getBranch($category_id) {
      return $this->_buildBranch($category_id);
    }

    function setShortCode($status = false) {
      return $this->shortcode = $status;
    }

  }

?>
                                                                                                  

bm_nav_categories file...focus on the execute method...

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2014 osCommerce

  Author: Clustersolutions

  Released under the GNU General Public License
*/

  class bm_nav_categories {
    var $code = 'bm_nav_categories';
    var $group = 'boxes';
    var $title;
    var $description;
    var $sort_order;
    var $enabled = false;

    function bm_nav_categories() {
      $this->title = MODULE_BOXES_NAV_CATEGORIES_TITLE;
      $this->description = MODULE_BOXES_NAV_CATEGORIES_DESCRIPTION;

      if ( defined('MODULE_BOXES_NAV_CATEGORIES_STATUS') ) {
        $this->sort_order = MODULE_BOXES_NAV_CATEGORIES_SORT_ORDER;
        $this->enabled = (MODULE_BOXES_NAV_CATEGORIES_STATUS == 'True');

        $this->group = ((MODULE_BOXES_NAV_CATEGORIES_CONTENT_PLACEMENT == 'Left Column') ? 'boxes_column_left' : 'boxes_column_right');
      }
    }

    function execute() {
      global $oscTemplate, $cPath_array, $OSCOM_CategoryTree;

      //require(DIR_WS_CLASSES . 'category_tree_status_mod.php');
      //$OSCOM_CategoryTree = new category_tree_status_mod();

      if (!empty($cPath_array)) {
        $OSCOM_CategoryTree->setSpacerString('  ', 0);
        $OSCOM_CategoryTree->setParentGroupString('<ul class="list-unstyled col-sm-12">', '</ul>', true);
        $node = $OSCOM_CategoryTree->getData($cPath_array[0]);
        $category_tree = $OSCOM_CategoryTree->getBranch($cPath_array[0]);

        ob_start();
        include(DIR_WS_MODULES . 'boxes/templates/nav_categories.php');
        $data = ob_get_clean();

        $oscTemplate->addBlock($data, $this->group);
      }
    }

    function isEnabled() {
      return $this->enabled;
    }

    function check() {
      return defined('MODULE_BOXES_NAV_CATEGORIES_STATUS');
    }

    function install() {
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Categories Module', 'MODULE_BOXES_NAV_CATEGORIES_STATUS', 'True', 'Do you want to add the module to your shop?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Content Placement', 'MODULE_BOXES_NAV_CATEGORIES_CONTENT_PLACEMENT', 'Left Column', 'Should the module be loaded in the left or right column?', '6', '1', 'tep_cfg_select_option(array(\'Left Column\', \'Right Column\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_BOXES_NAV_CATEGORIES_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
    }

    function remove() {
      tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

    function keys() {
      return array('MODULE_BOXES_NAV_CATEGORIES_STATUS', 'MODULE_BOXES_NAV_CATEGORIES_CONTENT_PLACEMENT', 'MODULE_BOXES_NAV_CATEGORIES_SORT_ORDER');
    }
  }

?>

Thanks

Link to comment
Share on other sites

  • 1 year later...
  • 3 years later...

Hello, I know this is an old thread, but I'm trying to achieve this kind of thing on the BS version.   Category menu on left, that only shows the sub-categories of the selected category. 

Has anyone been successful in altering the code to show just sub-categories of selected category in BS? 

Link to comment
Share on other sites

Hello Ros @Rosyweb,

In the category box module you can pass a fixed root category to the category class like this (example for root category 1):

      $OSCOM_CategoryTree->setRootCategoryID(1);

or you can pass the actual category id as root category id. So the category box will dynamically show only the subcategories of the actual category:

      $OSCOM_CategoryTree->setRootCategoryID((int)$current_category_id);

in this case you need to add $current_category_id to the globals list of the module:

      global $oscTemplate, $cPath, $current_category_id;

 

Link to comment
Share on other sites

Thank you, that was a really simple way to do it.  

So what I'm trying to bring in now:

left navigation now shows only the current level we're at  - selected using the method you've shown me

 global $oscTemplate, $cPath, $current_category_id;

But in the header for the left menu, I wish it to say Category:   "current category name".    So I need to pull in the current category name there.    So it can't be just getTree, it needs to be the selected category name.  I'll be looking for the variable to put, but if you are able to help or push me in the right direction that will be great.   

Link to comment
Share on other sites

In bm_category.php use:

      $category_titel =  $OSCOM_CategoryTree->getData($current_category_id, 'name');

You just have to add a check if $current_category_id is not empty or zero and use MODULE_BOXES_CATEGORIES_BOX_TITLE for that case.

Link to comment
Share on other sites

So - to feed back.  With help from Raiwa, I've achieved what I wanted.  Static horizontal menu at top appears all the time.  When you click on a category then a vertical sub-menu appears just showing the level in the category you're at.  

I created a new module for this, but you don't have to.  You could just amend bm_categories.php and the template file (tpl_bm_categories.php).

Changed the    function execute()  to:

    function execute() {  
	  global $oscTemplate, $cPath, $current_category_id;

      $OSCOM_CategoryTree = new category_tree();
      $OSCOM_CategoryTree->setCategoryPath($cPath, '<strong>', '</strong>');

  // sets cateogory tree to current level only
  	  $OSCOM_CategoryTree->setRootCategoryID((int)$current_category_id);
	 
      $OSCOM_CategoryTree->setParentGroupString('<ul class="nav nav-pills nav-stacked">', '</ul>', true);
   
  // defined category title - to call in template bm_categories
     $category_title =  $OSCOM_CategoryTree->getData($current_category_id, 'name');
      	 
     $category_tree = $OSCOM_CategoryTree->getTree();	  
      
	  
      ob_start();
      include('includes/modules/boxes/templates/tpl_' . basename(__FILE__));
      $data = ob_get_clean();

      $oscTemplate->addBlock($data, $this->group);
    }

Then I amended the template file - to only show this when a category has been selected. 

 <?php if (!empty($category_title)) {?><div class="panel panel-default bm-nav-categories"><div class="panel-heading"><?php echo MODULE_BOXES_CATEGORIES2_BOX_TITLE; ?> <?php echo $category_title; ?></div> <?php echo $category_tree;?></div><?php 
} else {return null;} ?>

Of course styles etc may be different on others versions.   But it seems to work, so might be helpful to others.    Thanks for your help Raiwa!

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...