Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Show sub-categories in 'Categories' menu-box

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #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
  #2  
Old 12-20-2006, 05:17 AM
 
alru111 alru111 is offline
 

eXpert
  
Join Date: Dec 2005
Posts: 244
 

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

good mod
Advice from a customer point of view. You might want to indent subcategory icons also or remove them altogether. Right now it's a long unreadable list and you can't say either it's cat or subcat.
__________________
X-Cart version 4.0.19
Reply With Quote
  #3  
Old 12-21-2006, 04:59 PM
 
sohaibkhan sohaibkhan is offline
 

Advanced Member
  
Join Date: Apr 2006
Posts: 78
 

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

hello,

i was unable to find

<tr style="CURSOR: pointer;" class="MenuItemOff" {if $js_enabled}onmouseover="ShowMenyItem(this,'On'); MM_swapImage('cat_img{$catid}','','{if $full_url}{$http_host}{$ImagesDir|replace:"..":""} {else}{$ImagesDir}{/if}/custom/cat_itemon{cycle name='on_images' values='8,1,2,3,4,5,6,7'}.gif',1)" onmouseout="ShowMenyItem(this,'Off'); MM_swapImgRestore()"{/if}>
<td><img src="{$ImagesDir}/spacer.gif" width="7" height="1" alt="" /></td>
<td height="17">&nbsp;&nbsp;<img id="cat_img{$catid}" src="{$ImagesDir}/custom/cat_item{cycle values="8,1,2,3,4,5,6,7"}.gif" alt="" class="CatImage" />&nbsp;&nbsp;<a href="home.php?cat={$catid}" class="CategoriesList">{$c.category}</a></td>
<td><img src="{$ImagesDir}/spacer.gif" width="10" height="1" alt="" /></td>
</tr>
{if not $smarty.foreach.cats.last}

in my categories.tpl
__________________
Current version: 4.1.5 Centos 4x
Reply With Quote
  #4  
Old 01-22-2007, 02:21 PM
 
Reed Reed is offline
 

Member
  
Join Date: Jan 2005
Posts: 13
 

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

I like this mod... but is there anyway to have only the subcategories shown for the current category you are in. So basically all the categories are shown and then the sub categories for the current category are located under the category name. Thanks for your help!
__________________
X-Cart Gold Version 4.1.5
Reply With Quote
  #5  
Old 02-05-2007, 09:04 AM
  jasonroy's Avatar 
jasonroy jasonroy is offline
 

Senior Member
  
Join Date: Sep 2006
Location: Tualatin, Oregon
Posts: 147
 

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

Quote:
Originally Posted by sohaibkhan
hello,

i was unable to find

Code:
<tr style="CURSOR: pointer;" class="MenuItemOff" {if $js_enabled}onmouseover="ShowMenyItem(this,'On'); MM_swapImage('cat_img{$catid}','','{if $full_url}{$http_host}{$ImagesDir|replace:"..":""}{else}{$ImagesDir}{/if}/custom/cat_itemon{cycle name='on_images' values='8,1,2,3,4,5,6,7'}.gif',1)" onmouseout="ShowMenyItem(this,'Off'); MM_swapImgRestore()"{/if}> <td><img src="{$ImagesDir}/spacer.gif" width="7" height="1" alt="" /></td> <td height="17">&nbsp;&nbsp;<img id="cat_img{$catid}" src="{$ImagesDir}/custom/cat_item{cycle values="8,1,2,3,4,5,6,7"}.gif" alt="" class="CatImage" />&nbsp;&nbsp;<a href="home.php?cat={$catid}" class="CategoriesList">{$c.category}</a></td> <td><img src="{$ImagesDir}/spacer.gif" width="10" height="1" alt="" /></td> </tr> {if not $smarty.foreach.cats.last}

in my categories.tpl

yeah, the original categories.tpl has nothing like this. He posted the original the same as the replace with. Instead, maybe you can post your entire categories.tpl
file?

I tinkered with it and never got it working
__________________
rjroffroad.com
x-cart 4.1.3
+ez checkout
+remember anonymous carts
Reply With Quote
  #6  
Old 12-05-2007, 12:08 AM
  ShishaPipeUK's Avatar 
ShishaPipeUK ShishaPipeUK is offline
 

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

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

Quote:
Originally Posted by jasonroy
yeah, the original categories.tpl has nothing like this. He posted the original the same as the replace with. Instead, maybe you can post your entire categories.tpl
file?

