[小 大] 2013-09-17 00:20 来源: 未知 作者:wtozz_admin 我要投稿
zencart侧边导航点击一级目录展开二级目录

zen cart Categories默认的是只显示一级目录,当点开一级后才能展开二级目录等,若要让它把一级和二级并列展开,则要更改些东西。

includes\classes\category_tree.php替换这下面的 代码即可

<?php
/**
 * category_tree Class.
 *
 * @package classes
 * @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: category_tree.php 3041 2006-02-15 21:56:45Z wilt $
 */
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}
/**
 * category_tree Class.
 * This class is used to generate the category tree used for the categories sidebox
 *
 * @package classes
 */
class category_tree extends base {

function zen_category_tree($product_type = "all") {
    global $db, $cPath;
   if($cPath != '') global $cPath_array;
    if ($product_type != 'all') {
      $sql = "select type_master_type from " . TABLE_PRODUCT_TYPES . "
                where type_master_type = " . $product_type . "";
      $master_type_result = $db->Execute($sql);
      $master_type = $master_type_result->fields['type_master_type'];
    }
    $this->tree = array();
    if ($product_type == 'all') {
      $categories_query = "select c.categories_id, cd.categories_name, c.parent_id, c.categories_image
                             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)$_SESSION['languages_id'] . "'
                             and c.categories_status= 1
                             order by sort_order, cd.categories_name";
    } else {
      $categories_query = "select ptc.category_id as categories_id, cd.categories_name, c.parent_id, c.categories_image
                             from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd, " . TABLE_PRODUCT_TYPES_TO_CATEGORY . " ptc
                             where c.parent_id = 0
                             and ptc.category_id = cd.categories_id
                             and ptc.product_type_id = " . $master_type . "
                             and c.categories_id = ptc.category_id
                             and cd.language_id=" . (int)$_SESSION['languages_id'] ."
                             and c.categories_status= 1
                             order by sort_order, cd.categories_name";
    }
     $categories = $db->Execute($categories_query, '', true, 150);
    while (!$categories->EOF)  {
    if($cPath == '') $cPath_array[$i++]=$categories->fields['categories_id'];
      $this->tree[$categories->fields['categories_id']] =
     array(  'name' => $categories->fields['categories_name'],
           'parent' => $categories->fields['parent_id'],
           'level' => 0,
           'path' => $categories->fields['categories_id'],
           'image' => $categories->fields['categories_image'],
           'next_id' => false);

if (isset($parent_id)) {
        $this->tree[$parent_id]['next_id'] = $categories->fields['categories_id'];
      }

$parent_id = $categories->fields['categories_id'];

if (!isset($first_element)) {
        $first_element = $categories->fields['categories_id'];
      }
      $categories->MoveNext();
    }
    if (1) {
      $new_path = '';
      reset($cPath_array);
      while (list($key, $value) = each($cPath_array)) {
      //$new_path = '';
        unset($parent_id);
        unset($first_id);
        if ($product_type == 'all') {
          $categories_query = "select c.categories_id, cd.categories_name, c.parent_id, c.categories_image
                               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)$_SESSION['languages_id'] . "
                               and c.categories_status= 1
                               order by sort_order, cd.categories_name";
        } else {
          /*
          $categories_query = "select ptc.category_id as categories, cd.categories_name, c.parent_id, c.categories_image
          from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd, " . TABLE_PRODUCT_TYPES_TO_CATEGORY . " ptc
          where c.parent_id = '" . (int)$value . "'
          and ptc.category_id = cd.categories_id
          and ptc.product_type_id = '" . $master_type . "'
          and cd.language_id='" . (int)$_SESSION['languages_id'] . "'
          and c.categories_status= '1'
          order by sort_order, cd.categories_name";
          */
          $categories_query = "select ptc.category_id as categories_id, cd.categories_name, c.parent_id, c.categories_image
                             from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd, " . TABLE_PRODUCT_TYPES_TO_CATEGORY . " ptc
                             where c.parent_id = " . (int)$value . "
                             and ptc.category_id = cd.categories_id
                             and ptc.product_type_id = " . $master_type . "
                             and c.categories_id = ptc.category_id
                             and cd.language_id=" . (int)$_SESSION['languages_id'] ."
                             and c.categories_status= 1
                             order by sort_order, cd.categories_name";

}

$rows = $db->Execute($categories_query);
        if ($rows->RecordCount()>0) {
          $new_path .= $value;
          while (!$rows->EOF) {
            $this->tree[$rows->fields['categories_id']] = array('name' => $rows->fields['categories_name'],
            'parent' => $rows->fields['parent_id'],
            'level' => $key+1,
            'path' => $new_path . '_' . $rows->fields['categories_id'],
            'image' => $categories->fields['categories_image'],
            'next_id' => false);

if (isset($parent_id)) {
              $this->tree[$parent_id]['next_id'] = $rows->fields['categories_id'];
            }

$parent_id = $rows->fields['categories_id'];
            if (!isset($first_id)) {
              $first_id = $rows->fields['categories_id'];
            }

$last_id = $rows->fields['categories_id'];
            $rows->MoveNext();
          }
          $this->tree[$last_id]['next_id'] = $this->tree[$value]['next_id'];
          $this->tree[$value]['next_id'] = $first_id;
          $new_path .= '_';
        } else {
          break;
        }
      }
    }
    $row = 0;
    return $this->zen_show_category($first_element, $row);
  }

