Changing root category id

Open to all! Ask other shopowners for help.
Post Reply
radhavallabh
Senior Contributor
Posts: 466
Joined: Tue Oct 27, 2020 4:09 am
Phoenix Version: 1.1.0.6
Has thanked: 29 times
Been thanked: 3 times

Changing root category id

Post by radhavallabh »

Hi;
I am trying to make a category menu which takes the current category id as its root and displays its sub categories.
I duplicated the bm_categories.php module and tried assigning this to the global variable of $root_category_id

Code: Select all

$root_category_id= intval($GLOBALS['current_category_id']);
But still it does not change the root level of the category menu.

Can someone please help me achieve this;
Help shall be deeply appreciated dear;
Thank you in advance;
Warm Regds./
radhavallabh


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: Changing root category id

Post by ecartz »

If you go back to the original code in the execute method, change https://github.com/CE-PhoenixCart/Phoen ... es.php#L18

Code: Select all

      $display = new tree_display(Guarantor::ensure_global('category_tree'));
to

Code: Select all

      $category_tree = new category_tree();
      $category_tree->set_root_id((int)$GLOBALS['current_category_id']);
      $display = new tree_display($category_tree);
radhavallabh
Senior Contributor
Posts: 466
Joined: Tue Oct 27, 2020 4:09 am
Phoenix Version: 1.1.0.6
Has thanked: 29 times
Been thanked: 3 times

Re: Changing root category id

Post by radhavallabh »

ecartz wrote: Tue May 09, 2023 8:35 am If you go back to the original code in the execute method, change https://github.com/CE-PhoenixCart/Phoen ... es.php#L18

Code: Select all

      $display = new tree_display(Guarantor::ensure_global('category_tree'));
to

Code: Select all

      $category_tree = new category_tree();
      $category_tree->set_root_id((int)$GLOBALS['current_category_id']);
      $display = new tree_display($category_tree);

Worked like a charm dear!! Thank you so much!
radhavallabh
Senior Contributor
Posts: 466
Joined: Tue Oct 27, 2020 4:09 am
Phoenix Version: 1.1.0.6
Has thanked: 29 times
Been thanked: 3 times

Re: Changing root category id

Post by radhavallabh »

ecartz wrote: Tue May 09, 2023 8:35 am If you go back to the original code in the execute method, change https://github.com/CE-PhoenixCart/Phoen ... es.php#L18

Code: Select all

      $display = new tree_display(Guarantor::ensure_global('category_tree'));
to

Code: Select all

      $category_tree = new category_tree();
      $category_tree->set_root_id((int)$GLOBALS['current_category_id']);
      $display = new tree_display($category_tree);
Dear this helps change the root level of the category now
But it does not display the name of the category that has become the root itself now.

Like if root_category_id now becomes 25 instead of 0,
it shows the sub_categories example 25_34 , 25_36 under it, but does not display the name of root_category_id 25 itself also.

Any way to achieve that too??
Thank you in advance;
Very Warm Regds./
radhavallabh
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Changing root category id

Post by ecartz »

Edit the template to show the current category somewhere? E.g. at https://github.com/CE-PhoenixCart/Phoen ... es.php#L18


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