I tinkered with it and never got it working

Here is my full shopcart/skin1/customer/categories.tpl code

Code:
{* $Id: categories.tpl,v 1.26 2005/11/17 06:55:37 max Exp $ *} {capture name=menu} {if $active_modules.Fancy_Categories ne ""} {include file="modules/Fancy_Categories/categories.tpl"} {assign var="fc_cellpadding" value="0"} {else} <table cellpadding="0" cellspacing="0" width="100%"> {if $config.General.root_categories eq "Y"} {assign var="_categories" value=$categories} {else} {assign var="_categories" value=$subcategories} {/if} {foreach from=$_categories key=catid item=c name="cats"} <tr style="CURSOR: pointer;" class="MenuItemOff" {if $js_enabled}onmouseover="ShowMenyItem(this,'On'); MM_swapImage('cat_img{$catid}','','{if $full_url}{$http_host}{$ImagesDir|replace:"..":""}{else}{$ImagesDir}{/if}/custom/cat_itemon{cycle name='on_images' values='8,1,2,3,4,5,6,7'}.gif',1)" onmouseout="ShowMenyItem(this,'Off'); MM_swapImgRestore()"{/if}> <td><img src="{$ImagesDir}/spacer.gif" width="7" height="1" alt="" /></td> <td height="17" nowrap>&nbsp;&nbsp;<img id="cat_img{$catid}" src="{$ImagesDir}/custom/cat_item{cycle values="8,1,2,3,4,5,6,7"}.gif" alt="" class="CatImage" />&nbsp;&nbsp;<a href="home.php?cat={$catid}" class="CategoriesList"><FONT style='padding-left:{$c.indent}px;'>{$c.category}</FONT></a></td> <td><img src="{$ImagesDir}/spacer.gif" width="10" height="1" alt="" /></td> </tr> {if not $smarty.foreach.cats.last} <tr> <td><img src="{$ImagesDir}/spacer.gif" width="7" height="1" alt="" /></td> <td class="VertMenuLine"><img src="{$ImagesDir}/spacer.gif" width="1" height="1" alt="" /></td> <td><img src="{$ImagesDir}/spacer.gif" width="10" height="1" alt="" /></td> </tr> {/if} {/foreach} </table> {/if} <BR /><BR />{/capture} { include file="menu.tpl" dingbats="dingbats_categorie.gif" menu_title=$lng.lbl_categories menu_content=$smarty.capture.menu cellpadding=$fc_cellpadding menu_style="categories"}
__________________
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
  #7  
Old 12-28-2007, 10:03 PM
  divinechic's Avatar 
divinechic divinechic is offline
 

Advanced Member
  
Join Date: Dec 2007
Posts: 78
 

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

Will this mod work for version Gold 4.1.9?
__________________
X-Cart Gold version 4.1.9
Reply With Quote
  #8  
Old 01-02-2008, 05:46 PM
  ShishaPipeUK's Avatar 
ShishaPipeUK ShishaPipeUK is offline
 

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

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

Quote:
Originally Posted by divinechic
Will this mod work for version Gold 4.1.9?

I can't see why not, try it, just make sure you backup the files before you try the mod.
__________________
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
  #9  
Old 01-20-2008, 07:14 AM
  ShishaPipeUK's Avatar 
ShishaPipeUK ShishaPipeUK is offline
 

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

Smile Re: Show sub-categories in 'Categories' menu-box

Quote:
Originally Posted by jasonroy
yeah, the original categories.tpl has nothing like this. He posted the original the same as the replace with. Instead, maybe you can post your entire categories.tpl
file?

I tinkered with it and never got it working

I have highlited the new parts of the code in RED to make it easier to understand. The categories.tpl code shown before was using the Crystal blue skin.

You maybe able to follow this mod a bit better now.
__________________
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
  #10  
Old 03-22-2008, 04:17 PM
  MythNReality's Avatar 
MythNReality MythNReality is offline
 

X-Adept
  
Join Date: Mar 2005
Location: S. Cali
Posts: 403
 

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

I've tried but didn't work with the 4-1-9...anyone?
__________________
_____________
Capture Your Mini-Me Look!

- X-CART Gold (Current Version) V4.6
- Reboot
- CDSEO
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 03:44 PM.

   

 
X-Cart forums © 2001-2020