Hi,
You don't need to use it if the script inserting the data in the category table does it properly.
HikaShop itself doesn't rebuild the whole category tree each time you create or move a category via the interface.
This function is a band aid to fix the tree when it is corrupt because of some strange actions, mass actions, script imports, etc.
Basically, when you insert/move/remove categories on the category tree, you need to provide the category_id and the category_parent_id of the categories so that the system knows which category is child/parent of which one. But you also need to provide the category_left, category_right and category_depth which need to be calculated based on the position of the categories in the tree. And you also need to update these values in the other categories. These fields allow a fast loading of the category data but are complex to calculate from a third party script.
Which is why we provide that rebuild button so that HikaShop will recalculate all of them for you.
If you want to run that function from an external PHP script, you need to have three things in your script:
1. You need to load the Joomla framework of the website
stackoverflow.com/questions/23937651/loa...in-external-php-file
2. Load the HikaShop framework:
if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true;
3. Call the rebuild function:
$class = hikashop_get('class.category');
$database = JFactory::getDBO();
// Load the categories for the tree rebuild process
//
$query = 'SELECT category_left,category_right,category_depth,category_id,category_parent_id FROM #__hikashop_category ORDER BY category_left ASC';
$database->setQuery($query);
$root = null;
$categories = $database->loadObjectList();
$class->categories = array();
foreach($categories as $cat){
$class->categories[$cat->category_parent_id][]=$cat;
if(empty($cat->category_parent_id)){
$root = $cat;
}
}
// Reattach orphan categories to the root category
//
if(!empty($root)){
$query = 'UPDATE `#__hikashop_category` SET category_parent_id = '.(int)$root->category_id.' WHERE category_parent_id = 0 AND category_id != '.(int)$root->category_id.'';
$database->setQuery($query);
$database->query();
}
// Rebuild the category tree
//
$class->rebuildTree($root,0,1);
Then, you can call that external PHP script from your server's cron and off you go.