Jump to content

afterSaveProduct and addproduct hook issue


quitequick

Recommended Posts

Prestashop version 1.4.8.2. I'm new to Prestashop development and I'm having difficulty with the afterSaveProduct hook.

 

I have written a module that uses the addproduct hook. It works as I expect. Unfortunately, this hook does not get called with the CSV Import (I have no idea why!). So I am now using the afterSaveProduct hook instead. I realise that $params are different for each hook (unfortunately).

 

However, when using the afterSaveProduct hook and calling Product::getCover($product->id); with a valid $product->id, I get nothing returned and no reported errors. With the addproduct hook, it returns what I expect - an image_id.

 

I have tried tracing the code but I am a noob to Prestashop I can not obviously see what is going wrong. My only guess is that the DB is not being initialised correctly - but that is just a guess.

 

Any ideas?

Link to comment
Share on other sites

Hi,

I was asleep, too many cookies you know.

 

For adminImport not hooking I tend to think that it is because, csv import is not a module (does not extends module class), and as hook depends on Module::hookExec.

 

For example Module::hookExec is triggered for watermark in adminImport but not for product update.

 

An override of a well choosen class or an override of adminimport could detect all products update.

Edited by math_php (see edit history)
Link to comment
Share on other sites

Thanks, Math - but I can detect the product updates with the afterSaveProduct hook just fine. The problem is that Product::getCover($product->id); returns nothing when I call it from within the afterSaveProduct hook. I need to update an external DB when a new product is added/updated, and that includes the image(s).

 

Thinking about it... has the image been added to the DB by the time the afterSaveProduct hook is called? Is this the issue?

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...