function zen_show_category($counter,$ii) {
    global $cPath_array;

$this->categories_string = "";

for ($i=0; $i<$this->tree[$counter]['level']; $i++) {
      if ($this->tree[$counter]['parent'] != 0) {
       $this->categories_string="";  //一二级目录排列不一致时,清空循环加载的空格
        $this->categories_string .= CATEGORIES_SUBCATEGORIES_INDENT;
      }
    }

if ($this->tree[$counter]['parent'] == 0) {
      $cPath_new = 'cPath=' . $counter;
      $this->box_categories_array[$ii]['top'] = 'true';
    } else {
      $this->box_categories_array[$ii]['top'] = 'false';
      $cPath_new = 'cPath=' . $this->tree[$counter]['path'];
      $this->categories_string .= CATEGORIES_SEPARATOR_SUBS;
    }
    $this->box_categories_array[$ii]['path'] = $cPath_new;

if (isset($cPath_array) && in_array($counter, $cPath_array)) {
      $this->box_categories_array[$ii]['current'] = true;
    } else {
      $this->box_categories_array[$ii]['current'] = false;
    }

// display category name
    $this->box_categories_array[$ii]['name'] = $this->categories_string . $this->tree[$counter]['name'];

// make category image available in case needed
    $this->box_categories_array[$ii]['image'] = $this->tree[$counter]['image'];

if (zen_has_category_subcategories($counter)) {
      $this->box_categories_array[$ii]['has_sub_cat'] = true;
    } else {
      $this->box_categories_array[$ii]['has_sub_cat'] = false;
    }

if (SHOW_COUNTS == 'true') {
      $products_in_category = zen_count_products_in_category($counter);
      if ($products_in_category > 0) {
        $this->box_categories_array[$ii]['count'] = $products_in_category;
      } else {
        $this->box_categories_array[$ii]['count'] = 0;
      }
    }

if ($this->tree[$counter]['next_id'] != false) {
      $ii++;
      $this->zen_show_category($this->tree[$counter]['next_id'], $ii);
    }
    return $this->box_categories_array;
  }
}
?>

