Neuigkeiten
  • Die modified eCommerce Shopsoftware ist kostenlos, aber nicht umsonst.
    Spenden
  • Damit wir die modified eCommerce Shopsoftware auch zukünftig kostenlos anbieten können:
    Spenden
  • Thema: Bei Klick auf Kategorie nur Unterkategorien ausklappen, main_content jedoch nicht ändern

    hpzeller

    • Experte
    • Beiträge: 4.129
    • Geschlecht:
    Hallo ams,

    wenn dir so etwas gefällt

    [ Für Gäste sind keine Dateianhänge sichtbar ]

    habe ich hier etwas für modified 2.0 mit Template 'tpl_modified' zusammengestellt .

    Im 'template/tpl_modified/source/boxes/categories.php' alles mit folgendem Code ersetzen

    Code: PHP  [Auswählen]
    <?php
    /* -----------------------------------------------------------------------------------------
       $Id: categories.php 4200 2013-01-10 19:47:11Z Tomcraft1980 $

       modified eCommerce Shopsoftware
       http://www.modified-shop.org

       Copyright (c) 2009 - 2013 [www.modified-shop.org]
       -----------------------------------------------------------------------------------------
       based on:
       (c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
       (c) 2002-2003 osCommerce(categories.php,v 1.23 2002/11/12); www.oscommerce.com
       (c) 2003 nextcommerce (categories.php,v 1.10 2003/08/17); www.nextcommerce.org
       (c) 2006 XT-Commerce

       Released under the GNU General Public License
       -----------------------------------------------------------------------------------------
       Third Party contributions:
       Enable_Disable_Categories 1.3          Autor: Mikel Williams | mikel@ladykatcostumes.com

       Released under the GNU General Public License
       ---------------------------------------------------------------------------------------*/


    // include smarty
    include(DIR_FS_BOXES_INC . 'smarty_default.php');

    // set cache id
    $cache_id = md5($_SESSION['language'].$_SESSION['customers_status']['customers_status'].'-'.$cPath.((SPECIALS_CATEGORIES === true || WHATSNEW_CATEGORIES === true) ? '-'.basename($PHP_SELF) : ''));

    if (!$box_smarty->is_cached(CURRENT_TEMPLATE.'/boxes/box_categories.html', $cache_id) || !$cache) {

      // include needed functions
      require_once (DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/source/inc/xtc_show_category.inc.php');
      require_once (DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/source/inc/close_ul_tags.inc.php');
      require_once (DIR_FS_INC.'xtc_has_category_subcategories.inc.php');
      require_once (DIR_FS_INC.'xtc_count_products_in_category.inc.php');
     
      $foo = array();
      $categories_string = '';
      unset($prev_id);
     
      $categories_query = xtDBquery("SELECT c.categories_id,
                                            cd.categories_name,
                                            c.parent_id
                                       FROM "
    .TABLE_CATEGORIES." c
                                       JOIN "
    .TABLE_CATEGORIES_DESCRIPTION." cd
                                            ON c.categories_id = cd.categories_id
                                               AND cd.language_id='"
    .(int)$_SESSION['languages_id']."'
                                               AND trim(cd.categories_name) != ''
                                      WHERE c.categories_status = '1'
                                            "
    .CATEGORIES_CONDITIONS_C."
                                   ORDER BY c.sort_order, cd.categories_name"
    );
      if (xtc_db_num_rows($categories_query, true) > 0) {
        $sub_categories = array();
        while ($categories = xtc_db_fetch_array($categories_query, true)) {
          if ($categories['parent_id'] == 0) {
            $categories['cat_link'] = xtc_href_link(FILENAME_DEFAULT, xtc_category_link($categories['categories_id'],$categories['categories_name']));
            $foo[$categories['categories_id']] = array (
                'name' => $categories['categories_name'],
                'link' => $categories['cat_link'],
                'parent' => $categories['parent_id'],
                'level' => 0,
                'path' => $categories['categories_id'],
                'next_id' => false
              );

            if (isset($prev_id)) {
              $foo[$prev_id]['next_id'] = $categories['categories_id'];
            }

           $prev_id = $categories['categories_id'];

            if (!isset ($first_element)) {
              $first_element = $categories['categories_id'];
            }
          } else {
            if (!in_array($categories['parent_id'], $sub_categories)) $sub_categories[] = $categories['parent_id'];
          }  
        }

        if (!empty($sub_categories)) {
          $new_path = '';
          $id = $sub_categories;    
          reset($id);
          while (list ($key, $value) = each($id)) {
            unset ($prev_id);
            unset ($first_id);
            $categories_query = xtDBquery("SELECT c.categories_id,
                                                  cd.categories_name,
                                                  c.parent_id
                                             FROM "
    .TABLE_CATEGORIES." c
                                             JOIN "
    .TABLE_CATEGORIES_DESCRIPTION." cd
                                                  ON c.categories_id = cd.categories_id
                                                     AND cd.language_id='"
    .(int)$_SESSION['languages_id']."'
                                                     AND trim(cd.categories_name) != ''
                                            WHERE c.categories_status = '1'
                                              AND c.parent_id = '"
    .$value."'
                                                  "
    .CATEGORIES_CONDITIONS_C."
                                         ORDER BY c.sort_order, cd.categories_name"
    );
                                         
            if (xtc_db_num_rows($categories_query, true) > 0) {
              $new_path .= $value;
              while ($row = xtc_db_fetch_array($categories_query, true)) {
                $row['cat_link'] = xtc_href_link(FILENAME_DEFAULT, xtc_category_link($row['categories_id'], $row['categories_name']));
                $foo[$row['categories_id']] = array (
                    'name' => $row['categories_name'],
                    'link' => $row['cat_link'],
                    'parent' => $row['parent_id'],
                    'level' => $key +1,
                    'path' => $new_path.'_'.$row['categories_id'],
                    'next_id' => false
                  );
                $foo[$row['categories_id']]['level'] = $foo[$row['parent_id']] ['level'] +1; //p3e/web28  dauerhaft aufgeklappte Kategorien              
                if (isset ($prev_id)) {
                  $foo[$prev_id]['next_id'] = $row['categories_id'];
                }
                $prev_id = $row['categories_id'];
                if (!isset ($first_id)) {
                  $first_id = $row['categories_id'];
                }
                $last_id = $row['categories_id'];
              }
              $foo[$last_id]['next_id'] = isset($foo[$value]['next_id']) ? $foo[$value]['next_id'] : 0;
              $foo[$value]['next_id'] = $first_id;
              $new_path .= '_';
            } else {
              break;
            }
          }
        }
       
        if (!empty($first_element)) {
          xtc_show_category($first_element);
        }
       
        $box_smarty->assign('BOX_CONTENT', $categories_string);
      }
    }

    if (!$cache) {
      $box_categories = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_categories.html');
    } else {
      $box_categories = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_categories.html', $cache_id);
    }

    $smarty->assign('box_CATEGORIES', $box_categories);
    ?>
     

    Im 'template/tpl_modified/source/inc/xtc_show_category.inc.php' alles mit folgendem Code ersetzen

    Code: PHP  [Auswählen]
    <?php
      /* -----------------------------------------------------------------------------------------
       $Id: xtc_show_category.inc.php 4200 2013-01-10 19:47:11Z Tomcraft1980 $

       modified eCommerce Shopsoftware
       http://www.modified-shop.org

       Copyright (c) 2009 - 2013 [www.modified-shop.org]
       -----------------------------------------------------------------------------------------
       based on:
       (c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
       (c) 2002-2003 osCommerce(categories.php,v 1.23 2002/11/12); www.oscommerce.com
       (c) 2003   nextcommerce (xtc_show_category.inc.php,v 1.4 2003/08/13); www.nextcommerce.org
       (c) 2010  web28 (xtc_show_category.inc.php, v 2.1 2010/11/12); www.rpa-com.de

       Released under the GNU General Public License
       ---------------------------------------------------------------------------------------*/
     

      function xtc_show_category($counter, $oldlevel=1) {
        global $foo, $categories_string, $id, $cPath;  

        $level = $foo[$counter]['level']+1;

        //BOF +++ UL LI Verschachtelung  mit Quelltext Tab Einzügen +++    
        $ul = $tab = '';  
        for ($i = 1; $i <= $level; $i++) {
          $tab .= "\t";
        }    

        //BOF +++ Kategorien markieren +++
        $category_path = explode('_',$cPath); //Kategoriepfad in Array einlesen
       
        if ($level > $oldlevel) { //neue Unterebene
    //      $ul = "\n" . $tab. '<ul>'. "\n";
          $ul = "\n" . $tab. '<div class="category_button">' . (in_array($foo[$counter]['parent'], $category_path) ? '-' : '+') . '</div><ul class="subcategories" ' . (!in_array($foo[$counter]['parent'], $category_path) ? 'style="display: none;' : '') . '">'. "\n"; // Kategorien mit Button aufklappen und zuklappen
          $categories_string = rtrim($categories_string, "\n"); //Zeilenumbruch entfernen
          $categories_string = substr($categories_string, 0, strlen($categories_string) -5);  //letztes  </li>  entfernen  
        } elseif ($level < $oldlevel) { //zurück zur höheren Ebene
          $ul = close_ul_tags($level,$oldlevel);      
        }
        //EOF +++ UL LI Verschachtelung  mit Quelltext Tab Einzügen +++


        //Elternkategorie markieren
        $cat_active_parent = '';
        $in_path = in_array($counter, $category_path); //Testen, ob aktuelle Kategorie ID im Kategoriepfad enthalten ist
        if ($in_path) $cat_active_parent = " activeparent".$level;
       
        //Aktive Kategorie markieren
        $cat_active = '';
        $this_category = array_pop($category_path); //Letzter Eintrag im Array ist die aktuelle Kategorie
        if ($this_category == $counter) $cat_active = " active".$level;
        //EOF +++ Kategorien markieren +++

        //BOF +++ Kategorie Linkerstellung +++  
        if (trim($categories_string == '')) $categories_string = "\n"; //Zeilenschaltung Codedarstellung  
        $categories_string .= $ul; //UL LI Versschachtelung
        $categories_string .= $tab; //Tabulator Codedarstellung
    //    $categories_string .= '<li class="level'.$level.$cat_active.$cat_active_parent.'">';    
        $categories_string .= '<li class="category_li level'.$level.$cat_active.$cat_active_parent.'">'; // Kategorien mit Button aufklappen und zuklappen
        $categories_string .= '<a href="'.$foo[$counter]['link'].'" title="'. $foo[$counter]['name'] . '">';
        $categories_string .= $foo[$counter]['name'];
        //Anzeige Anzahl der Produkte in Kategorie, für bessere Performance im Admin deaktivieren
        if (SHOW_COUNTS == 'true') {
          $products_in_category = xtc_count_products_in_category($counter);
          if ($products_in_category > 0) {
            $categories_string .= '&nbsp;(' . $products_in_category . ')';
          }
        }  
        $categories_string .= '</a></li>';
        $categories_string .= "\n"; //Zeilenschaltung Codedarstellung  
        //EOF  +++ Kategorie Linkerstellung +++

        //Nächste Kategorie
        if ($foo[$counter]['next_id']) {
          xtc_show_category($foo[$counter]['next_id'], $level);
        } else {  
          if ($level > 1) $categories_string .= close_ul_tags(1,$level);
          return;
        }
      }
    ?>
     

    Im 'template/tpl_modified/stylesheet.css' folgenden Code ganz am Ende einfügen

    Code: CSS  [Auswählen]
    /* START Kategorien mit Button aufklappen und zuklappen */
    .category_li {
      position: relative;
    }

    .category_button {
      font-size: 20px;
      line-height: 26px;
      width: 27px;
      height: 27px;
      background-color: #e3e3e3;
      color: #444;
      text-align: center;
      cursor:pointer;
      position: absolute;
      top: 0;
      right: 0;
    }

    ul#categorymenu li.level1 a,
    ul#categorymenu li.level2 a,
    ul#categorymenu li.level3 a,
    ul#categorymenu li.level4 a,
    ul#categorymenu li.level5 a {
      padding-right: 28px;
    }
    /* ENDE Kategorien mit Button aufklappen und zuklappen */
     

    Im 'template/tpl_modified/javascript/general_bottom.js.php' folgenden Code ganz am Ende einfügen, also nach '<?php } ?>'

    Code: PHP  [Auswählen]
    <!-- START Kategorien mit Button aufklappen und zuklappen -->
    <script>
      $(function(){
        $('.category_button').click(function() {
          var $this = $(this);
          $this.siblings('.subcategories').slideToggle();
          $this.text($this.text() == "+" ? "-" : "+");
        });
      });
    </script>
    <!-- ENDE Kategorien mit Button aufklappen und zuklappen -->
     

    Gruss
    Hanspeter

    ams

    • Fördermitglied
    • Beiträge: 175
    Hallo Hanspeter,
    vielen Dank für deine ausführliche Rückmeldung!

    Das sieht super aus. Ich habe nur leider einen älteren Shop. Gibt es auch eine Einbauanleitung für die alten 105er Shops? :-)

    Die ersten beiden Anpassungen werden bei mir wahrscheinlich Probleme machen, oder was meinst du? Hast du da Erfahrungen?

    Beste Grüße
    ams

    hpzeller

    • Experte
    • Beiträge: 4.129
    • Geschlecht:
    Hast du einen Link zum Shop?

    PS:
    Wenn du einen so alten Shop hast rate ich dir ein Update zu machen, denn abgesehen von Sicherheitsmängeln die ein so alter Shop hat, musst du damit rechnen das dir der Hoster bald einmal die nötige PHP-Version nicht mehr anbietet.

    Gruss
    Hanspeter

    ams

    • Fördermitglied
    • Beiträge: 175
    Hab dir gerade ne Mail geschickt!

    ams

    • Fördermitglied
    • Beiträge: 175
    Hallo Hanspeter,

    ich versuche gerade deine Anpassungen in einer älteren Shopversion einzuarbeiten. Dazu hätte ich einige Fragen zu deiner Anleitung.

    template/tpl_modified/source/boxes/categories.php
    - Kannst du mir hier deine Anpassungen nennen bzw. welche Zeilen es genau sind?

    template/tpl_modified/source/inc/xtc_show_category.inc.php
    - hast du hier nur diese Anpassung gemacht?

    Code: PHP  [Auswählen]
    $ul = "\n" . $tab. '<div class="category_button">' . (in_array($foo[$counter]['parent'], $category_path) ? '-' : '+') . '</div><ul class="subcategories" ' . (!in_array($foo[$counter]['parent'], $category_path) ? 'style="display: none;' : '') . '">'. "\n"; // Kategorien mit Button aufklappen und zuklappen

    template/tpl_modified/javascript/general_bottom.js.php
    - diese Datei gibt es bei mir nicht, kann ich das in die template/xtc5/javascript/general.js.php übernehmen oder kann ich das gleich vergessen?

    Über eine Rückmeldung würde ich mich freuen, danke!
    ams

    hpzeller

    • Experte
    • Beiträge: 4.129
    • Geschlecht:
    Hallo ams,

    um es gleich vorweg zu nehmen bei meinem Vorschlag wird jeweils der komplette Kategorie-Baum an den Browser gesendet und bei bedarf per JavaScript ein- bzw. aus-geblendet, dies hat unweigerlich zur Folge das sich die Ladezeit (Übertragung und Rendering) der Seite erhöht. Mein Vorschlag ist deshalb für Shops mit sehr vielen und tief verschachtelten Kategorien nicht geeignet.

    Leider habe ich keinen Code eines 1.05er Shops, aber du könntest ja mal den kompletten Code der Skripte 'template/tpl_modified/source/boxes/categories.php' und 'template/tpl_modified/source/inc/xtc_show_category.inc.php' deines Shops hier posten, dann kann ich dir evtl. zeigen was zu ändern ist.

    Gruss
    Hanspeter

    web28

    • modified Team
    • Beiträge: 9.404
    [...]
    Wie wurde das hier umgesetzt? Ist auch ein modified shop, den ich beim Suchen hier gefunden habe. Gibt es dafür vielleicht irgendwo eine Anleitung?

    Beispiel: merchandisee.de
    [...]

    Kann man im Quelltext der Beispielseite sehen. hpzeller hat das für modified etwas angepasst.

    Wer sehr viele Kategorien hat kann diese Lösungen nicht gebrauchen, das hat hpzeller aber auch schon geschrieben. Bei solchen Shop benötigt man eine dynamische Nachladefunktion der Unterkategorien anstatt eine einfaches Ein/Ausblenden.

    ams

    • Fördermitglied
    • Beiträge: 175
    Ok, vielen Dank für den Hinweis!

    Das kommt dann bei uns eher nicht in Frage. Ich suche weiter...

    Danke euch!

    ams

    • Fördermitglied
    • Beiträge: 175

    Leider habe ich keinen Code eines 1.05er Shops, aber du könntest ja mal den kompletten Code der Skripte 'template/tpl_modified/source/boxes/categories.php' und 'template/tpl_modified/source/inc/xtc_show_category.inc.php' deines Shops hier posten, dann kann ich dir evtl. zeigen was zu ändern ist.


    Hallo Hanspeter,
    ich komme doch nochmal auf dein Angebot zurück. Ich würde es testen und mir die Ladezeit mal ansehen, wir haben ca. 80-100 Kategorien. Vielleicht klappt es ja doch noch.

    Ich würde mich freuen, wenn du mir da einen Tipp geben könntest, danke!

    Anbei die beiden Dateien:

    template/xtc5/source/boxes/categories.php
    Code: PHP  [Auswählen]
    <?php

    /* -----------------------------------------------------------------------------------------
       $Id: categories.php 1302 2005-10-12 16:21:29Z mz $  

       XT-Commerce - community made shopping
       http://www.(( Wir dulden keine kommerziellen Werbelinks - Bitte <a href="index.php?topic=3013.0">Forenregeln</a> beachten! ))

       Copyright (c) 2003 XT-Commerce
       -----------------------------------------------------------------------------------------
       based on:
       (c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
       (c) 2002-2003 osCommerce(categories.php,v 1.23 2002/11/12); www.oscommerce.com
       (c) 2003      nextcommerce (categories.php,v 1.10 2003/08/17); www.nextcommerce.org

       Released under the GNU General Public License
       -----------------------------------------------------------------------------------------
       Third Party contributions:
       Enable_Disable_Categories 1.3                Autor: Mikel Williams | mikel@ladykatcostumes.com

       Released under the GNU General Public License
       ---------------------------------------------------------------------------------------*/

    // reset var
    $box_smarty = new smarty;
    $box_content = '';
    $rebuild = false;

    $box_smarty->assign('language', $_SESSION['language']);
    // set cache ID
    if (!CacheCheck()) {
            $cache=false;
            $box_smarty->caching = 0;
      $cache_id = null; //DokuMan - 2010-02-26 - Undefined variable: cache_id
    } else {
            $cache=true;
            $box_smarty->caching = 1;
            $box_smarty->cache_lifetime = CACHE_LIFETIME;
            $box_smarty->cache_modified_check = CACHE_CHECK;
            $cache_id = $_SESSION['language'].$_SESSION['customers_status']['customers_status_id'].'-'.$cPath;
    }

    if(!$box_smarty->is_cached(CURRENT_TEMPLATE.'/boxes/box_categories.html', $cache_id) || !$cache){
    $box_smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE.'/');
    $rebuild=true;

    // include needed functions
    require_once (DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/source/inc/xtc_show_category.inc.php');
    require_once (DIR_FS_INC.'xtc_has_category_subcategories.inc.php');
    require_once (DIR_FS_INC.'xtc_count_products_in_category.inc.php');


    $categories_string = '';
    if (GROUP_CHECK == 'true') {
            $group_check = "and c.group_permission_".$_SESSION['customers_status']['customers_status_id']."=1 ";
    }
    $categories_query = "select c.categories_id,
                                               cd.categories_name,
                                               c.parent_id
                                               from "
    .TABLE_CATEGORIES." c,
                                               "
    .TABLE_CATEGORIES_DESCRIPTION." cd
                                               where c.categories_status = '1'
                                               and c.section = '0'
                                               and c.parent_id = '0'
                                               "
    .$group_check."
                                               and c.categories_id = cd.categories_id
                                                                                       and c.categories_id != '10' # wo die XX stehen deine auszublendende Kategorie-ID
                                               and cd.language_id='"
    .(int) $_SESSION['languages_id']."'
                                               order by sort_order, cd.categories_name"
    ;
    $categories_query = xtDBquery($categories_query);

    while ($categories = xtc_db_fetch_array($categories_query, true)) {
            $foo[$categories['categories_id']] = array ('name' => $categories['categories_name'], 'parent' => $categories['parent_id'], 'level' => 0, 'path' => $categories['categories_id'], 'next_id' => false);

            if (isset ($prev_id)) {
                    $foo[$prev_id]['next_id'] = $categories['categories_id'];
            }

            $prev_id = $categories['categories_id'];

            if (!isset ($first_element)) {
                    $first_element = $categories['categories_id'];
            }
    }

    //------------------------
    if ($cPath) {
            $new_path = '';
            $id = explode('_', $cPath);
            reset($id);
            while (list ($key, $value) = each($id)) {
                    unset ($prev_id);
                    unset ($first_id);
                    $categories_query = "select c.categories_id, cd.categories_name, c.parent_id from ".TABLE_CATEGORIES." c, ".TABLE_CATEGORIES_DESCRIPTION." cd where c.categories_status = '1' and c.parent_id = '".$value."' ".$group_check." and c.categories_id = cd.categories_id and cd.language_id='".$_SESSION['languages_id']."' order by sort_order, cd.categories_name";
                    $categories_query = xtDBquery($categories_query);
                    $category_check = xtc_db_num_rows($categories_query, true);
                    if ($category_check > 0) {
                            $new_path .= $value;
                            while ($row = xtc_db_fetch_array($categories_query, true)) {
                                    $foo[$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 ($prev_id)) {
                                            $foo[$prev_id]['next_id'] = $row['categories_id'];
                                    }

                                    $prev_id = $row['categories_id'];

                                    if (!isset ($first_id)) {
                                            $first_id = $row['categories_id'];
                                    }

                                    $last_id = $row['categories_id'];
                            }
                            $foo[$last_id]['next_id'] = $foo[$value]['next_id'];
                            $foo[$value]['next_id'] = $first_id;
                            $new_path .= '_';
                    } else {
                            break;
                    }
            }
    }

    xtc_show_category($first_element);
    }

    // set cache ID
    if (!$cache || $rebuild) {
            $box_smarty->assign('BOX_CONTENT', $categories_string);
            if ($rebuild) $box_smarty->clear_cache(CURRENT_TEMPLATE.'/boxes/box_categories.html', $cache_id);
            $box_categories = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_categories.html',$cache_id);
    } else {
            $box_categories = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_categories.html', $cache_id);
    }

    $smarty->assign('box_CATEGORIES', $box_categories);
    ?>
     

    template/xtc5/source/inc/xtc_show_category.inc.php
    Code: PHP  [Auswählen]
    <?php
    /* -----------------------------------------------------------------------------------------
       $Id$

       modified eCommerce Shopsoftware - community made shopping
       http://www.modified eCommerce Shopsoftware.org

       Copyright (c) 2010 modified eCommerce Shopsoftware
       -----------------------------------------------------------------------------------------
       XT-Commerce - community made shopping
       http://www.(( Wir dulden keine kommerziellen Werbelinks - Bitte <a href="index.php?topic=3013.0">Forenregeln</a> beachten! ))

       Copyright (c) 2003 XT-Commerce
       -----------------------------------------------------------------------------------------
       based on:
       (c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
       (c) 2002-2003 osCommerce(categories.php,v 1.23 2002/11/12); www.oscommerce.com
       (c) 2003      nextcommerce (xtc_show_category.inc.php,v 1.4 2003/08/13); www.nextcommerce.org
       (c) 2010  web28 (xtc_show_category.inc.php, v 2.1 2010/11/12); www.rpa-com.de

       Released under the GNU General Public License
       ---------------------------------------------------------------------------------------*/
     

    function xtc_show_category($counter, $oldlevel=1) {
            global $foo, $categories_string, $id, $cPath;  
           
            $level = $foo[$counter]['level']+1;
           
            //BOF +++ UL LI Verschachtelung  mit Quelltext Tab Einzügen +++               
                    $ul = $tab = '';       
                    for ($i = 1; $i <= $level; $i++) {
                            $tab .= "\t";
                    }              
                   
                    if ($level > $oldlevel) { //neue Unterebene
                            $ul = "\n" . $tab. '<ul>'. "\n";
                            $categories_string = rtrim($categories_string, "\n"); //Zeilenumbruch entfernen
                            $categories_string = substr($categories_string, 0, strlen($categories_string) -5);  //letztes  </li>  entfernen
                    }
                    elseif ($level < $oldlevel) { //zurück zur höheren Ebene
                            $ul = close_ul_tags($level,$oldlevel);                 
                    }
                   
            //EOF +++ UL LI Verschachtelung  mit Quelltext Tab Einzügen +++
           
            //BOF +++ Kategorien markieren +++
                    $category_path = explode('_',$cPath); //Kategoriepfad in Array einlesen
                   
                    //Elternkategorie markieren
                    $cat_active_parent = '';
                    $in_path = in_array($counter, $category_path); //Testen, ob aktuelle Kategorie ID im Kategoriepfad enthalten ist
                    if ($in_path) $cat_active_parent = " activeparent".$level;
                   
                    //Aktive Kategorie markieren
                    $cat_active = '';
                    $this_category = array_pop($category_path); //Letzter Eintrag im Array ist die aktuelle Kategorie
                    if ($this_category == $counter) $cat_active = " active".$level;
            //EOF +++ Kategorien markieren +++
           
           
            //BOF +++ Kategorie Linkerstellung +++ 
                    $cPath_new=xtc_category_link($counter,$foo[$counter]['name']);
                   
                    if (trim($categories_string == '')) $categories_string = "\n"; //Zeilenschaltung Codedarstellung       
                   
                    $categories_string .= $ul; //UL LI Versschachtelung
                    $categories_string .= $tab; //Tabulator Codedarstellung
                    $categories_string .= '<li class="level'.$level.$cat_active.$cat_active_parent.'">';
                    $categories_string .= '<a href="'.xtc_href_link(FILENAME_DEFAULT, $cPath_new).'" title="'. $foo[$counter]['name'] . '">';
                    $categories_string .= $foo[$counter]['name'];
                   
                    //Anzeige Anzahl der Produkte in Kategorie, für bessere Performance im Admin deaktivieren
                    if (SHOW_COUNTS == 'true') {
                            $products_in_category = xtc_count_products_in_category($counter);
                            if ($products_in_category > 0) {
                                    $categories_string .= '&nbsp;(' . $products_in_category . ')';
                            }
                    }      

                    $categories_string .= '</a></li>';
                    $categories_string .= "\n"; //Zeilenschaltung Codedarstellung  
            //EOF  +++ Kategorie Linkerstellung +++

            //Nächste Kategorie
            if ($foo[$counter]['next_id']) {
                    xtc_show_category($foo[$counter]['next_id'], $level);
            } else {       
                    if ($level > 1) $categories_string .= close_ul_tags(1,$level);
                    return;
            }
    }

    //Alle offenen UL LI Tags schließen
    function close_ul_tags($level, $oldlevel) {
            $count = 1;
            $ul = '';
            while($count <= $oldlevel - $level) { //für jede Ebene die UL LI Tags schließen
                    $tab_end = '';
                    for ($i = 1; $i <= $oldlevel - $count; $i++) {
                            $tab_end .= "\t";
                    }                      
                    $ul .=  $tab_end . "\t". '</ul>'. "\n". $tab_end . '</li>'. "\n";                      
                    $count++;
            }
            return $ul;
    }
    ?>
     

    Besten Dank
    ams

    hpzeller

    • Experte
    • Beiträge: 4.129
    • Geschlecht:
    Hallo ams,

    habe die Änderungen in die Skripte unten eingefügt.

    template/xtc5/source/boxes/categories.php
    Code: PHP  [Auswählen]
    <?php

    /* -----------------------------------------------------------------------------------------
       $Id: categories.php 1302 2005-10-12 16:21:29Z mz $  

       XT-Commerce - community made shopping
       http://www.(( Wir dulden keine kommerziellen Werbelinks - Bitte <a href="index.php?topic=3013.0">Forenregeln</a> beachten! ))

       Copyright (c) 2003 XT-Commerce
       -----------------------------------------------------------------------------------------
       based on:
       (c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
       (c) 2002-2003 osCommerce(categories.php,v 1.23 2002/11/12); www.oscommerce.com
       (c) 2003      nextcommerce (categories.php,v 1.10 2003/08/17); www.nextcommerce.org

       Released under the GNU General Public License
       -----------------------------------------------------------------------------------------
       Third Party contributions:
       Enable_Disable_Categories 1.3                Autor: Mikel Williams | mikel@ladykatcostumes.com

       Released under the GNU General Public License
       ---------------------------------------------------------------------------------------*/

    // reset var
    $box_smarty = new smarty;
    $box_content = '';
    $rebuild = false;

    $box_smarty->assign('language', $_SESSION['language']);
    // set cache ID
    if (!CacheCheck()) {
            $cache=false;
            $box_smarty->caching = 0;
      $cache_id = null; //DokuMan - 2010-02-26 - Undefined variable: cache_id
    } else {
            $cache=true;
            $box_smarty->caching = 1;
            $box_smarty->cache_lifetime = CACHE_LIFETIME;
            $box_smarty->cache_modified_check = CACHE_CHECK;
            $cache_id = $_SESSION['language'].$_SESSION['customers_status']['customers_status_id'].'-'.$cPath;
    }

    if(!$box_smarty->is_cached(CURRENT_TEMPLATE.'/boxes/box_categories.html', $cache_id) || !$cache){
    $box_smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE.'/');
    $rebuild=true;

    // include needed functions
    require_once (DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/source/inc/xtc_show_category.inc.php');
    require_once (DIR_FS_INC.'xtc_has_category_subcategories.inc.php');
    require_once (DIR_FS_INC.'xtc_count_products_in_category.inc.php');


    $categories_string = '';
    if (GROUP_CHECK == 'true') {
            $group_check = "and c.group_permission_".$_SESSION['customers_status']['customers_status_id']."=1 ";
    }
    $categories_query = "select c.categories_id,
                                               cd.categories_name,
                                               c.parent_id
                                               from "
    .TABLE_CATEGORIES." c,
                                               "
    .TABLE_CATEGORIES_DESCRIPTION." cd
                                               where c.categories_status = '1'
                                               and c.section = '0'
                                               "
    .$group_check."
                                               and c.categories_id = cd.categories_id
                                               and c.categories_id != '10' # wo die XX stehen deine auszublendende Kategorie-ID
                                               and cd.language_id='"
    .(int) $_SESSION['languages_id']."'
                                               order by sort_order, cd.categories_name"
    ;
    $categories_query = xtDBquery($categories_query);

    while ($categories = xtc_db_fetch_array($categories_query, true)) {
          if ($categories['parent_id'] == 0) {     
            $foo[$categories['categories_id']] = array ('name' => $categories['categories_name'], 'parent' => $categories['parent_id'], 'level' => 0, 'path' => $categories['categories_id'], 'next_id' => false);

            if (isset ($prev_id)) {
                    $foo[$prev_id]['next_id'] = $categories['categories_id'];
            }

            $prev_id = $categories['categories_id'];

            if (!isset ($first_element)) {
                    $first_element = $categories['categories_id'];
            }
          } else {
            if (!in_array($categories['parent_id'], $sub_categories)) $sub_categories[] = $categories['parent_id'];
          }        
    }

    //------------------------
    // if ($cPath) {
    if (!empty($sub_categories)) {
            $new_path = '';
    //        $id = explode('_', $cPath);
                  $id = $sub_categories;        
            reset($id);
            while (list ($key, $value) = each($id)) {
                    unset ($prev_id);
                    unset ($first_id);
                    $categories_query = "select c.categories_id, cd.categories_name, c.parent_id from ".TABLE_CATEGORIES." c, ".TABLE_CATEGORIES_DESCRIPTION." cd where c.categories_status = '1' and c.parent_id = '".$value."' ".$group_check." and c.categories_id = cd.categories_id and cd.language_id='".$_SESSION['languages_id']."' order by sort_order, cd.categories_name";
                    $categories_query = xtDBquery($categories_query);
                    $category_check = xtc_db_num_rows($categories_query, true);
                    if ($category_check > 0) {
                            $new_path .= $value;
                            while ($row = xtc_db_fetch_array($categories_query, true)) {
                                    $foo[$row['categories_id']] = array ('name' => $row['categories_name'],
                                                 'parent' => $row['parent_id'],
                                                 'level' => $key +1,
                                                 'path' => $new_path.'_'.$row['categories_id'],
                                                 'next_id' => false
                                                );

                                    $foo[$row['categories_id']]['level'] = $foo[$row['parent_id']] ['level'] +1; //p3e/web28  dauerhaft aufgeklappte Kategorien

                                    if (isset ($prev_id)) {
                                            $foo[$prev_id]['next_id'] = $row['categories_id'];
                                    }

                                    $prev_id = $row['categories_id'];

                                    if (!isset ($first_id)) {
                                            $first_id = $row['categories_id'];
                                    }

                                    $last_id = $row['categories_id'];
                            }
                            $foo[$last_id]['next_id'] = $foo[$value]['next_id'];
                            $foo[$value]['next_id'] = $first_id;
                            $new_path .= '_';
                    } else {
                            break;
                    }
            }
    }

    xtc_show_category($first_element);
    }

    // set cache ID
    if (!$cache || $rebuild) {
            $box_smarty->assign('BOX_CONTENT', $categories_string);
            if ($rebuild) $box_smarty->clear_cache(CURRENT_TEMPLATE.'/boxes/box_categories.html', $cache_id);
            $box_categories = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_categories.html',$cache_id);
    } else {
            $box_categories = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_categories.html', $cache_id);
    }

    $smarty->assign('box_CATEGORIES', $box_categories);
    ?>
     

    template/xtc5/source/inc/xtc_show_category.inc.php
    Code: PHP  [Auswählen]
    <?php
    /* -----------------------------------------------------------------------------------------
       $Id$

       modified eCommerce Shopsoftware - community made shopping
       http://www.modified eCommerce Shopsoftware.org

       Copyright (c) 2010 modified eCommerce Shopsoftware
       -----------------------------------------------------------------------------------------
       XT-Commerce - community made shopping
       http://www.(( Wir dulden keine kommerziellen Werbelinks - Bitte <a href="index.php?topic=3013.0">Forenregeln</a> beachten! ))

       Copyright (c) 2003 XT-Commerce
       -----------------------------------------------------------------------------------------
       based on:
       (c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
       (c) 2002-2003 osCommerce(categories.php,v 1.23 2002/11/12); www.oscommerce.com
       (c) 2003      nextcommerce (xtc_show_category.inc.php,v 1.4 2003/08/13); www.nextcommerce.org
       (c) 2010  web28 (xtc_show_category.inc.php, v 2.1 2010/11/12); www.rpa-com.de

       Released under the GNU General Public License
       ---------------------------------------------------------------------------------------*/
     

    function xtc_show_category($counter, $oldlevel=1) {
            global $foo, $categories_string, $id, $cPath;  
           
            $level = $foo[$counter]['level']+1;
           
            //BOF +++ UL LI Verschachtelung  mit Quelltext Tab Einzügen +++                
                    $ul = $tab = '';        
                    for ($i = 1; $i <= $level; $i++) {
                            $tab .= "\t";
                    }              

            //BOF +++ Kategorien markieren +++
                    $category_path = explode('_',$cPath); //Kategoriepfad in Array einlesen
                   
                    if ($level > $oldlevel) { //neue Unterebene
    //                        $ul = "\n" . $tab. '<ul>'. "\n";
                            $ul = "\n" . $tab. '<div class="category_button">' . (in_array($foo[$counter]['parent'], $category_path) ? '-' : '+') . '</div><ul class="subcategories" ' . (!in_array($foo[$counter]['parent'], $category_path) ? 'style="display: none;' : '') . '">'. "\n"; // Kategorien mit Button aufklappen und zuklappen                        
                            $categories_string = rtrim($categories_string, "\n"); //Zeilenumbruch entfernen
                            $categories_string = substr($categories_string, 0, strlen($categories_string) -5);  //letztes  </li>  entfernen
                    }
                    elseif ($level < $oldlevel) { //zurück zur höheren Ebene
                            $ul = close_ul_tags($level,$oldlevel);                  
                    }
                   
            //EOF +++ UL LI Verschachtelung  mit Quelltext Tab Einzügen +++
                   
                    //Elternkategorie markieren
                    $cat_active_parent = '';
                    $in_path = in_array($counter, $category_path); //Testen, ob aktuelle Kategorie ID im Kategoriepfad enthalten ist
                    if ($in_path) $cat_active_parent = " activeparent".$level;
                   
                    //Aktive Kategorie markieren
                    $cat_active = '';
                    $this_category = array_pop($category_path); //Letzter Eintrag im Array ist die aktuelle Kategorie
                    if ($this_category == $counter) $cat_active = " active".$level;
            //EOF +++ Kategorien markieren +++
           
           
            //BOF +++ Kategorie Linkerstellung +++  
                    $cPath_new=xtc_category_link($counter,$foo[$counter]['name']);
                   
                    if (trim($categories_string == '')) $categories_string = "\n"; //Zeilenschaltung Codedarstellung        
                   
                    $categories_string .= $ul; //UL LI Versschachtelung
                    $categories_string .= $tab; //Tabulator Codedarstellung
    //                $categories_string .= '<li class="level'.$level.$cat_active.$cat_active_parent.'">';
                    $categories_string .= '<li class="category_li level'.$level.$cat_active.$cat_active_parent.'">'; // Kategorien mit Button aufklappen und zuklappen                     
                    $categories_string .= '<a href="'.xtc_href_link(FILENAME_DEFAULT, $cPath_new).'" title="'. $foo[$counter]['name'] . '">';
                    $categories_string .= $foo[$counter]['name'];
                   
                    //Anzeige Anzahl der Produkte in Kategorie, für bessere Performance im Admin deaktivieren
                    if (SHOW_COUNTS == 'true') {
                            $products_in_category = xtc_count_products_in_category($counter);
                            if ($products_in_category > 0) {
                                    $categories_string .= '&nbsp;(' . $products_in_category . ')';
                            }
                    }      

                    $categories_string .= '</a></li>';
                    $categories_string .= "\n"; //Zeilenschaltung Codedarstellung  
            //EOF  +++ Kategorie Linkerstellung +++

            //Nächste Kategorie
            if ($foo[$counter]['next_id']) {
                    xtc_show_category($foo[$counter]['next_id'], $level);
            } else {        
                    if ($level > 1) $categories_string .= close_ul_tags(1,$level);
                    return;
            }
    }

    //Alle offenen UL LI Tags schließen
    function close_ul_tags($level, $oldlevel) {
            $count = 1;
            $ul = '';
            while($count <= $oldlevel - $level) { //für jede Ebene die UL LI Tags schließen
                    $tab_end = '';
                    for ($i = 1; $i <= $oldlevel - $count; $i++) {
                            $tab_end .= "\t";
                    }                      
                    $ul .=  $tab_end . "\t". '</ul>'. "\n". $tab_end . '</li>'. "\n";                      
                    $count++;
            }
            return $ul;
    }
    ?>
     

    Folgender Code in der 'template/xtc5/source/boxes/categories.php' and c.section = '0' und and c.categories_id != '10' # wo die XX stehen deine auszublendende Kategorie-ID, scheint eine Shop spezifische Anpassung zu sein, eventuell muss man diese Zeilen noch entfernen um einen kompletten Kategorie-Baum zu erhalten.

    Da es in deinem Shop wahrscheinlich keine 'general_bottom.js.php' Datei gibt, müsste man noch abklären wo das JavaScript einzubauen ist, es muss nämlich nach der jQuery Bibliothek eingefügt werden.

    PS:
    Also 80-100 Kategorien sind nicht viel, es gibt Shops die weitaus mehr Kategorien laden.

    Gruss
    Hanspeter

    ams

    • Fördermitglied
    • Beiträge: 175
    Hallo Hanspeter,
    vielen Dank für die Anpassung, super Sache!

    Ja stimmt, die general_bottom.js.php gibts bei mir nicht. Ich hätte es in die template/xtc5/javascript/general.js.php übernommen, geht das überhaupt so einfach?

    Danke dir!
    ams

    hpzeller

    • Experte
    • Beiträge: 4.129
    • Geschlecht:
    Ja in die 'template/xtc5/javascript/general.js.php' kannst du das JavaScript einbauen, einfach darauf achten das es nach der jQuery library im HTLM-Quellcode eingebunden wird.

    Folgende CSS-Eigenschaften musst du natürlich passend zu deinem Template ändern,

    Code: CSS  [Auswählen]
      font-size: 20px;
      line-height: 26px;
      width: 27px;
      height: 27px;
      background-color: #e3e3e3;
      color: #444;


      padding-right: 28px;
     

    den Rest des CSS darfst du aber nicht ändern, sonst werden keine Buttons angezeigt.

    Gruss
    Hanspeter

    ams

    • Fördermitglied
    • Beiträge: 175
    Hallo Hanspeter,

    das mit der 'template/xtc5/javascript/general.js.php' hat super geklappt!

    Das CSS passe ich noch an. Vielen Dank für die super Hilfe!!!

    Beste Grüße
    ams

    hpzeller

    • Experte
    • Beiträge: 4.129
    • Geschlecht:
    Keine Ursache

    Gruss
    Hanspeter

    insertinto

    • Neu im Forum
    • Beiträge: 32
    • Geschlecht:
    Danke für die Anleitung!
    Passt auch gut in tpl_modified_responsive rein.

    viele Grüße
    Ines
    13 Antworten
    10762 Aufrufe
    15. Juli 2011, 18:42:21 von dr4g0nstyle
               
    anything