AbanteCart Community
Shopping Cart Operations => Support => Topic started by: toulip on November 29, 2020, 06:19:42 AM
-
Hello there :)
I have a product which need to have a value specified by the customer.
This value can be between -30 and 100.
I tried with a textarea and a regex /^-?[1-9]\d{0,2}$|^0$/
Everything works fine except for the value "0"
I also tried with an input instead of a textarea.
The regex is good, and not the problem. I think it comes from the way the script is written but I can't find it to edit it.
Is there someone here with a solution ?
Thank you and have a nice day !
-
hi.
Why do you use digits set [1-9] instead [0-9] ?
-
Hello, thank you for your reply
Because "-0" is not a valid value ^^
But as I said, I don't think it comes from the regex, I tried multiple regex and I have always the issue with 0.
In fact, if I don't set regex at all, but set the "required" field only I still can't enter the value "0" and all the other value work.
-
what about this pattern?
^(-?\d+\.)?-?\d+$
-
Still doesn't work unfortunately :/
As I mentionned in the previous post, if I simply don't put any regex and set "required field " to true, I stil can't enter "0"
By the way, I forgot to mention that the error message displayed when entering "0" is "error_required_options" and not the regex error message :/
This is not a regex issue, but a script issue I think
Tahnk you for your time :)
-
I think you need this ^-?[1-9]\d{0,2}$|^-0$
You can test your regex in here https://www.regexpal.com
-
Thank you for your answer. :)
"-0" is not a value I want to be correct
The value specified by the customer need to be between -30 and 100. "-0" does not exist.
So ^-?[1-9]\d{0,2}$|^0$ is correct as you can enter a negative value, 0 or something superior to 0 and 3 digit longs
The regex is not the issue. Do you know where I can find the script that handle the product option validation ? It certainly come from there :)
-
The regex is good, and not the problem. I think it comes from the way the script is written but I can't find it to edit it.
https://github.com/abantecart/abantecart-src/blob/master/public_html/storefront/model/catalog/product.php#L1344
-
Thank you very much !
Now that I had acces to the code it's fixed.
The product option check use the function empty() which consider the string "0" empty so it's not valid.
I fixed by editing line 1338
unfortunately I can't post my fix as the forum rules consider this a link....
But it is a simple check if option != 0 before the empty check