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

Subcategory Mods on 4.2.0

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #11  
Old 03-25-2009, 07:45 PM
 
Tim CDN Tim CDN is offline
 

Advanced Member
  
Join Date: Mar 2009
Posts: 48
 

Default Re: Subcategory Mods on 4.2.0

Thanks, still working on it. Pretty confusing for a new programmer.
__________________
Gold 4.2.0
CDSEOPRO v.1.3.1
Advanced MiniCart
ezUpsell
One Page Checkout
Drug Test Kits
Reply With Quote
  #12  
Old 03-26-2009, 01:43 AM
  Victor D's Avatar 
Victor D Victor D is offline
 

X-Adept
  
Join Date: Aug 2008
Posts: 643
 

Default Re: Subcategory Mods on 4.2.0

Three different results can be achieved by following this mod.
What model you are trying to implement?

Real working horse for this mod is the .tpl and .php files modification
CSS is required to specify additional lookout

So if you don't see subcats try to execute cleanup.php on your store or clear templates cache in admin
If it won't improve situation you should revise changes you made to php and tpl one more time
__________________
Regards,
Victor Dubiniuk

X-Cart Skins Store
- twenty two different skins for 4.1.x and 4.2.x;
- 4.3.x compatible versions are available;
- refresh you store now!

Smart menu X-Cart add-on for 4.1.8 - 4.3.x
Featured Products Slide Show X-Cart add-on for 4.1.8 - 4.3.x
Reply With Quote
  #13  
Old 03-29-2009, 07:48 AM
 
user1 user1 is offline
 

Member
  
Join Date: Feb 2009
Posts: 29
 

Default Re: Subcategory Mods on 4.2.0

Hello there.

First of all I would like to thank Victor D and artmatt for their excellent work and support. I could use some help right now, since I don't have knowledge of html or css.

I want to use the first model that artmatt used in post #1. So I want my Categories panel to show a category's subcategories only when a customer clicks on that category and browses its products. (it's simple, don't you get it?)

I want to go a little bit further and move the subcategory's text and front icon a bit to the right. That way, it will be easier to distinguish the categories from subcategories. I even want to change the icon in front of subcategories.

So I used the following...


