В стародавние приснопамятные времена жил-был BMPE (русский Virtuemart 1.0.x), в котором присутствовал модуль «ВМРЕ — Основной модуль», содержащий кучу полезных фич. Одна из них — вывод в меню всех категорий Virtuemart вместе с их подкатегориями. Круто? Не то слово.
К сожалению, в стандартной поставке похожего модуля для Virtuemart 1.1.x такой возможности нет. По крайней мере, если выбрать «Category display type: Link List«.
Исправляем.За вывод категорий в этом модуле отвечает файл administrator\components\com_virtuemart\classes\ps_product_category.php, а в нем функция get_category_tree, которой передается $category_id из файла modules\mod_virtuemart\mod_virtuemart.php (строка echo $ps_product_category->get_category_tree( $category_id, $class_mainlevel );).
Таким образом, функция получает ID категории и открывает ее, если категория открыта. Но нам-то надо открыть ВСЕ категории…
Для этого берем код в строках 637-704 из файла СТАРОГО модуля и заменяем ими строки 663-731 в НОВОМ модуле, т.е. код в файле
administrator\components\com_virtuemart\classes\ps_product_category.php
// Copy the Array into an Array with auto_incrementing Indexes $key = array_keys($categories); // Array of category table primary keys $nrows = $size = sizeOf($key); // Category count $html = ""; // Find out if we have subcategories to display $allowed_subcategories = Array(); if( !empty( $categories[$category_id]["category_parent_id"] ) ) { // Find the Root Category of this category $root = $categories[$category_id]; $allowed_subcategories[] = $categories[$category_id]["category_parent_id"]; // Loop through the Tree up to the root while( !empty( $root["category_parent_id"] )) { $allowed_subcategories[] = $categories[$root["category_child_id"]]["category_child_id"]; $root = $categories[$root["category_parent_id"]]; } } // Fix the empty Array Fields if( $nrows < count( $row_list ) ) { $nrows = count( $row_list ); } // Now show the categories for($n = 0 ; $n < $nrows ; $n++) { if( !isset( $row_list[$n] ) || !isset( $category_tmp[$row_list[$n]]["category_child_id"] ) ) continue; if( $category_id == $category_tmp[$row_list[$n]]["category_child_id"] ) $style = $highlighted_style; else $style = ""; $allowed = false; if( $depth_list[$n] > 0 ) { // Subcategory! if( isset( $root ) && in_array( $category_tmp[$row_list[$n]]["category_child_id"], $allowed_subcategories ) || $category_tmp[$row_list[$n]]["category_parent_id"] == $category_id || $category_tmp[$row_list[$n]]["category_parent_id"] == @$categories[$category_id]["category_parent_id"]) { $allowed = true; } } else $allowed = true; $append = ""; if( $allowed ) { if( $style == $highlighted_style ) { $append = 'id="active_menu"'; } if( $depth_list[$n] > 0 ) { $css_class = "sublevel"; } else { $css_class = $links_css_class; } $catname = shopMakeHtmlSafe( $category_tmp[$row_list[$n]]["category_name"] ); $html .= ' <a title="'.$catname.'" style="display:block;'.$style.'" class="'. $css_class .'" href="'. $sess->url(URL."index.php?page=shop.browse&category_id=".$category_tmp[$row_list[$n]]["category_child_id"]) .'" '.$append.'>' . str_repeat(" ",$depth_list[$n]) . $catname . ps_product_category::products_in_category( $category_tmp[$row_list[$n]]["category_child_id"] ) .'</a>'; } } return $html;
удаляем и заменяем кодом:
/** SECOND STEP * Find out if we have subcategories to display **/ $allowed_subcategories = Array(); if( !empty( $categories[$category_id]["category_parent_id"] ) ) { // Find the Root Category of this category $root = $categories[$category_id]; $allowed_subcategories[] = $categories[$category_id]["category_parent_id"]; // Loop through the Tree up to the root while( !empty( $root["category_parent_id"] )) { $allowed_subcategories[] = $categories[$root["category_child_id"]]["category_child_id"]; $root = $categories[$root["category_parent_id"]]; } } // Fix the empty Array Fields if( $nrows < count( $row_list ) ) { $nrows = count( $row_list ); } $html = ''; // Now show the categories for($n = 0 ; $n < $nrows ; $n++) { if( !isset( $row_list[$n] ) || !isset( $category_tmp[$row_list[$n]]["category_child_id"] ) ) continue; if( $category_id == $category_tmp[$row_list[$n]]["category_child_id"] ) $style = $highlighted_style; else $style = ""; $allowed = true; if( $depth_list[$n] > 0 ) { // Subcategory! if( isset( $root ) && in_array( $category_tmp[$row_list[$n]]["category_child_id"], $allowed_subcategories ) || $category_tmp[$row_list[$n]]["category_parent_id"] == $category_id || $category_tmp[$row_list[$n]]["category_parent_id"] == @$categories[$category_id]["category_parent_id"]) { $allowed = true; } } else $allowed = true; $append = ""; if( $allowed ) { if( $style == $highlighted_style ) { $append = 'id="active_menu"'; } if( $depth_list[$n] > 0 ) $css_class = "sublevel"; else $css_class = $links_css_class; $catname = shopMakeHtmlSafe( $category_tmp[$row_list[$n]]["category_name"] ); if ($category_tmp[$row_list[$n]]["category_parent_id"]==4 || $category_tmp[$row_list[$n]]["category_parent_id"]==73 || $category_tmp[$row_list[$n]]["category_child_id"]==4 || $category_tmp[$row_list[$n]]["category_child_id"]==73) {$html.='<noindex>';} $html .= ' <a title="'.$catname.'" style="display:block;'.$style.'" class="'. $css_class .'" href="'. $sess->url(URL."index.php?page=shop.browse&category_id=".$category_tmp[$row_list[$n]]["category_child_id"]) .'" '.$append.'>' . str_repeat("",$depth_list[$n]) . $catname . ps_product_category::products_in_category( $category_tmp[$row_list[$n]]["category_child_id"] ) .'</a>'; if ($category_tmp[$row_list[$n]]["category_parent_id"]==4 || $category_tmp[$row_list[$n]]["category_parent_id"]==73 || $category_tmp[$row_list[$n]]["category_child_id"]==4 || $category_tmp[$row_list[$n]]["category_child_id"]==73) {$html.='</noindex>';} } } return $html;
Вот, собственно, и все…
Кстати, текущий активный пункт меню можно выделить в строке 653, заменив
$highlighted_style="font-style:italic;" ) {
на что-то свое, например
$highlighted_style="background:#90DCB3;color:#333333;font-weight:bold;" ) {
Уважаемый администратор, а подскажите плиззз:
То что написано в статье отлично, но боюсь пробовать… не знаю подходит мне это или нет.
Мой вопрос:
Как заставить модуль категорий показывать под-подкатегории. Делаю сайт экотоваров и замучился с этой проблемой (Адрес: три w точка maiya точка com.ua). Там меню категорий справа, показывает только саму категорию и подкатегорию, а мне нужен еще один уровень – по-подкатегория. Помогите… Заранее спасибо.
Забыл отметить, что у меня joomla 2.5.7, а Virtuemart 2.0.12b
Только начал писать про 1.1 ))
Какой у вас стоит модуль? Чем выводите меню?
Модуль по-моему стандартный? называется Virtuemart Category 2.0.0RC3. Меню сверху вывел вручную (через раздел меню в админпанели), не знаю как это сделать автоматически 🙁 Хелп ми плиззз.
Еще не знаю как привести в порядок вид буллитов — особенностей товара — http://maiya точка com.ua/features/mnogorazovye-eco-podguzniky/podguznik-vkladysh/mnogorazovyj-podguznik-nepromokajka-serii-premium-komplekt-detail (ссылку сокращу :)) Подскажите плиз какой файл за это отвечает.
Открою вам секрет 🙂 Если сделать копию файла, который собираетесь заменить, то даже если случайно напортачить — ничего не произойдет, всегда можно откатиться к старой версии 😉
Спасибо за секрет. Я никому не скажу 🙁 Я просто не уверен, что то что описано сверху именно то, что мне надо. поэтому пришлось написать в виде вопроса. Сорри, если туплю.
Чуть попозже посмотрю более пристально.