Page 1 of 2
tep_get_category_tree() with spacing
Posted: Tue May 17, 2022 3:32 pm
by loop
Hi All
In categories.php (admin) i have the "goto" dropdown and every categories is below each other....
in earlier version of oscommerce i used the function tep_get_category_tree($parent_id = '0', $spacing = '', $exclude = '', $categories = []) with spacing = " > " for example and thenn the dropdown looks better as we see the structure.
in general.php i see that the spacing parameter is not used anymore as it's
Code: Select all
function tep_get_category_tree($parent_id = '0', $spacing = '', $exclude = '', $categories = []) {
$category_tree =& Guarantor::ensure_global('category_tree');
if ( (count($categories) < 1) && ($exclude !== '0') ) {
$categories[] = ['id' => '0', 'text' => TEXT_TOP];
}
return $category_tree->get_selections($categories, $parent_id);
}
is there a other way to have a nice "categorie dropdown"?
like
top
subcat1
subcat2
top2
subcat3
subsubcat4
like this?
Re: tep_get_category_tree() with spacing
Posted: Tue May 17, 2022 4:25 pm
by ecartz
The current behavior of not allowing the user to specify the indention has existed since the initial import from osCommerce, as seen at
https://github.com/CE-PhoenixCart/Phoen ... l.php#L190
You could of course make your own function and specify how to indent however you want. The indention is currently hardcoded at
https://github.com/CE-PhoenixCart/Phoen ... ee.php#L64
Or it looks like
tree_display->buildBranchArray could do that after specifying
the spacer_string and the spacer_multiplier. But I don't see any current examples in core or the supporters' code.
Note that the structure you say that you want is the default from that code. I.e. that code already produces an indented menu:
Screenshot_category_menu.png
If all you want to do is to add a level of indent so that Fruits and Vegetables are indented relative to Top, you could just call get_selections directly as at
https://github.com/CE-PhoenixCart/Phoen ... lt.php#L35 and put the prefix string as the third parameter. E.g.
Code: Select all
Guarantor::ensure_global('category_tree')->get_selections([['id' => '0', 'text' => TEXT_TOP]], '0', ' > '),
Re: tep_get_category_tree() with spacing
Posted: Wed May 18, 2022 6:45 am
by loop
i'm not sure now, the image with the apple / fruits is what i like in the categories.php (with more levels, but i'm not sure if the standard phoenix apple / fruit has more levels)
so i need in the goto dropdown:
Code: Select all
fruit
apple
green apple
red apple
orange
banana
vegetable
...
this is what i like (and had in oscommerce) in the goto dropdown
but in my categories.php i see:
fruit
apple
greenapple
red apple
orange
banana
do i have a bug in my categories.php and it should be standard as i need it?
Re: tep_get_category_tree() with spacing
Posted: Wed May 18, 2022 8:23 am
by ecartz
The normal menu is exactly as I showed:
1. No products.
2. Subcategories indented relative to their parents.
If you want products in your menu, you could make your own copy of get_selections and add products to it. Something like
Code: Select all
function phoenix_build_entries($entries = [], $parent_id = '0', $indent = '') {
if (!is_array($entries)) {
$entries = [];
}
foreach ($GLOBALS['category_tree']->get_children($parent_id) as $category_id) {
$entries[] = [
'id' => $category_id,
'text' => $indent . $GLOBALS['category_tree']->get($category_id, 'name'),
];
$entries = phoenix_build_entries($entries, $category_id, "$indent ");
$entries = phoenix_build_product_entries($entries, $category_id, "$indent ");
}
return $entries;
}
Re: tep_get_category_tree() with spacing
Posted: Wed May 18, 2022 8:30 am
by LeeFoster
ecartz wrote: ↑Wed May 18, 2022 8:23 am
The normal menu is exactly as I showed:
1. No products.
2. Subcategories indented relative to their parents.
I've just checked mine and I get no indentation either. Just a list of all of the categories. Installed Version: CE Phoenix v1.0.8.5 if that makes any difference.
Re: tep_get_category_tree() with spacing
Posted: Wed May 18, 2022 8:45 am
by loop
ah sorry, i don't want productcs in the structure
i want only categories, but as in your list i want categories shiffted...
Code: Select all
top
cat1
cat2
subcat1
subcat2
subcat3
only categories, but with spaces...
Re: tep_get_category_tree() with spacing
Posted: Wed May 18, 2022 8:49 am
by ecartz
Perhaps missing
https://github.com/CE-PhoenixCart/Phoen ... 06785186fa which should have arrived in 1.0.8.3 if I'm reading it correctly.
Re: tep_get_category_tree() with spacing
Posted: Wed May 18, 2022 9:27 am
by LeeFoster
Re: tep_get_category_tree() with spacing
Posted: Wed May 18, 2022 9:32 am
by ecartz
LeeFoster wrote: ↑Wed May 18, 2022 9:27 am
I have both those files.
Do you have the same version as shown after that change? As that change was specifically to add indent.
Re: tep_get_category_tree() with spacing
Posted: Wed May 18, 2022 9:38 am
by LeeFoster
ecartz wrote: ↑Wed May 18, 2022 9:32 am
LeeFoster wrote: ↑Wed May 18, 2022 9:27 am
I have both those files.
Do you have the same version as shown after that change? As that change was specifically to add indent.
Yes I do, I made sure to check that.
I've installed a fresh 1.0.8.14 version and that has the indent as has a clean 1.0.8.5 so something I've added or forgotten to remove must be messing with it.