Jump to content

Presta 1.2.8.8 does not accept 13 characters entered in the EAN field - it accepts up to 10.


AngoG

Recommended Posts

Hi,

I need help. The EAN code of a product consists of 13 characters (digits). When in the back office, on the product card of the Presta store (1.7.8.8) I want to enter numbers in the EAN field, but I can only enter from 1 to 10 - a maximum of 10 digits. I can save and everything works. But when I want to enter the number 11, or 12 or 13, the Presta back office gives me the message "Unable to update settings". And additionally, when I want to enter, for example, 14 characters, the inscription "This value is not valid" appears under the EAN field - this is understandable and comparable - because I checked in the database that up to 13 characters can be entered in this field. Please tell me why I cannot enter 13 characters in the EAN field, but only up to 10.

How to remove this error? What could be causing this error?

presta_screen.jpg

Link to comment
Share on other sites

Modify the core form class 

Locate the form definition for “ean13”
In PrestaShop 1.7.8.8, the product form is usually defined in:

/src/PrestaShopBundle/Form/Admin/Product/ProductBasicInformationType.php
(If you don’t see that exact file, search for “ean13” under src/PrestaShopBundle/Form/Admin/Product/.)

Change the Length constraint and “maxlength” attribute
Find the section that looks roughly like this:

->add('ean13', TextType::class, [
  'label' => 'EAN-13',
  'required' => false,
  'constraints' => [
    new Length(['max' => 10]),    // ← currently 10
    new Regex(['pattern' => '/^\d*$/']),
  ],
  'attr' => [
    'maxlength' => 10,            // ← currently 10
  ],
])
 

Replace 10 with 13 in both places

Clear PrestaShop’s cache
After saving those changes, delete (or empty) the contents of /var/cache/prod (and /var/cache/dev if you’re in dev mode). Otherwise, Symfony will keep using the old cached form definition.

 

Link to comment
Share on other sites

28 minutes ago, El Patron said:

Modify the core form class 

Locate the form definition for “ean13”
In PrestaShop 1.7.8.8, the product form is usually defined in:

/src/PrestaShopBundle/Form/Admin/Product/ProductBasicInformationType.php
(If you don’t see that exact file, search for “ean13” under src/PrestaShopBundle/Form/Admin/Product/.)

Change the Length constraint and “maxlength” attribute
Find the section that looks roughly like this:

->add('ean13', TextType::class, [
  'label' => 'EAN-13',
  'required' => false,
  'constraints' => [
    new Length(['max' => 10]),    // ← currently 10
    new Regex(['pattern' => '/^\d*$/']),
  ],
  'attr' => [
    'maxlength' => 10,            // ← currently 10
  ],
])
 

Replace 10 with 13 in both places

Clear PrestaShop’s cache
After saving those changes, delete (or empty) the contents of /var/cache/prod (and /var/cache/dev if you’re in dev mode). Otherwise, Symfony will keep using the old cached form definition.

 

Thank you very much for your information.

Unfortunately I don't have the ProductBasicInformationType.php file but I found: src/Core/Domail/Product/ValueObject/Ean13.php

The length restriction and the "maxlength" attribute are correct here. See below please ...

Can there be any other reason?
Or am I looking in the wrong place?

---------------------------------------

 * Holds product Ean13 code value
 */
class Ean13
{
    /**
     * Valid ean regex pattern
     */
    public const VALID_PATTERN = '/^[0-9]{0,13}$/';

    /**
     * Maximum allowed symbols
     */
    public const MAX_LENGTH = 13;

    /**
     * @var string
     */
    private $value;

    /**
     * @param string $value
     */
    public function __construct(string $value)
    {
        $this->assertEan13IsValid($value);
        $this->value = $value;
    }

    /**
     * @return string
     */
    public function getValue(): string
    {
        return $this->value;
    }

    /**
     * @param string $value
     *
     * @throws ProductConstraintException
     */
    private function assertEan13IsValid(string $value): void
    {
        if (strlen($value) <= self::MAX_LENGTH && preg_match(self::VALID_PATTERN, $value)) {
            return;
        }

        throw new ProductConstraintException(
            sprintf(
                'Invalid Ean13 "%s". It should match pattern "%s" and cannot exceed %s symbols',
                $value,
                self::VALID_PATTERN,
                self::MAX_LENGTH
            ),
            ProductConstraintException::INVALID_EAN_13
        );
    }
}
 

Link to comment
Share on other sites

45 minutes ago, El Patron said:

look for and check this

src/PrestaShopBundle/Form/Admin/Product/ProductBasicInformationType.php

Hi,
I greatly appreciate your time and help.

Unfortunately, there is no file (ProductBasicInformationType.php)  - in the location you provided.
I also looked through the contents of the other files in the Product directory and there are no links to ean13.

Can something else be responsible for the number of characters in the ean13 field?

Link to comment
Share on other sites

3 hours ago, AngoG said:

Hi,
I greatly appreciate your time and help.

Unfortunately, there is no file (ProductBasicInformationType.php)  - in the location you provided.
I also looked through the contents of the other files in the Product directory and there are no links to ean13.

Can something else be responsible for the number of characters in the ean13 field?

Hi, I unzipped 1788 from 'github' and found the file, below is screen shot. 

https://app.screencast.com/HumQjV3r6pw2w

 

Link to comment
Share on other sites

1 hour ago, El Patron said:

Hi, I unzipped 1788 from 'github' and found the file, below is screen shot. 

https://app.screencast.com/HumQjV3r6pw2w

 

Hi,
Yes, I have this file.
But MAX_LENGTH = 13 - I'm attaching my file.
Do you think there could be another reason somewhere in my store, or a limiter, that I can only enter EAN13 up to 10 characters?

Thank you very much for your help.

ean13.jpg

Link to comment
Share on other sites

Maybe the issue lies in how PrestaShop validates EAN-13 codes. By default, PrestaShop checks that the EAN-13 value is no longer than 13 characters and is numeric. In classes/Validate.php (around line 689), you should find:

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

To allow up to 13 alphanumeric characters (A–Z, a–z, 0–9), while still accepting an empty value, replace the digit-only regex with an alphanumeric one:

return !$ean13 || preg_match('/^[A-Za-z0-9]{0,13}$/', $ean13);

Note:  I did not test actual change as I don't have a 1.7 dev shop anymore.

 

of course clear cache....whether  you need to or not looool
 

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...