alextn Posted April 20, 2019 Share Posted April 20, 2019 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 More sharing options...
tdsoft Posted April 22, 2019 Share Posted April 22, 2019 What is Text that you enterred it and get INVALID? Link to comment Share on other sites More sharing options...
alextn Posted April 22, 2019 Author Share Posted April 22, 2019 (edited) 42 minutes ago, tdsoft said: Any string that contains a letter, like 123a, 111a,12345b, and others. I tried to modify the rule and also to eliminate it but the result is always error. Some idea? Edited April 22, 2019 by alextn (see edit history) Link to comment Share on other sites More sharing options...
tdsoft Posted April 23, 2019 Share Posted April 23, 2019 you can learn more: https://www.php.net/manual/en/function.is-string.php Link to comment Share on other sites More sharing options...
day Posted April 23, 2019 Share Posted April 23, 2019 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 More sharing options...
alextn Posted April 23, 2019 Author Share Posted April 23, 2019 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 More sharing options...
alextn Posted April 23, 2019 Author Share Posted April 23, 2019 12 hours ago, tdsoft said: you can learn more: https://www.php.net/manual/en/function.is-string.php thanks, I looked at the manual but I can't understand. Perhaps something related to true or false? but I don't understand how to change the function. I am a beginner of php programming, I kindly ask you for concrete help. Link to comment Share on other sites More sharing options...
alextn Posted April 23, 2019 Author Share Posted April 23, 2019 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 More sharing options...
day Posted April 23, 2019 Share Posted April 23, 2019 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 Link to comment Share on other sites More sharing options...
alextn Posted April 23, 2019 Author Share Posted April 23, 2019 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 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? Link to comment Share on other sites More sharing options...
day Posted April 23, 2019 Share Posted April 23, 2019 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 More sharing options...
alextn Posted April 23, 2019 Author Share Posted April 23, 2019 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 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 More sharing options...
day Posted April 24, 2019 Share Posted April 24, 2019 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 1 Link to comment Share on other sites More sharing options...
alextn Posted April 24, 2019 Author Share Posted April 24, 2019 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 More sharing options...
Hsaneipour Posted January 9, 2021 Share Posted January 9, 2021 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now