[小 大] 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. hdu_1728_逃离迷宫(bfs)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1728 题意:走迷宫,找最小的拐角 题解:对BFS有了新的理解,DFS+剪枝应该也能过,用BFS就要以拐 ...

  2. servlet第2讲(上集)----创建servlet实例(实现servlet接口)

  3. Go-file

    两个包具有文件操作的相关方法,一个是os,一个是syscall,其中os中的相关方法是对syscall相关方法的封装,推荐使用os中的相关方法.文件的打开文件的第一步操作实际上是创建,但是由于文件的打 ...

  4. HAProxy与varnish

    Even if HAProxy can do TCP proxying, it is often used in front of web application, exactly where we ...

  5. Myeclipse8.6安装freemarker插件

    1. 打开http://sourceforge.net/projects/freemarker-ide/files/ 下载最新版本,目前本人下载时最新版本是:freemarker-ide-0.9.14 ...

  6. 运维命令rsync

    如果你是一位运维工程师,你很可能会面对几十台.几百台甚至上千台服务器,除了批量操作外,环境同步.数据同步也是必不可少的技能. 说到“同步”,不得不提的利器就是rsync,今天就来说说我从这个工具中看到 ...

  7. 转: Ant 脚本的结构化设计

    引言 Ant 脚本是由 Apache 提供的一种基于 Java 的构建工具,为 Java 开发人员所熟悉.Java 开发人员使用 Ant 脚本可以很方便地完成 Java 开发过程中常见的如拷贝文件.创 ...

  8. 字符函数库 cctype

    <cctype> (ctype.h) Character handling functions This header declares a set of functions to cla ...

  9. 虚拟机centos分区

    在计算机上安装 Linux 系统,对硬盘进行分区是一个非常重要的步骤,下面介绍几个分区方案. 方案 1 / :建议大小在 5GB 以上. swap :即交换分区,建议大小是物理内存的 1~2 倍. 方 ...

  10. java socket解析和发送二进制报文工具(附java和C++转化问题)

    解析: 首先是读取字节: /** * 读取输入流中指定字节的长度 * <p/> * 输入流 * * @param length 指定长度 * @return 指定长度的字节数组 */ pu ...