Obtain Category path names

  • Posts: 79
  • Thank you received: 3
9 years 6 months ago #230850

-- HikaShop version -- : Business 2.6.0
-- Joomla version -- : 3.4.8
-- PHP version -- : 5.5.32

Hello.
I have a book store and I have a category tree with a maximun depth of 3 or 4 levels . And I need to store in a Custom field the gategory path names for a product in order to do a search filter:



As you can see if I have a product asigned to "Historia" category, I need to store "Materias;Humanidades;Historia" in my product Custom field in order to find this product if I use "Humanidades" search term.

What can I do to obtain this category path names?

Thank in advance.
Regards

Attachments:
Last edit: 9 years 6 months ago by pljuarez.

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

  • Posts: 13201
  • Thank you received: 2322
9 years 6 months ago #230870

Hi,

So you want a way to fill that custom field automatically, not manually, right ?

If it is, we don't have default options like that, it will require custom code.
Potentially create a custom mass action plugin to add the desired action to the products.

Here is the developer documentation for the developers:
www.hikashop.com/support/documentation/1...s-action-plugin.html

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

  • Posts: 79
  • Thank you received: 3
9 years 6 months ago #231228

Thanks Xavier for your comment, this remembered me a plugin I developed some months ago. I have modified it in order to do this operation.
Here is my solution.
My plugin is based on "onBeforeProductCreate" and "onBeforeProductUpdate" triggers. In its code, I have included a loop in order to concatenate category names:

$primer_ruta = true;
//Construct a new category object
$class = hikashop_get('class.category');
$cate = $class->get((string) $categoria);

//loop until reach the category_id I need or reach the root category
while (($cate->category_id != JText::_('CAT_MATERIAS')) && ($cate->category_id != JText::_('CAT_RAIZ'))){
	//Concatenate category name. If it isn't first name in path concatenate a semicolon as separator 
	if ($primer_ruta){
		$ruta=$cate->category_name.$ruta;
		$primer_ruta=false;
	}else{
		$ruta=$cate->category_name.'; '.$ruta;
	}

	//Up one level in categories tree
	$class = hikashop_get('class.category');
	$cate = $class->get((string) $cate->category_parent_id);
}

//When I reach root node then I store the category path in my custom field
if ($cate->category_id == JText::_('CAT_MATERIAS')){
	$productData->materias=$ruta;
}

Regards

The following user(s) said Thank You: Xavier

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

Time to create page: 0.075 seconds
Powered by Kunena Forum