tep_get_category_tree() with spacing

Open to all! Ask other shopowners for help.
loop
Contributor
Posts: 253
Joined: Thu Mar 25, 2021 12:26 pm
Phoenix Version:
Has thanked: 7 times
Been thanked: 3 times

tep_get_category_tree() with spacing

Post 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?


Join The Code Co-op to get access to your library in the Code Co-op Forum
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: tep_get_category_tree() with spacing

Post 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', '&nbsp;&gt;&nbsp;'),
You do not have the required permissions to view the files attached to this post.
loop
Contributor
Posts: 253
Joined: Thu Mar 25, 2021 12:26 pm
Phoenix Version:
Has thanked: 7 times
Been thanked: 3 times

Re: tep_get_category_tree() with spacing

Post 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?
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: tep_get_category_tree() with spacing

Post 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&nbsp;&nbsp;&nbsp;");
        $entries = phoenix_build_product_entries($entries, $category_id, "$indent&nbsp;&nbsp;&nbsp;");
      }


      return $entries;
    }
LeeFoster
Contributor
Posts: 263
Joined: Sun Feb 28, 2021 9:41 pm
Phoenix Version: v1.0.8.20
Has thanked: 1 time
Been thanked: 5 times

Re: tep_get_category_tree() with spacing

Post 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.
loop
Contributor
Posts: 253
Joined: Thu Mar 25, 2021 12:26 pm
Phoenix Version:
Has thanked: 7 times
Been thanked: 3 times

Re: tep_get_category_tree() with spacing

Post 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...
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: tep_get_category_tree() with spacing

Post 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.
LeeFoster
Contributor
Posts: 263
Joined: Sun Feb 28, 2021 9:41 pm
Phoenix Version: v1.0.8.20
Has thanked: 1 time
Been thanked: 5 times

Re: tep_get_category_tree() with spacing

Post by LeeFoster »

ecartz wrote: Wed May 18, 2022 8:49 am Perhaps missing https://github.com/CE-PhoenixCart/Phoen ... 06785186fa which should have arrived in 1.0.8.3 if I'm reading it correctly.
I have both those files.
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: tep_get_category_tree() with spacing

Post 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.
LeeFoster
Contributor
Posts: 263
Joined: Sun Feb 28, 2021 9:41 pm
Phoenix Version: v1.0.8.20
Has thanked: 1 time
Been thanked: 5 times

Re: tep_get_category_tree() with spacing

Post 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.


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply