Describe the bug
The hook actionProductAdd doesn't pass the param id_product_old when duplicate product.
It's necessary to have the old id when duplicating a product in order to also be able to clone the module data.
I know I could do an override, but this isn't the best solution.
To Reproduce
Steps to reproduce the behavior:
More info
(BOOM-4863) Duplicate product hook for modules - PrestaShop Issue Tracker
Additionnal information
PrestaShop version: 1.7.3.4
PHP version: 7.1
Hi @alejoasotelo,
Thanks for your report.
The solution That I posted in this comment:
http://forge.prestashop.com/browse/BOOM-4863?focusedCommentId=162626&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-162626 doesn't fix your issue?
Best regards, Khouloud
Hi @khouloudbelguith
Thanks for your help!
Yes, I read it.
I should not modifiy the core or create an override to get the old id. That is a temporary solution. We need a permanent solution.
The hook to duplicate product shold be include the id_product_old. What is the use of having the hook when a product is duplicated if the source product is not known?
Maybe 'actionProductAdd' should not include id_product_old, maybe PS needs a new hook called actionProductDuplicated o something like that.
Best!
Hi @eternoendless,
To include id_product_old in the list of params of the "hook actionProductAdd". We need to add this parameter actionProductAdd in the file "SHOP_FOLDER/src/Adapter/Product/AdminProductDataUpdater.php" and replace L215 by this :
$this->hookDispatcher->dispatchWithParameters('actionProductAdd', array('id_product' => (int)$product->id,'id_product_old'=>$id_product_old, 'product' => $product));
What do you think?
Thanks!
Best regards, Khouloud
Hi @alejoasotelo, @khouloudbelguith
you need to respect the best practice and not make changes directly in core files.
i suggest to use something like :
public function hookActionProductAdd($params)
{
/**
* @var $attribute Symfony\Component\HttpFoundation\ParameterBag
*/
$attribute = $params['request']->attributes;
$oldId = $attribute->get('id');
}
and after that you can use $oldId.
Thanks!
It seems that this commit solve the issue : https://github.com/PrestaShop/PrestaShop/commit/6655cab883dcec1cae6f2dd58087fae1fc7e268b#diff-31a3a3e02b67c2e9064868bd3841ceab
But this fix is not included in 1.7.5.1. Is it planned for the next release ?
hey @hamzanatek, @khouloudbelguith was talking to @eternoendless which is the lead dev of this project, so if even the Core team can't touch core files to add a feature, what can we do? :sob:
Yes indeed ! It should be great that every core team member mention it in their github profiles.
It's an open source project and for some we are also working on other projects.
And it's already defined :wink:
And @khouloudbelguith is in product team:
Thanks for the answer but I don't have the "Member of something" in any of your profiles. Maybe it's not a public information or I do I have to activate something in github ?
@jf-viguier im just giving the code that can be used before including the commit 6655cab in the Prestashop core. and in my point of view there's no need to make a change in the code because the old product ID exists in the request :)
and by the way im not a member of Prestashop core ;) I'm just trying to help
Thanks @hamzanatek!! I have applied your code and it works like a charm. And as you said you don't even need to reach to the core.
@hamzanatek the old id needs to be in the params because it is a hook for add/duplicated a product. It would be wrong if the hook that is executed when add or duplicate a product doesn't have the old id in the params.
i think so get it from the request it is just an alternative to solve the problem but the best way it is get it from the $params.
Best!
@matks Could you have a check on it, during the migration of the page, you can maybe add this?
Most helpful comment
hey @hamzanatek, @khouloudbelguith was talking to @eternoendless which is the lead dev of this project, so if even the Core team can't touch core files to add a feature, what can we do? :sob: