Nachfolgendes PHP-Script enthält die Classe zur Erzeugung der Strukturen für das mod_mainmenu für Virtuemart - erzeugt also eine Categry-Display-Type zur Darstellung als Navigationsmenü im Listenformat.
joomlapfad/modules/mod_virtuemart/vm_modmainmenu.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
if ( ! defined ( '_VALID_MOS' ) && ! defined ( '_JEXEC' ) ) die ( 'Direct Access to ' . basename ( __FILE__ ) . ' is not allowed.' ) ; /** * * @copyright Copyright (C) 2009 kraft - All rights reserved. */ /* The class to manage and show product categories */ class modmainmenutree extends vmAbstractObject { /** * @param int $category_id The category to be highlighted * @return string HTML code with the link list */ function get_category_mainmenu( $curr_cat_id = 0 ) { global $sess ; $categories = ps_product_category:: getCategoryTreeArray ( ) ; $result = ps_product_category:: sortCategoryTreeArray ( $categories ) ; $id_list = $result [ 'id_list' ] ; $count = count ( $id_list ) ; $sorted_cats = Array ( ) ; for ( $n = 0 ; $n < $count ; $n ++ ) { $sorted_cats [ $n ] [ 'category_child_id' ] = $categories [ $id_list [ $n ] ] [ 'category_child_id' ] ; $sorted_cats [ $n ] [ 'category_parent_id' ] = $categories [ $id_list [ $n ] ] [ 'category_parent_id' ] ; $sorted_cats [ $n ] [ 'category_name' ] = $categories [ $id_list [ $n ] ] [ 'category_name' ] ; $sorted_cats [ $n ] [ 'cat_depth' ] = $result [ 'depth_list' ] [ $n ] ; } $allowed_subcats = Array ( ) ; if ( ! empty ( $categories [ $curr_cat_id ] [ 'category_parent_id' ] ) ) { $root = $categories [ $curr_cat_id ] ; $allowed_subcats [ ] = $categories [ $curr_cat_id ] [ 'category_parent_id' ] ; while ( ! empty ( $root [ 'category_parent_id' ] ) ) { $root = $categories [ $root [ 'category_parent_id' ] ] ; $allowed_subcats [ ] = $categories [ $root [ 'category_child_id' ] ] [ 'category_child_id' ] ; } } for ( $n = 0 ; $n < $count ; $n ++ ) { if ( $sorted_cats [ $n ] [ 'category_parent_id' ] == 0 || in_array ( $sorted_cats [ $n ] [ 'category_child_id' ] , $allowed_subcats ) || in_array ( $sorted_cats [ $n ] [ 'category_parent_id' ] , $allowed_subcats ) || $sorted_cats [ $n ] [ "category_parent_id" ] == $curr_cat_id ) { $sorted_cats [ $n ] [ 'cat_allowed' ] = 1 ; } if ( ( $sorted_cats [ $n + 1 ] [ 'category_parent_id' ] > 0 ) && ( $sorted_cats [ $n + 1 ] [ 'cat_depth' ] > $sorted_cats [ $n ] [ 'cat_depth' ] ) ) { $sorted_cats [ $n ] [ 'cat_isparent' ] = "parent" ; } if ( in_array ( $sorted_cats [ $n ] [ 'category_child_id' ] , $allowed_subcats ) || $sorted_cats [ $n ] [ 'category_child_id' ] == $curr_cat_id ) { $sorted_cats [ $n ] [ 'cat_isactive' ] = "active" ; } if ( $sorted_cats [ $n ] [ 'cat_depth' ] > $sorted_cats [ $n - 1 ] [ 'cat_depth' ] || $n == 0 ) { $sorted_cats [ $n ] [ 'cat_first_item' ] = "first_item" ; } if ( $sorted_cats [ $n + 1 ] [ 'cat_depth' ] < $sorted_cats [ $n ] [ 'cat_depth' ] || $n == $count ) { $sorted_cats [ $n ] [ 'cat_last_item' ] = "last_item" ; } } $cat_id = 0 ; foreach ( $sorted_cats as $cat ) { if ( ! $cat [ 'cat_allowed' ] ) { array_splice ( $sorted_cats , $cat_id , 1 ) ; } else { $cat_id ++; } } $modMainMenuHTML = '' ; $count = count ( $sorted_cats ) ; for ( $n = 0 ; $n < $count ; $n ++ ) { $liClass = "" ; $liID = "" ; $aClass = "" ; $catname = shopMakeHtmlSafe( $sorted_cats [ $n ] [ 'category_name' ] ) ; if ( ! empty ( $sorted_cats [ $n ] [ 'cat_first_item' ] ) ) { $liClass .= " " . $sorted_cats [ $n ] [ 'cat_first_item' ] ; } if ( ! empty ( $sorted_cats [ $n ] [ 'cat_last_item' ] ) ) { $liClass .= " " . $sorted_cats [ $n ] [ 'cat_last_item' ] ; } if ( ! empty ( $sorted_cats [ $n ] [ 'cat_isparent' ] ) ) { $liClass .= " " . $sorted_cats [ $n ] [ 'cat_isparent' ] ; } if ( ! empty ( $sorted_cats [ $n ] [ 'cat_isactive' ] ) ) { $liClass .= " " . $sorted_cats [ $n ] [ 'cat_isactive' ] ; } if ( $sorted_cats [ $n ] [ 'category_child_id' ] == $curr_cat_id ) { $liID .= ' id="current"' ; } if ( ! empty ( $sorted_cats [ $n ] [ 'cat_isactive' ] ) || $sorted_cats [ $n ] [ 'category_child_id' ] == $curr_cat_id ) { $aClass = ' class="' ; if ( ! empty ( $sorted_cats [ $n ] [ 'cat_isactive' ] ) ) { $aClass .= 'active_link' ; } if ( $sorted_cats [ $n ] [ 'category_child_id' ] == $curr_cat_id ) { $aClass .= ' current_link' ; } $aClass .= '"' ; } $ULLI = "" ; if ( ! empty ( $sorted_cats [ $n ] [ 'cat_first_item' ] ) ) { $ULLI = " ; } if ( $n == 0 ) { $ULLI = ' ; } if ( ! empty ( $sorted_cats [ $n - 1 ] [ 'cat_last_item' ] ) ) { $ULLI = str_repeat ( "" , $sorted_cats [ $n - 1 ] [ 'cat_depth' ] - $sorted_cats [ $n ] [ 'cat_depth' ] ) . '' ; } $modMainMenuHTML .= $ULLI . '. $sorted_cats [ $n ] [ 'category_child_id' ] . $liClass . '"' . $liID . '>' ; $modMainMenuHTML .= ' . $aClass . ' href="' . $sess -> url ( URL. "index.php?page=shop.browse&category_id=" . $sorted_cats [ $n ] [ 'category_child_id' ] ) ; $modMainMenuHTML .= '" title="' . $catname . '">' ; $modMainMenuHTML .= $catname ; $modMainMenuHTML .= ps_product_category:: products_in_category ( $sorted_cats [ $n ] [ 'category_child_id' ] ) ; $modMainMenuHTML .= ' ' ; } if ( $sorted_cats [ $count - 1 ] [ 'cat_depth' ] > 0 ) { $modMainMenuHTML .= str_repeat ( "" , $sorted_cats [ $count - 1 ] [ 'cat_depth' ] ) ; } $modMainMenuHTML .= "" ; return $modMainMenuHTML ; } }
Wenn Ihnen dieser Beitrag geholfen und viel Zeit gespart hat, zeigen Sie sich erkenntlich: Über einen Klick auf Google+1 und Facebook-teilen oder Rückmeldungen freue ich mich. Zeigen Sie mir, dass sich die Mühe für die Beitragerstellung gelohnt hat.
Schenken Sie auch den Produktwerbungen Ihre Beachtung (Maus benutzen! ;-) ), denn damit wird mein Aufwand für diese Beiträge refinanziert.