In file "include/categories.php" look for the following line: (taken from post #1)

Code:
if (!empty($subcategories)) {

and just before it add the following block of code: (taken from post #1)

Code:
function func_getallsubcat(){ $a =func_get_categories_list("", true, "all"); $b=$a['all_categories']; $c=array(); foreach ($b as $k=>$v){ if($v['parentid']!="0") $c[$v['parentid']][]=$v; } return $c; } $smarty->assign("allsubcategories", func_getallsubcat());

Open file "skin1/customer/categories.tpl"

Add {* at the start of the file and *} at the end of the file. You should have something like this:

Code:
{*blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah *}



Now, in the end of the file, after *} you must add: (taken from post #5)

Code:
{capture name=menu} {if $active_modules.Fancy_Categories} {include file="modules/Fancy_Categories/categories.tpl"} {assign var="additional_class" value="menu-fancy-categories-list"} {else} {assign var=thiscat value=$cat} {assign var=par value=0} {foreach from=$categories item=cats} {assign var=Mcatid value=$cats.categoryid} {foreach from=$allsubcategories.$Mcatid item=subb} {if $subb.categoryid eq $thiscat} {assign var=par value=$subb.parentid} {/if} {/foreach} {/foreach} <ul> {foreach from=$categories_menu_list item=c} <li><a href="home.php?cat={$c.categoryid}" title="{$c.category|escape}">{$c.category}</a></li> {if $c.categoryid eq $par} {foreach from=$allsubcategories.$par item=sub} {if $sub.parentid eq $c.categoryid} <li class="subcat"><a href="home.php?cat={$sub.categoryid}" class="subMenuItem">{$sub.category}</a></li> {/if} {/foreach} {/if} {foreach from=$allcategories item=cat} {if $cat.parentid eq $c.categoryid} <li class="subcat"><a href="home.php?cat={$cat.categoryid}" class="subMenuItem">{$cat.category}</a></li> {/if} {/foreach} {/foreach} </ul> {assign var="additional_class" value="menu-categories-list"} {/if} {/capture} {include file="customer/menu_dialog.tpl" title=$lng.lbl_categories content=$smarty.capture.menu}

And finally, at the end of file "skin1/main.css" add this:

Code:
.menu-categories-list ul li.subcat { margin-left: 11px; background: transparent url(images/category_bullet_invert.gif) no-repeat 8px 5px; }

Now I have a problem. I have one category :

Name (Position)
Category 1 (Pos. 10)

with four subcategories:

Name (Position)
Alpha (Pos. 10)
Gamma (Pos. 20)
Delta (Pos. 30)
Omega (Pos. 40)

When I click on Category 1 the subcategories appear in correct position order:
Alpha
Gamma
Delta
Omega

When I click on any subcategory the order changes, the subcategories appear in WRONG position order (the new order is alphabetical):
Alpha
Delta
Gamma
Omega

One way of bypassing this it is to assign position to subcategories alphabetically. But I don't like this way. Any idea how to fix this?

Best regards,
Andrew
__________________
x-cart v4.3.2 gold
http://www.FarMoreThanGames.com
Reply With Quote
  #14  
Old 03-30-2009, 12:18 AM
  Victor D's Avatar 
Victor D Victor D is offline
 

X-Adept
  
Join Date: Aug 2008
Posts: 643
 

Default Re: Subcategory Mods on 4.2.0

try to replace
Code:
function func_getallsubcat(){ $a =func_get_categories_list("", true, "all"); $b=$a['all_categories']; $c=array(); foreach ($b as $k=>$v){ if($v['parentid']!="0") $c[$v['parentid']][]=$v; } return $c; } $smarty->assign("allsubcategories", func_getallsubcat());

with
Code:
function func_getallsubcat(){ $a =func_get_categories_list("", true); $b=$a['all_categories']; $c=array(); foreach ($b as $k=>$v){ if($v['parentid']!="0") $c[$v['parentid']][]=$v; } return $c; } $smarty->assign("allsubcategories", func_getallsubcat());
__________________
Regards,
Victor Dubiniuk

X-Cart Skins Store
- twenty two different skins for 4.1.x and 4.2.x;
- 4.3.x compatible versions are available;
- refresh you store now!

Smart menu X-Cart add-on for 4.1.8 - 4.3.x
Featured Products Slide Show X-Cart add-on for 4.1.8 - 4.3.x
Reply With Quote
  #15  
Old 03-30-2009, 04:03 AM
 
user1 user1 is offline
 

Member
  
Join Date: Feb 2009
Posts: 29
 

Default Re: Subcategory Mods on 4.2.0

Quote:
Originally Posted by Victor D
try to replace
Code:
function func_getallsubcat(){ $a =func_get_categories_list("", true, "all"); $b=$a['all_categories']; $c=array(); foreach ($b as $k=>$v){ if($v['parentid']!="0") $c[$v['parentid']][]=$v; } return $c; } $smarty->assign("allsubcategories", func_getallsubcat());

with
Code:
function func_getallsubcat(){ $a =func_get_categories_list("", true); $b=$a['all_categories']; $c=array(); foreach ($b as $k=>$v){ if($v['parentid']!="0") $c[$v['parentid']][]=$v; } return $c; } $smarty->assign("allsubcategories", func_getallsubcat());

Thank you for your answer. Still, I get the same result with this change.

I cleaned up the templates' cache but same result.

You can see the problem in my shop.


Best regards,
Andrew
__________________
x-cart v4.3.2 gold
http://www.FarMoreThanGames.com
Reply With Quote
  #16  
Old 03-31-2009, 04:07 AM
  Victor D's Avatar 
Victor D Victor D is offline
 

X-Adept
  
Join Date: Aug 2008
Posts: 643
 

Default Re: Subcategory Mods on 4.2.0

finally find some time and get it( Sorting conditions implemented in x-cart by default is strange a bit so I have added resorting).
Code:
function func_getallsubcat(){ $a =func_get_categories_list(null, true,"all"); $b=$a['all_categories']; if (!function_exists("sort_cats")){ function sort_cats($a, $b) {return $a["order_by"]> $b["order_by"]; } } uasort($b, "sort_cats"); $c=array(); foreach ($b as $k=>$v){ if($v['parentid']!="0") $c[$v['parentid']][]=$v; } return $c; } $smarty->assign("allsubcategories", func_getallsubcat());
__________________
Regards,
Victor Dubiniuk

X-Cart Skins Store
- twenty two different skins for 4.1.x and 4.2.x;
- 4.3.x compatible versions are available;
- refresh you store now!

Smart menu X-Cart add-on for 4.1.8 - 4.3.x
Featured Products Slide Show X-Cart add-on for 4.1.8 - 4.3.x
Reply With Quote

The following user thanks Victor D for this useful post:
user1 (03-31-2009)
  #17  
Old 03-31-2009, 08:59 AM
 
user1 user1 is offline
 

Member
  
Join Date: Feb 2009
Posts: 29
 

Default Re: Subcategory Mods on 4.2.0

Quote:
Originally Posted by Victor D
finally find some time and get it( Sorting conditions implemented in x-cart by default is strange a bit so I have added resorting).
Code:
function func_getallsubcat(){ $a =func_get_categories_list(null, true,"all"); $b=$a['all_categories']; if (!function_exists("sort_cats")){ function sort_cats($a, $b) {return $a["order_by"]> $b["order_by"]; } } uasort($b, "sort_cats"); $c=array(); foreach ($b as $k=>$v){ if($v['parentid']!="0") $c[$v['parentid']][]=$v; } return $c; } $smarty->assign("allsubcategories", func_getallsubcat());

Excellent. Thank you very much.

To help newbies (like me) a little:

the above code goes in "include/categories.php" in the position described in post#13.

at the end of file "skin1/main.css" I added this:

Code:
.menu-categories-list ul li.subcat { margin-left: 11px; background: transparent url(images/category_bullet_invert.gif) no-repeat 8px 5px; }


"margin-left: 11px;" means that I move the subcategories beneath the category 11 pixels to the right. Change the number to move it left or right.

"background: transparent url(images/category_bullet_invert.gif) no-repeat 8px 5px;" with this line I changed the image (bold letters) in front of subcategories. To put your own image, put your image in folder "images" and change the image name above.

Thanks goes to everyone that helped.


Best regards,
Andrew
__________________
x-cart v4.3.2 gold
http://www.FarMoreThanGames.com
Reply With Quote
  #18  
Old 04-01-2009, 12:25 AM
 
benz benz is offline
 

Senior Member
  
Join Date: Oct 2007
Posts: 111
 

Default Re: Subcategory Mods on 4.2.0

To fix the order issue, can you not just change the line from:
PHP Code:
func_get_categories_list("",true,"all"); 
to
PHP Code:
func_get_categories_list("",true,"sub_orderby"); 

Or does this no longer work in 4.2
__________________
Version 4.1.8
Version 4.1.11
Reply With Quote
  #19  
Old 04-01-2009, 01:20 AM
  Victor D's Avatar 
Victor D Victor D is offline
 

X-Adept
  
Join Date: Aug 2008
Posts: 643
 

Default Re: Subcategory Mods on 4.2.0

There is no such flag in include/func/func_categories.php
I doesn't catch why sorting differs for the root and subcategory. When you browse to subcategory sorting order is changed from order_by to category_path for the same flag.
__________________
Regards,
Victor Dubiniuk

X-Cart Skins Store
- twenty two different skins for 4.1.x and 4.2.x;
- 4.3.x compatible versions are available;
- refresh you store now!

Smart menu X-Cart add-on for 4.1.8 - 4.3.x
Featured Products Slide Show X-Cart add-on for 4.1.8 - 4.3.x
Reply With Quote
  #20  
Old 04-01-2009, 02:58 PM
 
benz benz is offline
 

Senior Member
  
Join Date: Oct 2007
Posts: 111
 

Default Re: Subcategory Mods on 4.2.0

Apologies all, I'd forgotten that I added that flag myself ages ago.

In categories.php around line 68 you can make the following change.
(WARNING - only tested in Xcart 4.1.11)

PHP Code:
if ($current_area == "C" || $current_area == "B") {
        global 
$user_account;
        
$search_condition[] = "$sql_tbl[categories].avail='Y'";
        
$search_condition[] = "($sql_tbl[category_memberships].membershipid IS NULL OR $sql_tbl[category_memberships].membershipid = '$user_account[membershipid]')";
        if (
$flag == "all")
            
$sort_condition " ORDER BY category";
#Add this line
        
elseif ($flag == "sub_orderby")
            
$sort_condition " ORDER BY $sql_tbl[categories].order_by";
#end modification
        
else
$sort_condition " ORDER BY $sql_tbl[categories].order_by, category"

In Xcart4.1.11 you can also pass any non-null $flag string to this function call and it will do the same thing without this mod thanks to the last else clause,
eg if you call
$raj =func_get_categories_list("", true,"lorumipsum");
it still works thanks to the last else clause - the bug in the original is that it doesn't work if you leave out the flag parameter.
__________________
Version 4.1.8
Version 4.1.11
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 12:41 PM.

   

 
X-Cart forums © 2001-2020