View Single Post
  #1  
Old 11-23-2006, 10:48 AM
  ShishaPipeUK's Avatar 
ShishaPipeUK ShishaPipeUK is offline
 

Senior Member
  
Join Date: Jul 2005
Location: London, England.
Posts: 118
 

Default Show sub-categories in 'Categories' menu-box

This xcart 4.1.3 modification also alows you to change the settings in the admin area General Settings - Appearance options. ( A new section is added called "Categories" menu-box" )

2 files to change and also patch the sql.

include/categories.php
skin1/customer/categories.tpl

Apply the SQL changes (Open the Patch/Upgrade page in admin area and select the patch.sql from the archive for the "Apply SQL patch" section).

Code:
INSERT INTO xcart_config SET name='subcategories_indent', comment='Indent sub-categories from their parents', value='16', category='Appearance', orderby='3', type='text', defvalue='16', variants=''; INSERT INTO xcart_config SET name='subcategories_truncate', comment='Truncate after NN symbols in category name (leave empty to not truncate)', value='', category='Appearance', orderby='4', type='text', defvalue='', variants=''; INSERT INTO xcart_config SET name='sep200', comment='\"Categories\" menu-box', value='', category='Appearance', orderby='1', type='separator', defvalue='', variants=''; INSERT INTO xcart_config SET name='subcategories_depth', comment='Number of categories levels in \"Categories\" menu', value='2', category='Appearance', orderby='2', type='text', defvalue='3', variants=''; UPDATE xcart_config SET value='1164177468' WHERE name='data_cache_expiration'; INSERT INTO xcart_languages SET code='US', name='opt_sep200', value='\"Categories\" menu-box', topic='Labels';

Then change the skin1/customer/categories.tpl from: (You need to amend the second category which is the line that has home.php?cat={$catid} - add in <FONT style='padding-left:{$c.indent}px;'> before the {$c.category} - Dont forget to close the font command with </font>

Code:
<a href="home.php?cat={$catid}" class="CategoriesList">{$c.category}</a></td>


Replace with: (Items in RED is the extra code)

Code:
<a href="home.php?cat={$catid}" class="CategoriesList"> <FONT style='padding-left:{$c.indent}px;'>{$c.category}</FONT> </a></td>

Now to the include/categories.php there are 5 changes to this 4.1.3 xcart file

1st change - Find in include/categories.php

Code:
# # This function builds the categories list within specified category ($cat) # function func_get_categories_list($cat=0, $short_list=true, $flag=NULL) { global $current_area, $sql_tbl, $shop_language, $active_modules, $config, $xcart_dir;

Replace with: (You are adding in the extra command $with_subcategories=false ) (Items in RED is the extra code)

Code:
# # This function builds the categories list within specified category ($cat) # function func_get_categories_list($cat=0, $short_list=true, $flag=NULL, $with_subcategories=false) { global $current_area, $sql_tbl, $shop_language, $active_modules, $config, $xcart_dir;

2nd change - Find in include/categories.php

Code:
if (!is_array($_categories) || empty($_categories)) return array("all_categories" => array(), "categories" => array(), "subcategories" => array()); foreach ($_categories as $k => $category) { $category['categoryid'] = $_categories[$k]['categoryid'] = $k; # # Get the full path for category name #

Replace with: (Items in RED is the extra code)

Code:
if (!is_array($_categories) || empty($_categories)) return array("all_categories" => array(), "categories" => array(), "subcategories" => array()); $first_depth = 0; foreach ($_categories as $k => $category) { $category['categoryid'] = $_categories[$k]['categoryid'] = $k; if ($with_subcategories && !empty($config['Appearance']['subcategories_truncate'])) if (strlen($category['category']) > $config['Appearance']['subcategories_truncate']) $category['category'] = substr($category['category'],0,$config['Appearance']['subcategories_truncate']) . '...'; # # Get the full path for category name #

3rd change - Find in include/categories.php

Code:
if ($flag == "all" || is_null($flag)) { $path = explode("/", $category["categoryid_path"]); $category_path = array(); foreach ($path as $catid) { if (empty($_categories[$catid])) break; $category_path[] = $_categories[$catid]['category']; } if (count($category_path) != count($path)) continue; $category["category_path"] = implode("/",$category_path); unset($category_path);


Replace with (Items in RED is the extra code)

Code:
if ($flag == "all" || is_null($flag) || $current_area == 'C' || $with_subcategories == true) { $path = explode("/", $category["categoryid_path"]); $category_path = array(); foreach ($path as $catid) { if (empty($_categories[$catid])) break; $category_path[] = $_categories[$catid]['category']; } if (count($category_path) != count($path)) continue; $category["depth"] = count($path) - $first_depth ; if ($category['depth'] < 0) $category['depth'] = 0; $category['indent'] = $category['depth'] ? ($category['depth'] -1 ) * $config['Appearance']['subcategories_indent'] : 0; $category['sortorder'] = array(); foreach ($path as $catid) { $category['sortorder'][] = $_categories[$catid]['order_by']; } $category["category_path"] = implode("/",$category_path); unset($category_path);

4th change - Find in include/categories.php

Code:
if (($flag == "root" || $flag == "current" || is_null($flag)) && $category["parentid"] == 0) $categories[$k] = $category; if (($flag == "level" || $flag == "current" || is_null($flag)) && $category["parentid"] == $cat) $subcategories[$k] = $category; } unset($_categories); if (($flag == "all" || is_null($flag)) && !empty($all_categories) && (($current_area != "C" && $current_area != "B") || empty($active_modules["Fancy_Categories"]))) { if (!function_exists("func_categories_sort")) { function func_categories_sort($a, $b) { return strcmp($a["category_path"], $b["category_path"]); } } uasort($all_categories, "func_categories_sort"); } return array("all_categories" => $all_categories, "categories" => $categories, "subcategories" => $subcategories); } # # This function gathering the current category data #


Replace with: (Items in RED is the extra code)

Code:
if (($flag == "root" || $flag == "current" || is_null($flag)) && $category["parentid"] == 0) $categories[$k] = $category; if (($flag == "level" || $flag == "current" || is_null($flag)) && $category["parentid"] == $cat) $subcategories[$k] = $category; if ($current_area == 'C' && $category['depth'] > 0 && $with_subcategories && $category['depth'] <= $config['Appearance']['subcategories_depth']) { $categories[$k] = $category; } } unset($_categories); # # Sorting categories # if ($with_subcategories) { function _compare_order_by($a,$b) { $min = min ( count($a['sortorder']), count($b['sortorder'])); for ($i=0; $i<$min; $i++) { if ($a['sortorder'][$i] != $b['sortorder'][$i]) return $a['sortorder'][$i] > $b['sortorder'][$i] ? 1 : -1; } if (count($a['sortorder']) != count($b['sortorder'])) return count($a['sortorder']) > count($b['sortorder']) ? 1 : -1; if ($a['category'] != $b['category']) return $a['category'] > $b['category'] ? 1 : -1; return 0; } uasort($categories,"_compare_order_by"); } if (($flag == "all" || is_null($flag)) && !empty($all_categories) && (($current_area != "C" && $current_area != "B") || empty($active_modules["Fancy_Categories"]))) { if (!function_exists("func_categories_sort")) { function func_categories_sort($a, $b) { return strcmp($a["category_path"], $b["category_path"]); } } uasort($all_categories, "func_categories_sort"); } return array("all_categories" => $all_categories, "categories" => $categories, "subcategories" => $subcategories); } # # This function gathering the current category data #

5th change - Find in include/categories.php

Code:
if (($current_area == "C" && defined("GET_ALL_CATEGORIES")) || defined('MANAGE_CATEGORIES')) { $_categories = func_get_categories_list($cat);

Replace with: (Items in RED is the extra code)

Code:
if (($current_area == "C" && defined("GET_ALL_CATEGORIES")) || defined('MANAGE_CATEGORIES')) { $_categories = func_get_categories_list($cat, true, NULL, true);
__________________
Apache/2.0.55 (Red Hat) & MYSQL Server: 5.0.24
PERL: 5.008005 / PHP: 4.4.4 - 4.3.1 X-CART

Shop carts at
http://www.nightscene.co.uk/shop/home.php
http://www.theshisha.net/shopcart/home.php
http://www.system-maintenance.com/maint/home.php
http://www.tabac4u.com
Reply With Quote