X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Find current subcategories siblings? (https://forum.x-cart.com/showthread.php?t=68129)

ScrapOrchard 11-11-2013 08:46 AM

Find current subcategories siblings?
 
Can someone point me in the right direction as to how to determine what the current subcategory's parent category is, so I can then get all the parent's subcategories?

Thanks!~

totaltec 11-11-2013 09:05 AM

Re: Find current subcategories siblings?
 
Look at the {$current_category} array. {$current_category.parentid} should contain the parent categoryid.

ScrapOrchard 11-11-2013 09:07 AM

Re: Find current subcategories siblings?
 
Thank you so much!

I was just coming back to post that I was able to locate the data I needed!

ScrapOrchard 11-13-2013 11:46 AM

Re: Find current subcategories siblings?
 
Ummm.. ok. So I haven't been able to figure out how or if the subcategory siblings data exists already.. somewhere. I want to provide a select menu which contains all the sibling subcategories, but on the subcategory pages.. I am able to locate the data if I am on the parent category page.

Am I going to need to make my own function to get this data?

If so, is there a tutorial or thread that explains the hierarchy (not sure this is the right word)?

From looking through the php files, I see the functions are in the /include/func files (duh) and I understand the root level php files passes values into Smarty, which is then used in the .tpl files... is it alright to call a function from the root php files or do I need another level in there?

ScrapOrchard 02-14-2015 06:54 AM

Re: Find current subcategories siblings?
 
I have made a little progress on this. But I am still not getting the data I need :(

I am not just familiar with how xCart works and how to store/access data.

Any help would be greatly appreciated.

And a very special thank you to cherie, for getting me this far. I did not want to keep bothering cherie, which is why I am posting in this thread.

To recap, I need to build an array, something like this where parentid:

PHP Code:

$subCats = array ( 
                  
"parentid"  => array (  
                                       
"subid" => "Category Name",  
                                       
"subid" => "Category Name",  
                                       
"subid" => "Category Name" 
                                       
), 
                  
"parentid"  => array (  
                                       
"subid" => "Category Name",  
                                       
"subid" => "Category Name",  
                                       
"subid" => "Category Name" 
                                       
), 
                  
"parentid"  => array (  
                                       
"subid" => "Category Name",  
                                       
"subid" => "Category Name",  
                                       
"subid" => "Category Name" 
                                       
), 
                  
"parentid"  => array (  
                                       
"subid" => "Category Name",  
                                       
"subid" => "Category Name",  
                                       
"subid" => "Category Name" 
                                       

                  ); 


The I need to retrieve and loop the array data based on $current_category.parentid.


What I current have, returns all the category names of all the subcategories but I can't figure out how to build the array correctly.


include/common.php
PHP Code:

$catResults "SELECT categoryid,category,parentid FROM $sql_tbl[categories] WHERE parentid!='0' AND avail='Y'";
$subCats func_query_hash($catResults,'parentid',false,true); 
$smarty->assign('subCats',$subCats); 


skin/<theme>/customer/main/subcategories.tpl
Code:

{foreach from=$subCats key=pid item=i}
{$pid}: {$i.category}
{/foreach}


cflsystems 02-17-2015 06:37 AM

Re: Find current subcategories siblings?
 
Why reinventing the wheel. If you are using the Flyout Menus module the categories array is already created. Just reuse it. I think it is called $categories_menu and subcategories for each category are under childs

ScrapOrchard 02-17-2015 03:01 PM

Re: Find current subcategories siblings?
 
And if I am not, can I still tap into those functions?

totaltec 02-17-2015 04:20 PM

Re: Find current subcategories siblings?
 
1 Attachment(s)
Quote:

Originally Posted by ScrapOrchard
And if I am not, can I still tap into those functions?

Certainly. I can understand why you might want your own control over this info.

Have you seen this webinar from Tony? http://kb.x-cart.com/pages/viewpage.action?pageId=7504837#Webinar2-10Apr2014-DesignchangesinX-Cart5(Custom...thmyownme nu?

It should get you familiar with overriding things.


Take a look at the attached file, it is my drop down menu module, rename the zip file to a tar, I just renamed it zip so I could upload.

cflsystems 02-17-2015 04:52 PM

Re: Find current subcategories siblings?
 
I believe this is for XC4 so the XC5 code won't work :)

If you are not using the Flyout Menus module you can still use its functions but you need to make your own calls to them to built the menu array

PhilJ 02-17-2015 05:18 PM

Re: Find current subcategories siblings?
 
(1) Uncheck General Settings > Appearance > "Always show root categories in the category list"

(2) Use...

Code:

<select onchange="window.location.href=this.value">
<option>{$lng.lbl_categories}...</option>
{foreach from=$categories_menu_list item=c name=categories}
<option value="home.php?cat={$c.categoryid}">{$c.category}</option>
{/foreach}
</select>


---
(1) May affect your main category menu though... It looks like yours is a custom menu, so you might get away with it.


All times are GMT -8. The time now is 11:07 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.