Jump to content
thirty bees forum

trigger update/create product hook with an external script so modules know that products got created/updated


Beeta

Recommended Posts

Hello,

I use @datakickmodule to import/update products but it don't trigger any hook. It just import data in the db (in this way it's fast), but in this way 30bees modules/functions don't know that the data was imported/updated. The perfect solution would be if datakick module could trigger asynchronously the hook not impatcing the import speed. I think that @musicmaster's prestool behave the same.

But as I think that Petr doesn't have time to add this feature to his module I would like to try to trigger the update product hook by a bash/php script and running it with cron calling directly the hook or by 30bees' webservice. Do you know how to do it?

I read about it here but I don't know if it's what I'm searching for:
https://mypresta.eu/developer/execute-hooks-with-webservice.html

Basically I have a CSV/XML with a list of reference codes, and I think that I need to figure out the product id and then call the hook, I don't need to add data to the product as data is already imported/updated from datakick module operations. I simply need to say to 30bees that those product got created/updated.

@zenI know you have some crons that run to update products and other things (I read about it in the forum). Do you trigger "product update hook" during this external imports? Maybe this could be usefull to you too?

Edited by Beeta
Link to comment
Share on other sites

First, you need to know exactly what hooks you want to trigger. There are a lot of them, actually. For product modification, these can be called (and that's only a subset of them)

  • actionObjectAddBefore
  • actionObjectProductAddBefore
  • actionObjectAddAfter
  • actionObjectProductAddAfter
  • actionObjectUpdateBefore
  • actionObjectProductUpdateBefore
  • actionAdminUpdateAfter
  • actionObjectProductUpdateAfter
  • actionAdminProductControllerAddBefore
  • actionAdminAddBefore
  • actionAdminProductControllerUpdateBefore
  • actionAdminUpdateBefore
  • actionProductUpdate
  • ...

Once you know which hook(s) to trigger, you need to find the place in the core that is calling them, and figure out what parameters are send. Each hook sends different parameter.

For example, hookObjectProductUpdateAfter

https://github.com/thirtybees/thirtybees/blob/82b3102a421ce53347c4a660966048439e4f759b/classes/ObjectModel.php#L857-L858

Expects single parameter 'object' that is instance of Product class. You can trigger it as this one (for product 123):

Hook::exec('hookObjectProductUpdateAfter', ['object' => new Product(123)]);

Note that this can actually cause you more troubles. Modules can expect that the hooks are triggered in some sequence. For example, I have a module that create create audit logs of all changes. This module expects that first 'hookObjectProductUpdateBefore' is called -- at that point I retrieve data from database. Then when 'hookObjectProductUpdateAfter' is called, I once again retrieve data from db, and compare these two datasets to find out what has changed. 

If you just trigger hookObjectProductUpdateAfter, my module would be quite confused 🙂

And I'm sure there will be other modules that depends on things like these (sequence, context, controllers, GET / POST parameters, etc). So be aware 

Link to comment
Share on other sites

@Beeta This things are quite tricky. Are you an experienced dev? 

I don't know exactly, what you are trying to achieve. But if it's only about "involic prestabay". It could be easier to modify this module a very little. You could set up a little cronjob and search for new/modified products by date_add or date_upd. Then you trigger the module "involvic prestabay" hook function (but not the hook itself).

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...