concretecms-community-store / community_store

An open, free and community developed eCommerce system for Concrete CMS
https://concretecms-community-store.github.io/community_store/
MIT License
106 stars 66 forks source link

'and' type filter attributes on product list regexp #718

Closed yildirimmurat closed 1 year ago

yildirimmurat commented 1 year ago

Hi there,

I am using community store inside my v9.1.3 concrete project and with php8.1. I added a product filter block and one of my filters should work like 'and' type. But the problem is whenever I select more than one checkbox inside this filter, I got error saying my query is wrong like "SQLSTATE[HY000]: General error: 3691 Mismatched parenthesis in regular expression.". So i tracked this error and on processUrlFilters() method of CommunityStore/Product/ProductList class I see the lline : $this->getQueryObject()->andWhere('ak_' . $handle . ' REGEXP :' .$paramname)->setParameter($paramname, "\(^|\n)" . preg_quote($searchterm) . "($|\n)");

Well, I dont understand completely what is happening behind but there is only one escape character before a opening parantheses.. So i solved my problem adding escape character for all opening and closing paranthesis characters..

Just curious if anybody also having problem with this.

Thanks

Mesuva commented 1 year ago

A client of mine showed this to me the other day, but I had trouble repeating it. I'm soon to do another burst of work on Community Store - I will take a look at this at the same time.

Mesuva commented 1 year ago

I've had trouble re-triggering this bug.

I'm wondering if it's a MySQL/MariaDB syntax thing.

I've trie changing the line you've mentioned to

$this->getQueryObject()->andWhere('ak_' . $handle . ' REGEXP :' .$paramname)->setParameter($paramname, "(^|\n)" . preg_quote($searchterm) . "($|\n)"); 

So I removed a backslash. Still works, which makes me think it was just ignoring slightly invalid syntax. Are you able to test my suggestion on your system?

yildirimmurat commented 1 year ago

hi @Mesuva when I delete only first escape character, I get wrong results: Then it just ignores the first parameters and only get result for the last category. So no 'and' functionality. It works perfectly when adding escape characters for each paranthesis. If it would help, I am working on

Server version: 8.0.32-0buntu0.20.04.1 - (Ubuntu) Server charset: UTF-8 Unicode (utf8mb4)

Mesuva commented 1 year ago

I've done a bit of digging into this, and found that the quotes on this have been creating different results across different databases (or maybe PHP versions). See my changes here: https://github.com/concretecms-community-store/community_store/commit/01cef391d34cba456f5368b12808cafaf87efe07#diff-75b84fc065a9b0519db02c3ea73533feb031576c96920161a47ad141586c6182

I'd be interested to see what results you get with those lines adjusted as per that commit

yildirimmurat commented 1 year ago

It works pretty well this way. Good idea to change the parameter name in each iteration, otherwise it would overwrite the previous ones. I think with this change the issue closes. Thanks.