When using numeric references for products, while importing from CSV file, if in accessories column we put a list of numeric references, none of them is imported.
The problem is in classes/Product.php, method getExistingIdsFromIdsOrRefs
foreach ((is_array($ids_or_refs) ? $ids_or_refs : array($ids_or_refs)) as $id_or_ref) {
if (is_numeric($id_or_ref)) {
$ids[] = (int)$id_or_ref;
} elseif (is_string($id_or_ref)) {
$refs[] = '\''.pSQL($id_or_ref).'\'';
}
}
Because of this condition when reference is a numeric value, the method use it as an ID but in our case it is not one, so none of the reference are found in database.
This conditions should rely on the "Use reference as key" import parameter or use both conditions for all values whatever their type is, like bellow:
foreach ((is_array($ids_or_refs) ? $ids_or_refs : array($ids_or_refs)) as $id_or_ref) {
$ids[] = (int)$id_or_ref;
$refs[] = '\''.pSQL($id_or_ref).'\'';
}
To reproduce :
I'm using 1.7.4.2 but code is the same in the develop branch.
Create an import file with numeric references, and fill the accessories column, launch import
Expected behavior : product accessories are set
Result of the test : no accessories are set
Severity :
This is not critical because this method is easy to override but I think it is an issue because numeric references are valid and should be supported everywhere in the core.
Hi @jgtrescazes,
Could you please provide me your CSV file to test with it.
Thanks!
Hi @khouloudbelguith
I'm not allowed to give you the real file but you can reproduce the issue with this file : reproduce-issue-10824.zip (csv in zip)
Import config:
Separator=";"
Separator multiple values=","
Mapping:
Col1=Reference
Col2=Name
Col3=Accessories
After importing this none of the accessories are imported.
If you try with the fix I made in my previous comment, accessories are imported
Hi @jgtrescazes,
Thanks for this clarifications.
I manage to reproduce the issue described above.
In the Col3=Accessories: if we put a reference of the products as values => Accessories are not imported.
But in the Col3=Accessories: if we put ids of the products as values => Accessories are successfully imported.
PS: Use product reference as a key is enabled.
@marionf what do you think?
Hello @jgtrescazes
Thanks for diving into this!
Would you be willing to make a pull request on GitHub with your code suggestion?
https://github.com/PrestaShop/PrestaShop/tree/develop
Thank you!
@khouloudbelguith Could you try to reproduce it on 1.7.6.0 ?
Hi @marionf,
Yes, I manage to reproduce the issue with PS1.7.6.0beta1
https://drive.google.com/file/d/12QQYXSMju1u7MEigXcXa6PkgVROGML-T/view
Thanks!
Hi, I manage to reproduce this bug from PS 1.7.5.2 to 1.7.6.1.
@jgtrescazes: if you found a way to fix it, can you create a pull request? Thanks!
Hi, @khouloudbelguith and @marionf my PR is ready for your review.
https://github.com/PrestaShop/PrestaShop/pull/21406