I'm trying to register hook actionProductAdd. In BO it shows that my module is transplanted in hook, but when I create a product, it does not trigger.
When I create a product, I should get a log that says 'hookActionProductAdd()' which indicates that my hook has been triggered.
Steps to reproduce the behavior:
public function hookActionProductAdd($params) {
Logger::addLog('hookActionProductAdd()', 1, null, null, null, true);
}
Thanks for opening this issue! We will help you to keep its state consistent
Hi @iibs,
I tried with ps_featuredproduct module

I tried to edit this line
From
$this->_clearCache('*');
To
$this->_clearCache('*')
When I try to save a product, I have this exception

Thanks to check and feedback.
I managed to get same error. I also tried to remove ; from my log, and then create product page crashed even before it rendered. However, I can't still get my log to show.
I also tried renaming my hook to hookAddProduct(), like in ps_featuredproduct, and replanting the module into hook, but it still does not log.
Ping @PrestaShop/prestashop-core-developers what do you think?
Thanks!
Hi @iibs
I tried this hook with the https://github.com/PrestaShop/ps_qualityassurance module, and indeed I don't see the actionProductAdd triggered, it does work with actionProductUpdate however.
I made some digging into this turns out actionProductAdd is not a generic hook used by all ObjectModels, it's a custom one and the only places I was able to find it were when we duplicate a product (both in legacy controller and migrated controller). So maybe the hook is not very well named but anyway that explains why it's not triggered
However you could try one of this two generic hooks
actionObjectProductAddBeforeactionObjectProductAddAfterI tested both of them and they work as expected.
However keep in mind that the product page has a special behaviour, when you click on "New Product" a "ghost" product is automatically and instantaneously created, however it is marked with a temporary state, it is only when you save the product the first time that the product will stop being a ghost/temporary product and will appear in the catalog (wether it's active or not).
So I don't know your use case, but it might not be the product addition hook that you will need, because when products are created from the BackOffice they are always empty shells. Although this might be more useful if it's added by an import, an external module or an API.
The hook is triggered when called, it's just the name is confusing so it's not called when you would expect to, it is only called when a product is duplicated. So I suggest to:
actionProductDuplicate and create an alias to the original actionProductAddIf this explanation is satisfactory for you we can either close this issue and open a new one to create the actionProductDuplicate or we can update this issue's description and purpose to manage this change.
By the way I forgot to mention when you duplicate the product (there's a button in the product page), you do see the log :)
Hi @jolelievre
So I don't know your use case, but it might not be the product addition hook that you will need
This is what I want to achieve:
I have already hooked into actionProductUpdate, but that does not trigger when product is saved for the first time. That's why I tried to explore different add hooks.
When I try to transplant hookActionObjectProductAddAfter, it's not shown on hook list, even though I have implemented it in code. I would prefer not to reset module, because I have additional tables and columns that include tons of information I don't want to lose.
Most helpful comment
Hi @iibs
I tried this hook with the https://github.com/PrestaShop/ps_qualityassurance module, and indeed I don't see the
actionProductAddtriggered, it does work withactionProductUpdatehowever.I made some digging into this turns out
actionProductAddis not a generic hook used by all ObjectModels, it's a custom one and the only places I was able to find it were when we duplicate a product (both in legacy controller and migrated controller). So maybe the hook is not very well named but anyway that explains why it's not triggeredHowever you could try one of this two generic hooks
actionObjectProductAddBeforeactionObjectProductAddAfterI tested both of them and they work as expected.
However keep in mind that the product page has a special behaviour, when you click on "New Product" a "ghost" product is automatically and instantaneously created, however it is marked with a temporary state, it is only when you save the product the first time that the product will stop being a ghost/temporary product and will appear in the catalog (wether it's active or not).
So I don't know your use case, but it might not be the product addition hook that you will need, because when products are created from the BackOffice they are always empty shells. Although this might be more useful if it's added by an import, an external module or an API.
TLDR
The hook is triggered when called, it's just the name is confusing so it's not called when you would expect to, it is only called when a product is duplicated. So I suggest to:
actionProductDuplicateand create an alias to the originalactionProductAddIf this explanation is satisfactory for you we can either close this issue and open a new one to create the
actionProductDuplicateor we can update this issue's description and purpose to manage this change.