kokosmin Posted October 3, 2014 Share Posted October 3, 2014 I introduced about 60 of my products with about 7000 variations in total. Up until now all the supplier product codes had 7 numbers. But now, there are products with 5 numbers and 2 letters. I put them always in the UPC code input area. As you know, UPC does not validate letters. What can I do to make UPC validate my new product codes? I don't want to change the 7000 I already inputed to EAN-13 or something else, as this will be very time consuming. I need the UPC field because one of my modules reads the code and displays the supplier's stock. Link to comment Share on other sites More sharing options...
kokosmin Posted October 11, 2014 Author Share Posted October 11, 2014 So.. is this impossible to do? Link to comment Share on other sites More sharing options...
PascalVG Posted October 12, 2014 Share Posted October 12, 2014 For this you probably have to edit /classes/Validate.php (Make backup!!!!!) Find function: /** * Check for barcode validity (UPC) * * @param string $upc Barcode to validate * @return boolean Validity is ok or not */ public static function isUpc($upc) { return !$upc || preg_match('/^[0-9]{0,12}$/', $upc); } And change the preg_match to something like this: return !$upc || preg_match('/^[0-9A-Z]{0,12}$/', $upc); This will allow anything from 0-12 characters of any number and letter combination, like 1A3, 134D, 1456743, ADFHERWEDE, AD4EDF89ED, A, 4, etc. or, if you want exactly 7 characters (little extra check of correctly entered) return !$upc || preg_match('/^[0-9A-Z]{7}$/', $upc); You could make it more stringent, like ONLY 7 numbers or ONLY 5 Numbers+2Letters, but as it looks like you add them only yourself, this seems overkill. Hope this helps, pascal 1 Link to comment Share on other sites More sharing options...
kokosmin Posted October 12, 2014 Author Share Posted October 12, 2014 This is so simple when you know what you're doing. THANK YOU! The solution works, UPC field validates. There's no need to overcomplicate with the other restrictions, but it's good you put the example, because someone else's project might need it. Link to comment Share on other sites More sharing options...
StavrosL Posted October 31, 2014 Share Posted October 31, 2014 Hello, I have the same thing with EAN 13. I want to use it as product part number. What I must change in order to accept letters (Greek and English) numbers, dashes (-) and dots(.) and space betewwn letters? Thank you very much! Stavros 1 Link to comment Share on other sites More sharing options...
intermediadorpopular Posted December 27, 2015 Share Posted December 27, 2015 I also want to know... Link to comment Share on other sites More sharing options...
intermediadorpopular Posted December 27, 2015 Share Posted December 27, 2015 I also want to know... Link to comment Share on other sites More sharing options...
www.bio-krby-kamna.cz Posted February 26, 2018 Share Posted February 26, 2018 For example : Chance length UPC code to 64 and add symbols 1. In database change length UPC field to 64 ( ps_product UPC field varchar 12 => 64) 2. /classes/Validate.php - return !$upc || preg_match('/^[0-9]{0,12}$/', $upc); + return !$upc || preg_match('/^[0-9a-zA-Z]{0,64}$/', $upc); 3. /classes/Product.php - 'upc' => array('type' => self::TYPE_STRING, 'validate' => 'isUpc', 'size' => 12), + 'upc' => array('type' => self::TYPE_STRING, 'validate' => 'isUpc', 'size' => 64), 4. /www/admin/themes/default/template/controllers/products/informations.tpl - <input maxlength="12" type="text" id="upc" name="upc" value="{$product->upc|escape:html:'UTF-8'}" /> + <input maxlength="64" type="text" id="upc" name="upc" value="{$product->upc|escape:html:'UTF-8'}" /> Link to comment Share on other sites More sharing options...
DOKI4ever Posted April 24, 2018 Share Posted April 24, 2018 (edited) On 10/31/2014 at 2:13 PM, StavrosL said: Hello, I have the same thing with EAN 13. I want to use it as product part number. What I must change in order to accept letters (Greek and English) numbers, dashes (-) and dots(.) and space betewwn letters? Thank you very much! Stavros Hello, I have the same problem, did anyone solve it? Y tried to change the Validate.php, but not all the codes get saved. Edited April 24, 2018 by DOKI4ever (see edit history) Link to comment Share on other sites More sharing options...
jeromecollection Posted July 12, 2019 Share Posted July 12, 2019 (edited) Le 24/04/2018 à 1:51 PM, DOKI4ever a dit : Hello, I have the same problem, did anyone solve it? Y tried to change the Validate.php, but not all the codes get saved. works for me for space and special characters add in this code each characters you want to allow with \ example you want allow ( put \( like /classes/Validate.php return !$upc || preg_match('/^[a-zA-Z 0-9-\(\)-]{0,64}$/', $upc); /www/admin/themes/default/template/controllers/products/informations.tpl <input maxlength="64" type="text" id="upc" name="upc" value="{$product->upc|escape:'html':'UTF-8'}" /> /public_html/themes/default-bootstrap/product.tpl insert wher your want to see UPC <div id="product_upc"{if empty($product->upc) || !$product->upc} style="display: none;"{/if}> <label> <i class="fas fa-industry" aria-hidden="true"></I> {l s='UPC:'} </label> <span class="editable" itemprop="upc"{if !empty($product->upc) && $product->upc} content="{$product->upc}"{/if}>{if !isset($groups)}{$product->upc|escape:'html':'UTF-8'}{/if}</span> Edited July 12, 2019 by jeromecollection (see edit history) Link to comment Share on other sites More sharing options...
richo Posted October 6, 2019 Share Posted October 6, 2019 hello I would like to remove the validation of the UPC field of a shop Prestashop1.7 can you tell me what are the files to edit? Thank you Link to comment Share on other sites More sharing options...
giraldillo Posted January 17, 2020 Share Posted January 17, 2020 On 10/6/2019 at 12:34 PM, richo said: hello I would like to remove the validation of the UPC field of a shop Prestashop1.7 can you tell me what are the files to edit? Thank you I'm interested on it too. Could you help us? Regards Link to comment Share on other sites More sharing options...
Prestag0od Posted February 8, 2021 Share Posted February 8, 2021 On 10/6/2019 at 1:34 PM, richo said: hello I would like to remove the validation of the UPC field of a shop Prestashop1.7 can you tell me what are the files to edit? Thank you On 1/17/2020 at 6:09 PM, giraldillo said: I'm interested on it too. Could you help us? Regards src/PrestaShopBundle/Form/Admin/Product ->add('upc', FormType\TextType::class, [ 'required' => false, 'label' => $this->translator->trans('UPC barcode', [], 'Admin.Catalog.Feature'), 'constraints' => [ <!-- new Assert\Regex('/^[0-9]{0,12}$/'), --> new Assert\Regex('/^[a-zA-Z 0-9]{0,64}$/'), ], 'empty_data' => '', src/PrestaShopBundle/Form/Admin/Product ->add('upc', FormType\TextType::class, [ 'required' => false, 'label' => $this->translator->trans('UPC barcode', [], 'Admin.Catalog.Feature'), 'constraints' => [ <!-- new Assert\Regex('/^[0-9]{0,12}$/'), --> new Assert\Regex('/^[a-zA-Z 0-9]{0,64}$/'), ], 'empty_data' => '', and classes/Validate.php public static function isUpc($upc) { <-- return !$upc || preg_match('/^[0-9]{0,12}$/', $upc); --> return !$upc || preg_match('/^[a-zA-Z 0-9-\(\)-]{0,64}$/', $upc); } Link to comment Share on other sites More sharing options...
MURAT ONUR YUKSEL Posted May 20, 2023 Share Posted May 20, 2023 To rename the references You can change below script in product-details.tpl to separately rename the references. {* if product have specific references, a table will be added to product details section *} {block name='product_specific_references'} {if !empty($product.specific_references)} <section class="product-features"> <p class="h6">{l s='Specific References' d='Shop.Theme.Catalog'}</p> <dl class="data-sheet"> {foreach from=$product.specific_references item=reference key=key} {if $key == 'upc'} <dt class="name">{'Barcode for Case'}</dt> {elseif $key == 'mpn'} <dt class="name">{'Barcode for Pack'}</dt> {elseif $key == 'ean13'} <dt class="name">{'Barcode for Each'}</dt> {else} <dt class="name">{$key}</dt> {/if} <dd class="value">{$reference}</dd> {/foreach} </dl> </section> {/if} Link to comment Share on other sites More sharing options...
lozal2244 Posted September 24, 2023 Share Posted September 24, 2023 For Prestashop 8.1.1 you hav eto modify the file src/Core/Domain/Product/ValueObject/Upc.php line 41, for example: From: public const VALID_PATTERN = '/^[0-9]{0,12}$/'; to: public const VALID_PATTERN = '/^[a-zA-Z 0-9-\(\)-]{0,24}$/'; 1 Link to comment Share on other sites More sharing options...
disarci Posted January 28 Share Posted January 28 Thank you Lozal2244 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