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

Subcategories: reference to parentid

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 02-25-2005, 04:19 PM
 
gbut gbut is offline
 

Newbie
  
Join Date: Feb 2005
Posts: 3
 

Default Subcategories: reference to parentid

Pardon my newbieness - just getting started w/x-cart...

I'm trying to do a conditional in customer/categories.tpl and need to detect current subcategory's parent id. I've seen references in the forums to $current_category.parentid but this isn't working for me (it's null).

Is there a mod I need to make to the query for $categories_data in include/categories.php to include the parent info? I don't see anything in there for parent.

Thanks!
__________________
------------------
~Gregg

X-Cart 4.0.12
Apache 1.3.33
mySQL 4.0.22
PHP 4.3.10
Reply With Quote
  #2  
Old 02-25-2005, 04:33 PM
  BCSE's Avatar 
BCSE BCSE is offline
 

X-Guru
  
Join Date: Apr 2003
Location: Ohio - bcsengineering.com
Posts: 3,091
 

Default

I think what you are reading is for 4.0.x In 3.x you will need to do some php manipulation to get the data you want. You'll need to parse the category name to find the parent category name, then get the category id from there.

For example if you have this category:
Quote:
Electronics/TV's/Plasma TV's
the parent category is:
Quote:
Electronics/TV's

To get that in php you'll need to use one (or more!) of the php string functions. Once you have the parent category name, you can select from the mysql the parent categoryid.

I hope that makes sense. I did some interesting parent category manipulation in this thread:
http://forum.x-cart.com/viewtopic.php?t=11857&postdays=0&postorder=asc&hig hlight=categories&start=15

Hope that helps you get started!

Carrie
__________________
Custom Development, Custom Coding and Pre-built modules for X-cart since 2002!

We support X-cart versions 3.x through 5.x!

Home of the famous Authorize.net DPM & CIM Modules, Reward Points Module, Point of Sale module, Speed Booster modules and more!


Over 200 X-cart Mods available & Thousands of Customizations Since 2002 - bcsengineering.com

Please E-Mail us for questions/support!
Reply With Quote
  #3  
Old 02-25-2005, 05:06 PM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default

Welcome Gregg. Please read the forum rules and descriptions prior to posting. I have deleted your other post in the Custom Mods section. That is for completed mods only, not questions. Also, please don't double post. Thanks!
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #4  
Old 02-28-2005, 04:45 PM
 
gbut gbut is offline
 

Newbie
  
Join Date: Feb 2005
Posts: 3
 

Default

Thanks folks. I've now ugraded to 4.0.12 so I can detect on
$current_category.parentid

Once detected though, I want to display the siblings - the parent category's children. In other words, subcats should display at both levels - standard expand/collapse behavior.

Whether in Animals section or Cats, display:
Code:
Animals Cats Dogs

When in parent (Animals) I can use:
{section name=subcat_num loop=$subcategories}

That works fine. I'm having trouble with displaying siblings. How do I reference the parent's subcategories?

This doesn't work:
{section name=subcat_num loop=$categories[cat_num].subcategories}
__________________
------------------
~Gregg

X-Cart 4.0.12
Apache 1.3.33
mySQL 4.0.22
PHP 4.3.10
Reply With Quote
  #5  
Old 02-28-2005, 05:57 PM
 
gbut gbut is offline
 

Newbie
  
Join Date: Feb 2005
Posts: 3
 

Default

I've got it worked out. Here's the code:

Code:
{section name=cat_num loop=$categories} <FONT class="CategoriesList">{$categories[cat_num].category}</FONT> {if $current_category.categoryid == $categories[cat_num].categoryid} {section name=subcat_num loop=$subcategories} <FONT class="CategoriesList"><span class="small">&gt; </span>{$subcategories[subcat_num].category}</FONT> {/section} {elseif $current_category.parentid == $categories[cat_num].categoryid} {section name=subcat_num loop=$allcategories} {if $allcategories[subcat_num].parentid eq $location[1].1|replace:"home.php?cat=":""} <FONT class="CategoriesList"><span class="small">&gt; </span>{ $allcategories[subcat_num].category|escape }</font> {/if} {/section} {/if} {/section}
__________________
------------------
~Gregg

X-Cart 4.0.12
Apache 1.3.33
mySQL 4.0.22
PHP 4.3.10
Reply With Quote
  #6  
Old 03-29-2005, 05:31 PM
 
PaulMc PaulMc is offline
 

Member
  
Join Date: Mar 2005
Posts: 10
 

Default keeping preset display order on subcats?

Thanks for sharing this solution! Question on the fragment below:
Quote:
Code:
{elseif $current_category.parentid == $categories[cat_num].categoryid} {section name=subcat_num loop=$allcategories} {if $allcategories[subcat_num].parentid eq $location[1].1|replace:"home.php?cat=":""} <FONT class="CategoriesList"><span class="small">&gt; </span>{ $allcategories[subcat_num].category|escape }</font> {/if} {/section} {/if}

Please excuse if the question's answer is obvious, but I can't determine why this bit causes display of the subcats in alphabetical order while viewing one of said subcats. Is there a modification which can be made to keep the subcats in preset order (as determined in the admin area)?

Thanks,

Paul
__________________
Paul Mc
4.0.12 Pro
Dedicated Linux Server
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



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 07:22 AM.

   

 
X-Cart forums © 2001-2020