Author Topic: [SOLVED] Product Option don't accept value "0"  (Read 291 times)

Offline toulip

  • Newbie
  • *
  • Posts: 7
  • Karma: +1/-0
    • View Profile
[SOLVED] Product Option don't accept value "0"
« 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 !
« Last Edit: November 30, 2020, 11:49:19 AM by toulip »

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1859
  • Karma: +281/-11
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Product Option don't accept value "0"
« Reply #1 on: November 30, 2020, 02:45:38 AM »
hi.
Why do you use digits set [1-9] instead [0-9] ?
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline toulip

  • Newbie
  • *
  • Posts: 7
  • Karma: +1/-0
    • View Profile
Re: Product Option don't accept value "0"
« Reply #2 on: November 30, 2020, 05:56:43 AM »
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.

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1859
  • Karma: +281/-11
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Product Option don't accept value "0"
« Reply #3 on: November 30, 2020, 06:28:42 AM »
what about this pattern?

^(-?\d+\.)?-?\d+$
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline toulip

  • Newbie
  • *
  • Posts: 7
  • Karma: +1/-0
    • View Profile
Re: Product Option don't accept value "0"
« Reply #4 on: November 30, 2020, 06:39:59 AM »
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 :)

Offline maxter

  • Full Member
  • ***
  • Posts: 182
  • Karma: +61/-0
    • View Profile
Re: Product Option don't accept value "0"
« Reply #5 on: November 30, 2020, 06:44:22 AM »
I think you need this ^-?[1-9]\d{0,2}$|^-0$

You can test your regex in here https://www.regexpal.com

Offline toulip

  • Newbie
  • *
  • Posts: 7
  • Karma: +1/-0
    • View Profile
Re: Product Option don't accept value "0"
« Reply #6 on: November 30, 2020, 07:50:08 AM »
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 :)



Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1859
  • Karma: +281/-11
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Product Option don't accept value "0"
« Reply #7 on: November 30, 2020, 09:46:26 AM »
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
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline toulip

  • Newbie
  • *
  • Posts: 7
  • Karma: +1/-0
    • View Profile
Re: [SOLVED] Product Option don't accept value "0"
« Reply #8 on: November 30, 2020, 11:52:53 AM »
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
« Last Edit: November 30, 2020, 12:01:56 PM by toulip »

 

Powered by SMFPacks Social Login Mod