Right Way to retrieve a category Tree to put in my own made view

  • Posts: 636
  • Thank you received: 16
1 year 7 months ago #352623

-- HikaShop version -- : 4.7.3
-- Joomla version -- : 4.3.2
-- PHP version -- : 8.2.2

Many years ago we used o-tree when working with HikaMarket to build our custom views.

Nowadays we are building sites only with HikaShop.

We want to make a view in a self-made component that would show a Product Category Tree.

What would be the right, modern way to do this using the already created resources in HikaShop?

Thank you.

Please Log in or Create an account to join the conversation.

  • Posts: 83326
  • Thank you received: 13473
  • MODERATOR
1 year 7 months ago #352626

Hi,

We'll need to know more on the situation to be able to say what the best.
Is it on the frontend, or on the backend ?
Do you need it to be a selector of categories using the category tree, like for example in the "categories" setting of a coupon ?
Or do you need it to be only a list of categoy names, without links, with just some kind of identation made with HTML ?
Or something else ?

In HikaShop, we display the category tree when someone needs to select one or several categories for a restriction option. Having a similar selector elsewhere should be rather easy, especially in the backend. And we also display the category tree for the explorer on the left side of the categories / products listing in the backend. Again, having a similar display in the backend should not be a problem.
For other kind of display, I'm afraid you'll have to do the display on your end. You could probably use the getList method of class.category to load the data of the categories from the database. So it would help a bit.

Please Log in or Create an account to join the conversation.

  • Posts: 636
  • Thank you received: 16
1 year 7 months ago #352631

Hi Nicolas,

thanks for such a quick and extensive attention to our request. I'll try to be as specific as possible.

Main need is for frontend use, for a restricted number of admin users that need to do some stuff from the frontend.
Using in backend is convenient too, specially if it would be the same method.

We need a fully functional tree as when we edit products in backend.

One that unfolds subcategories, that can be default rendered with a certain number of sub-levels, that can trigger the load of its children products in another container / function,

No need to re-organize or delete categories from the same tree.

Any further orientation will be appreciated. In the meanwhile we'll check the getList method you suggest.

Best regards,

Peter

Please Log in or Create an account to join the conversation.

  • Posts: 83326
  • Thank you received: 13473
  • MODERATOR
1 year 7 months ago #352637

Hi,

I'm not sure what you mean by "We need a fully functional tree as when we edit products in backend.". Are you talking about a category selector like the "categories" setting when you edit a product ?
If it's this, you can use code like this:

		$this->nameboxType = hikashop_get('type.namebox');
		echo $this->nameboxType->display(
			'data[product][categories]',  // this is the name of the input which you'll be able to access in the $_POST
			$categories, // this is the value already selected
			hikashopNameboxType::NAMEBOX_MULTIPLE,
			'category',
			array(
				'delete' => true,
				'brand' => false,
				'sort' => true,
				'default_text' => '<em>'.JText::_('HIKA_NONE').'</em>',
				'tooltip' => true,
			)
		);
Or are you talking about the category explorer on the left side of the products listing ?
Displaying the explorer can be done with code like this:
$tree = hikashop_get('type.categorysub');
echo $tree->displayTree('product_listing', 0, array('product','vendor'), true, true, $currentCategoryId, $urlWhereToRedirect);
where $currentCategoryId is the id of the current category and $urlWhereToRedirect contains the URL where you want the explorer to go when a category is selected. It will add to it the parameter &filter_id=xxx where xxx is the id of the category selected.

Please Log in or Create an account to join the conversation.

  • Posts: 636
  • Thank you received: 16
1 year 7 months ago #352662

Thank you, Nicolas,

I believe both solutions are well-suited to our needs.

We'll be in touch should we need further assistance. We appreciate your guidance on these matters.

Best regards,

Peter.

Please Log in or Create an account to join the conversation.

Time to create page: 0.061 seconds
Powered by Kunena Forum