Set rebuild o run every 1 hour

  • Posts: 1057
  • Thank you received: 11
  • Hikashop Business
9 years 4 months ago #207595

Hi !
I just managed to assosiate with a company that sells commercial and accounting programs.
He is working on sql (windows server)
But he managed to create the correct scripts to drop his data on hikashop.
Now categories, products, discounts, images, and soon user and orders, are automatically inserted to hikashop, without any click from the clients part.
Hikashop is even more fantastic. With a greater value and prospects in bigger markets.
My question has to do with the rebuild function (in categories) . I read somewhere in the forum that people has used part of your code for their scripts and rebuilded the categories. But what if we have to run this script in sql server?
Thanks!

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

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
9 years 4 months ago #207621

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.

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

  • Posts: 1057
  • Thank you received: 11
  • Hikashop Business
9 years 4 months ago #207723

Is this the easiest way?
Is it possible to run a cpanel cron task on a url like acymailing does to trigger ?

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

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
9 years 4 months ago #207748

Hi,

There is already such cron task in HikaShop. But there is no link between the cron task system and that rebuild function.
having that link would require the development of a HikaShop plugin with a similar code as the one I provided.
So no, going through the cron task system of HikaShop won't be easier.
That's why I recommended an external script.

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

Time to create page: 0.061 seconds
Powered by Kunena Forum