akeneo / pim-community-dev

[Community Development Repository] The open source Product Information Management (PIM)
http://www.akeneo.com
Other
951 stars 516 forks source link

Sku In list filter with hyphen #4630

Closed julienanquetil closed 8 years ago

julienanquetil commented 8 years ago

I try on several version of akeneo and also on the demo one If you have sku like 123456 and 789654 you can add it to in list filter on the grid view and you got results

but if you have (my case) sku like 123-456 and 789-654 you can add it to the "in list" in the grid view but you didn't have any result.

do you know why ? and how to fix it ?

Thanks

LaureBrosseau commented 8 years ago

Hello @julienanquetil,

It's a know bug, it has already been reported here: https://github.com/akeneo/pim-community-dev/issues/4435. We have created a ticket in our bug tracker under the reference PIM-5767.

I've noticed the an error on:

It happens on the PEF and on the Variant Group Edit Form. We did not investigate that further to define the origin of the bug. We'll keep you updated. Would you feel like contributing to fix this bug? If so, we'll be glad to help :)

Best regards,

Laure

julienanquetil commented 8 years ago

Thanks @LaureBro I didn't see there is already something... If i have time i will take a look (and try a PR) but not sure to have time in the comming week.

Thanks

Hocdoc commented 8 years ago

I also have some issues with String filters with hyphen in our code base.

I think the problem is in Pim\Bundle\FilterBundle\Filter\ProductValue\StringFilter.php: In prepareData() you escape the String value as a regex:

$data['value'] = preg_quote($data['value']);

A value like 123-456 will be 123\-456 after escaping. MySQL would then search with LIKE for 123\-456, but doesn't understand this backslash escaping.

Maybe you should use something like mysqli_real_escape_string instead of the preg_quote (but I don't know about the Mongo side).

julienanquetil commented 8 years ago

I know it's not the cleanest one but it's working on my side :

After the

$data['value'] = preg_quote($data['value']);;

I just add :

$data['value'] = str_replace('\-','-',$data['value']);

and now I can use the "in list with dash"

not sure if it will work for every one / config but fit my case :)

arnolanglade commented 8 years ago

@julienanquetil @Hocdoc Perhaps the better should be to fix how OroDatagridBundle create the query. Anyway, every contribution are very welcome. You can send a PR and we will be able to talk about it.

Hocdoc commented 8 years ago

I don't understand why the String value should get escaped with preg_quote?!

Perhaps the better should be to fix how OroDatagridBundle create the query.

As far as I can see, the query is always created in \Pim\Bundle\CatalogBundle\Doctrine\ORM\Filter\StringFilter.php in prepareCondition(). We could replace there the SQL LIKE with REGEXP, but it would be much slower. I think it would be better to escape just quotes instead of all possible regexp characters.

julienanquetil commented 8 years ago

@aRn0D your fix is very easy.... many thanks

LaureBrosseau commented 8 years ago

Hello @julienanquetil (and @Hocdoc again), we've fixed this bug in the 1.5 version :) it will be available in the next patch, we're planning to release it this week.

We'll keep you updated.

Best regards,

Laure

LaureBrosseau commented 8 years ago

Hello,

This issue has been fixed in the latest PIM version (1.5.8), it's working fine on the 1.6 too.

I'm closing this issue.

Regards,