Insert data into another table (Database)

  • Posts: 427
  • Thank you received: 19
5 years 3 months ago #309215

Hi, I want to ask if it is possible that when uploading a file, the data about it will also be imported into another table. I found this code but it does not work. Where am I wrong?

function onHikaBeforeFileSave(&$file, &$do) {
$do = true;
$file = new stdClass();
$file->file_path = 'myfilename.jpg';
$file->file_type = 'file';
$fileClass = hikashop_get('class.file');
$status = $fileClass->save($file);
}

function onHikaAfterFileSave(&$file) {
return onHikaBeforeFileSave($file, $do);
}

Last edit: 5 years 3 months ago by neo191987.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
5 years 3 months ago #309219

Hi,

How are you uploading your file ? The Joomla media manager ? The upload function in the HikaShop products ? A CSV import ? Custom upload fields ?

Regarding the upload function in the HikaShop products, there are no triggers for now. You would have to use onBeforeProductCreate and onBeforeProductUpdate or onAfterProductCreate and onAfterProductUpdate to look for them in hikashop_file and add the information in the table if not already there.

We'll add triggers to the file saving process with the next version as I think it's a good idea. We'll add the triggers onBeforeFileCreate onBeforeFileUpdate onAfterFileCreate and onAfterFileUpdate

The following user(s) said Thank You: neo191987

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

  • Posts: 427
  • Thank you received: 19
5 years 3 months ago #309226

Hi, I tried to trigger but still did not respond. I suppose that the product_quantity should be updated after save. Is there a plugin responsible for these actions and must be enabled? I tried a few things, but they did not work?

function onBeforeProductUpdate(&$element,&$do) {
$do = true;
$element->product_quantity = 10;
}

Last edit: 5 years 3 months ago by neo191987.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
5 years 3 months ago #309228

Hi,

I don't see why it wouldn't work.
Check that your plugin is installed and activated, and that you don't have a mass action on the product_quantity which could mess with this.

To check that your trigger is being called, set $do to false and save a product. If the save fails, it means that the code is being called.

The following user(s) said Thank You: neo191987

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

  • Posts: 427
  • Thank you received: 19
5 years 3 months ago #309376

Hi, I was able to do whatever I wanted :) I want to ask when are triggers (onBeforeFileCreate onBeforeFileUpdate onAfterFileCreate and onAfterFileUpdate) expected to be available? That's exactly what I need. With each successive version, it gets better and better. Well done to the team.

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

  • Posts: 1119
  • Thank you received: 114
5 years 3 months ago #309381

Hi,

You may want to update your Hikashop to 4.2.1 version. As log states it is already available:

[ www.hikashop.com/support/documentation/5...ashop-changelog.html

Thanks

The following user(s) said Thank You: nicolas, neo191987

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

  • Posts: 427
  • Thank you received: 19
5 years 3 months ago #309388

Hi, is it possible to add and onAfterFileDelete. I want to trigger some things after deleting. Is it possible at the moment?

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
5 years 3 months ago #309392

Hi,

You can add the code:

			JPluginHelper::importPlugin('hikashop');
			$app = JFactory::getApplication();
			$app->triggerEvent('onAfterFileDelete', array( &$pkeys, &$type ));
after :
			$translationHelper = hikashop_get('helper.translation');
			$translationHelper->deleteTranslations('file',$elements);
in the file administrator/components/com_hikashop/classes/file.php
We'll add that on our end too.

The following user(s) said Thank You: neo191987

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

  • Posts: 427
  • Thank you received: 19
5 years 3 months ago #309401

Hi, thank you. I have one last question on how to get information in this function. onAfterFileUpdate(&$file)

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

  • Posts: 12953
  • Thank you received: 1778
5 years 3 months ago #309405

Hello,

You should have every information you need through the $file variable, could you give us more information about the information you'll need ? Thank you.

Kind regards,
Mohamed Thelji

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

  • Posts: 427
  • Thank you received: 19
5 years 3 months ago #309434

Hi, I need file_id. But if I can get change even better. I tried through $file->file_id, but var_dump returns NULL.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
5 years 3 months ago #309482

We have high on our todo list to update the developer documentation to add all the new triggers missing, including this one.
This one is a simple one. It's just triggered when a file is being updated. It's triggered when you click on the "ok" button of the image / file edition popup of a product / category in the backend. I think you can do a var_dump of $file and then an exit in that function of your plugin to see the var_dump in the image edition popup after you click on that ok button.

Now, looking at the code of the "save" function in administrator/components/com_hikashop/classes/file.php I can see an issue with the code there.
The lines:
if(empty($new)) {
should actually be:
if($new) {
I think that's why you have that issue.

Last edit: 5 years 3 months ago by nicolas.
The following user(s) said Thank You: neo191987

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

  • Posts: 427
  • Thank you received: 19
5 years 3 months ago #310129

Hi, how can i get it file_id onAfterFileCreate(&$file), i got all the information through $file but without file_id.

To clarify exactly what needs to happen, I will write in detail. After uploading a file through Hikamarket (products - front end), information is sent to the trigger, which in turn creates a new row in the database.

Last edit: 5 years 2 months ago by neo191987.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
5 years 2 months ago #310145

Hi,

That's a good point. You can add the line:
$file->file_id = $status;
before the line:
$app->triggerEvent('onAfterFileCreate', array( &$file ));
in administrator/components/com_hikashop/classes/file.php so that you'll get the file_id in the trigger.
We'll do the change on our end too for the next version.

The following user(s) said Thank You: neo191987

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

  • Posts: 427
  • Thank you received: 19
5 years 2 months ago #310156

Thank you. Could you add in the next version and the trigger "FileDelete" ?

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
5 years 2 months ago #310157

Hi,

There's already a trigger after delete:
onAfterFileDelete( &$ids, &$type )
where $type is the type of file being deleted (category, file, watermark, image) and $ids a list of ids of files deleted.

The following user(s) said Thank You: neo191987

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

Time to create page: 0.101 seconds
Powered by Kunena Forum