TinoArts Posted August 6, 2020 Share Posted August 6, 2020 (edited) I need the product's EAN13 fields to be validated exactly as the "Reference" fields. First thing I've tried is changing the validate function and size from isEan13 to isReference in Product class: 'ean13' => array('type' => self::TYPE_STRING, 'validate' => 'isReference', 'size' => 64), It did not work. Then I've tried to change the isEan13() function return value to the same preg_match that isReference() has in Validate class, since isEan13 is being called from different files as well: public static function isEan13($ean13) { error_log('Validating EAN'); return !$ean13 || preg_match(Tools::cleanNonUnicodeSupport('/^[^<>;={}]*$/u'), $ean13); } I've actually even added an error_log debug output, which is not in the log at all, as if the function is not triggered at all. I've also reset the cache after each change. The result is always "This value is not valid." with 400 Bad Request. I double checked whether I am correctly editing default classes/overrides. I even tried to manually edit those classes in admin/autoupgrade/latest/classes folder, since they are there as well. What could be the issue? Edited August 6, 2020 by TinoArts typos (see edit history) Link to comment Share on other sites More sharing options...
TinoArts Posted August 11, 2020 Author Share Posted August 11, 2020 Bump Link to comment Share on other sites More sharing options...
TinoArts Posted August 20, 2020 Author Share Posted August 20, 2020 (edited) Bump. This really seems like a trivial thing, maybe I'm just missing something. Anyone can help? Edited August 20, 2020 by TinoArts (see edit history) Link to comment Share on other sites More sharing options...
elburgl69 Posted August 21, 2020 Share Posted August 21, 2020 (edited) When on V 1.7.x try manually deleting - app/cache/dev and/or; - app/cache/prod Edited August 21, 2020 by elburgl69 (see edit history) Link to comment Share on other sites More sharing options...
TinoArts Posted September 2, 2020 Author Share Posted September 2, 2020 You probably meant /var/cache/dev (or prod). I have tried deleting them but no luck. There must be something wrong with my code. Link to comment Share on other sites More sharing options...
TinoArts Posted March 24, 2021 Author Share Posted March 24, 2021 Solved finally. Turned out there were actually two rounds of validation. Validation is isEan13() function in Validate.php didn't even run until the first validation round is passed. The first validation is defined in src/PrestaShopBundle/Form/Admin/Product/ProductOptions.php. There, I needed to remove the 'constraints' argument for EAN13's field: ->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' => '', ]) After that, I could enter anything to the EAN13 field but it did go through validation defined in Validate.php. Since I wanted to be able to enter anything, simple is_string() works fine for me: public static function isEan13($ean13) { return is_string($ean13); } Works well now. 1 Link to comment Share on other sites More sharing options...
Enrique Gómez Posted May 5, 2023 Share Posted May 5, 2023 Same issue here, At least in the v2 product version for PS 8.1 there's the hookActionProductFormBuilderModifier to change this. But In previous version the only options is modify the core (as far as I know) 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