zencart侧边导航点击一级目录展开二级目录的更多相关文章

  1. bootstrap导航条在手机上默认展开二级目录,必须用setTimeout才能实现

    bootstrap导航条在手机上默认展开二级目录,必须用setTimeout才能实现 $(document).ready(function() { $('.dropdown').hover(funct ...

  2. .Net Core小技巧 - Swagger适配虚拟目录及二级目录

    前言 随着前后端分离模式与微服务架构的出现,Web API变得越来越重要及普遍.而后出现的网关技术,使开发者更倾向于使用二级/多级目录来暴露Web API,一是暴露的端口更少,方便管理:二是在网关中可 ...

  3. nginx下如何l在网站目录的二级目录下url重写的方法

    以我新项目为例子,该项目要求用laravel来做,因此我把整个项目丢到一个叫laravel的文件夹里面了,目录就变成c:/nginx/html/laravel了,然后发现只能通过localhost/l ...

  4. ztree 展开一级节点 | ztree只显示到二级目录

    // 默认展开一级节点var nodes = tree.getNodesByParam("level", 0);for (var i = 0; i < nodes.lengt ...

  5. Hibernate中一级缓存和二级缓存使用详解

    一.一级缓存二级缓存的概念解释 (1)一级缓存就是Session级别的缓存,一个Session做了一个查询操作,它会把这个操作的结果放在一级缓存中,如果短时间内这个 session(一定要同一个ses ...

  6. 有二级目录的IIS配置

    当项目配置文件中配置了二级目录时,如下: <!--二级目录地址--> <add key="SecondCatalog" value="/hotel&qu ...

  7. mybatis 详解(九)------ 一级缓存、二级缓存

    上一章节,我们讲解了通过mybatis的懒加载来提高查询效率,那么除了懒加载,还有什么方法能提高查询效率呢?这就是我们本章讲的缓存. mybatis 为我们提供了一级缓存和二级缓存,可以通过下图来理解 ...

  8. Mybatis第八篇【一级缓存、二级缓存、与ehcache整合】

    Mybatis缓存 缓存的意义 将用户经常查询的数据放在缓存(内存)中,用户去查询数据就不用从磁盘上(关系型数据库数据文件)查询,从缓存中查询,从而提高查询效率,解决了高并发系统的性能问题. myba ...

  9. Hibernate一级缓存和二级缓存详解

    (1)一级缓存 是Session级别的缓存,一个Session做了一个查询操作,它会把这个操作的结果放在一级缓存中,如果短时间内这个session(一定要同一个session)又做了同一个操作,那么h ...

随机推荐

  1. openwrt 中make的使用

    make 命令简单说明 make V=99 V=99表示输出详细的debug信息 make world 表示编译所有 make j=2 V=99 如是多核CPU,加j=2 选项理论上能加快编译速度 m ...

  2. myeclipse复制项目

    一.myEclipse 复制后修改名称,访问不到项目 这是因为,你只是改了项目的名称,而没有改 下面是解决方法: 方法 1.右击你的项目,选择"properties",在" ...

  3. MySQL外键的作用和创建

    MySQL外键的作用: 保持数据一致性,完整性,主要目的是控制存储在外键表中的数据.使两张表形成关联,外键只能引用外表中列的值! 我们来建两个表 CREATE TABLE `example1` ( ` ...

  4. Inno Setup入门(二十)——Inno Setup类参考(6)

    存储框 存储框也是典型的窗口可视化组件,同编辑框类似,可以输入.显示文本,但是和编辑框不同的是,编辑框只能编辑.显示单行文本,而存储框则可以对多行文本进行操作.存储框的类定义如下:< xmlna ...

  5. php发送get、post请求获取内容的几种方法

    方法1: 用file_get_contents 以get方式获取内容 <?php $url='http://www.domain.com/'; $html = file_get_contents ...

  6. PHP的curl实现get,post 和 cookie

    类似于dreamhost这类主机服务商,是显示fopen的使用 的.使用php的curl可以实现支持FTP.FTPS.HTTP HTPPS SCP SFTP TFTP TELNET DICT FILE ...

  7. Android OpenGL ES(十三)通用的矩阵变换指令 .

    Android OpenGL ES 对于不同坐标系下坐标变换,大都使用矩阵运算的方法来定义和实现的.这里介绍对应指定的坐标系(比如viewmodel, projection或是viewport) An ...

  8. json-c代码示例

    #include <stdio.h> #include <string.h> #include <json.h> int main(int argc,char ** ...

  9. [转]java构造方法的访问修饰符

    http://my.oschina.net/u/1464678/blog/210359 1.       类(class) 可见性修饰符: public—在所有类中可见,在其他包中可以用import导 ...

  10. 初探JavaScript魅力(四)

    选项卡 <title>无标题文档</title> <style> #div1 .active{background:#FF0;} #div1 div{width:2 ...