Jump to content

isEan13 function


alextn

Recommended Posts

Hi everyone, Prestashop 1.7. I need to modify for reasons I am not explaining the isEan13 function so that in the EAN 13 field letters and numbers can be entered without any control. I opened the classes / validate / validate.php file and modified the isEan13 function like this:


    public static function isEan13 ($ ean13)
    {
      return is_string ($ ean13);
    }


Entering numbers all ok, entering text letters, I always get the error This value is not valid. Any help please?  PS 
cash emptied
Link to comment
Share on other sites

I have created two new fields for storage and lost number

I also had the problem only with numbers for my new  fieldI have changed the following

 classes

Validate.php

public static function islosnr($los_nr)
    {
        
        return(is_string($los_nr) && preg_match(Tools::cleanNonUnicodeSupport('/^[~:#,$%&_=\(\)\.\? \+\-@\/a-zA-Z0-9\pL\pS-]*$/u'), $los_nr));
    }

     put on note

 /**

  public static function isEan13($ean13)
    {
        return !$ean13 || preg_match('/^[0-9]{0,13}$/', $ean13);
    }

*/

and test this

  public static function isEan13($ean13)

  {
        
        return(is_string($ean13) && preg_match(Tools::cleanNonUnicodeSupport('/^[~:#,$%&_=\(\)\.\? \+\-@\/a-zA-Z0-9\pL\pS-]*$/u'), $ean13);
    }

Maybe it works ???

 

juergen

 

Link to comment
Share on other sites

 public static function isEan13($ean13)

  {
        
        return(is_string($ean13) && preg_match(Tools::cleanNonUnicodeSupport('/^[~:#,$%&_=\(\)\.\? \+\-@\/a-zA-Z0-9\pL\pS-]*$/u'), $ean13);
    }

 

unfortunately it doesn't work, syntax error

Link to comment
Share on other sites

3 hours ago, day said:

I have created two new fields for storage and lost number

I also had the problem only with numbers for my new  fieldI have changed the following

 classes

Validate.php

public static function islosnr($los_nr)
    {
        
        return(is_string($los_nr) && preg_match(Tools::cleanNonUnicodeSupport('/^[~:#,$%&_=\(\)\.\? \+\-@\/a-zA-Z0-9\pL\pS-]*$/u'), $los_nr));
    }

     put on note

 /**

  public static function isEan13($ean13)
    {
        return !$ean13 || preg_match('/^[0-9]{0,13}$/', $ean13);
    }

*/

and test this

  public static function isEan13($ean13)

  {
        
        return(is_string($ean13) && preg_match(Tools::cleanNonUnicodeSupport('/^[~:#,$%&_=\(\)\.\? \+\-@\/a-zA-Z0-9\pL\pS-]*$/u'), $ean13);
    }

Maybe it works ???

 

juergen

 

ok, maybe this was the correct syntax but it still doesn't work. During the insertion of characters like a, b, c in the EAN13 field I always get an incorrect parameter error.

 

 

public static function isEan13($ean13)
    {
        return preg_match(Tools::cleanNonUnicodeSupport('/^[^<>;={}]*$/u'), $ean13);
    }

Link to comment
Share on other sites

ok, I've tested the following times

public static function isEan13($ean13)
    {
        return !$ean13 || preg_match('/^[~:#,$%&_=\(\)\.\? \+\-@\/a-zA-Z0-9\pL\pS-]*$/u', $ean13);
    }

 that works for me

ean13.png

Link to comment
Share on other sites

4 minutes ago, day said:

ok, I've tested the following times

public static function isEan13($ean13)
    {
        return !$ean13 || preg_match('/^[~:#,$%&_=\(\)\.\? \+\-@\/a-zA-Z0-9\pL\pS-]*$/u', $ean13);
    }

 that works for me

ean13.png

I confirm that it doesn't work for me. Do you confirm that the class in the Validate.php file should be replaced? in the path classes / Validate.php. I also tried to delete the Cache but nothing. Always error. Maybe I forget to do something?

desk.jpg

Link to comment
Share on other sites

I have just noticed that I have changed something more .....

I did that in the original shop that does not work either ????!!!!

I do not know right now where !

but I'm looking for something can take a while

 

sorry sorry

juergen

Link to comment
Share on other sites

31 minutes ago, day said:

ok, I've tested the following times

public static function isEan13($ean13)
    {
        return !$ean13 || preg_match('/^[~:#,$%&_=\(\)\.\? \+\-@\/a-zA-Z0-9\pL\pS-]*$/u', $ean13);
    }

 that works for me

ean13.png

 

 

ok, I'm waiting for other changes, please don't leave me ... I'm looking forward to it!

Link to comment
Share on other sites

I think I have found the offender

 ->add('ean13', FormType\TextType::class, array(
            'required' => false,
            'error_bubbling' => true,
            'label' => $this->translator->trans('EAN-13 or JAN barcode', [], 'Admin.Catalog.Feature'),
            'constraints' => array(
                new Assert\Regex("/^[0-9]{0,13}$/"),
            )
        ))

in  SRC/Form/Admin/Product/ProductOptions.php

change to this

  ->add('ean13', FormType\TextType::class, array(
            'required' => false,
            'error_bubbling' => true,
            'label' => $this->translator->trans('EAN-13 or JAN barcode', [], 'Admin.Catalog.Feature'),
            
            )
        )

and in

classes/Validate.php

change to this

 public static function isEan13($ean13)
    {
        return !$ean13 || preg_match('/^[~:#,$%&_=\(\)\.\? \+\-@\/a-zA-Z0-9\pL\pS-]*$/u', $ean13);
    }

 

if I set one of the two to original we only have numbers again

Juergen 

  • Like 1
Link to comment
Share on other sites

 

Thank you very much, you saved me

Solution:

//////////////////////////////////////////////////////////////////////

make the following changes

FILE: classes/Validate.php

public static function isEan13($ean13)
{
return !$ean13 || preg_match('/^[0-9]{0,13}$/', $ean13);
}

 

it becomes

public static function isEan13($ean13)
{
return !$ean13 || preg_match('/^[a-zA-Z0-9]{0,13}$/', $ean13);
}

//////////////////////////////////////////////////////////////////////


FILE: src\PrestaShopBundle\Form\Admin\Product/ProductOptions.php

  ->add('ean13', FormType\TextType::class, [
                'required' => false,
                'error_bubbling' => true,
                'label' => $this->translator->trans('EAN-13 or JAN barcode', [], 'Admin.Catalog.Feature'),
                'constraints' => [
                    new Assert\Regex('/^[0-9]{0,13}$/'),
                ],
                'empty_data' => '',
            ])

 

it becomes

  ->add('ean13', FormType\TextType::class, [
                'required' => false,
                'error_bubbling' => true,
                'label' => $this->translator->trans('EAN-13 or JAN barcode', [], 'Admin.Catalog.Feature'),
                'constraints' => [
                    new Assert\Regex('/^[a-zA-Z0-9]{0,13}$/'),
                ],
                'empty_data' => '',
            ])

//////////////////////////////////////////////////////////////////////

Link to comment
Share on other sites

  • 1 year later...
On 4/24/2019 at 3:16 PM, day said:

I think I have found the offender

 ->add('ean13', FormType\TextType::class, array(
            'required' => false,
            'error_bubbling' => true,
            'label' => $this->translator->trans('EAN-13 or JAN barcode', [], 'Admin.Catalog.Feature'),
            'constraints' => array(
                new Assert\Regex("/^[0-9]{0,13}$/"),
            )
        ))

in  SRC/Form/Admin/Product/ProductOptions.php

change to this

  ->add('ean13', FormType\TextType::class, array(
            'required' => false,
            'error_bubbling' => true,
            'label' => $this->translator->trans('EAN-13 or JAN barcode', [], 'Admin.Catalog.Feature'),
            
            )
        )

and in

classes/Validate.php

change to this

 public static function isEan13($ean13)
    {
        return !$ean13 || preg_match('/^[~:#,$%&_=\(\)\.\? \+\-@\/a-zA-Z0-9\pL\pS-]*$/u', $ean13);
    }

 

if I set one of the two to original we only have numbers again

Juergen 

Yes the only solution is above.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...