Jump to content

Error al hacer un override al archivo "/classes/Customer.php"


Recommended Posts

Buenos días.

Pido ayuda al foro porque llevo un par de días intentando solucionar un problema y no doy con la solución. Estoy creando un módulo nuevo para nuestra tienda y necesito que tanto el nombre como el apellido de los clientes puedan tener carácteres especiales, como comas, puntos y números.

Para ello, he cogido el $definition y he hecho los cambios necesarios, y una vez terminado, lo he movido al directorio "override/classes" dentro del módulo, y funciona. El problema viene cuando intentas deshabilitar o desinstalar el módulo , que no lo borra por completo. Pongo un ejemplo.

Cuando activo el plugin, el archivo que se crea en el directorio "override" se ve de esta manera:

<?php
class Customer extends CustomerCore
{
    /*
    * module: nombre
    * date: 2021-05-05 13:00:40
    * version: 1.0.0
    */
    public static $definition = [
        'table' => 'customer',
        'primary' => 'id_customer',
        'fields' => [
            'secure_key' => ['type' => self::TYPE_STRING, 'validate' => 'isMd5', 'copy_post' => false],
            'lastname' => ['type' => self::TYPE_STRING, 'validate' => 'isAnything', 'required' => true, 'size' => 255],
            'firstname' => ['type' => self::TYPE_STRING, 'validate' => 'isAnything', 'required' => true, 'size' => 255],
            'email' => ['type' => self::TYPE_STRING, 'validate' => 'isEmail', 'required' => true, 'size' => 255],
            'passwd' => ['type' => self::TYPE_STRING, 'validate' => 'isPasswd', 'required' => true, 'size' => 255],
            'last_passwd_gen' => ['type' => self::TYPE_STRING, 'copy_post' => false],
            'id_gender' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId'],
            'birthday' => ['type' => self::TYPE_DATE, 'validate' => 'isBirthDate'],
            'newsletter' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'],
            'newsletter_date_add' => ['type' => self::TYPE_DATE, 'copy_post' => false],
            'ip_registration_newsletter' => ['type' => self::TYPE_STRING, 'copy_post' => false],
            'optin' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'],
            'website' => ['type' => self::TYPE_STRING, 'validate' => 'isUrl'],
            'company' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName'],
            'siret' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName'],
            'ape' => ['type' => self::TYPE_STRING, 'validate' => 'isApe'],
            'outstanding_allow_amount' => ['type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'copy_post' => false],
            'show_public_prices' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false],
            'id_risk' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'copy_post' => false],
            'max_payment_days' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'copy_post' => false],
            'active' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false],
            'deleted' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false],
            'note' => ['type' => self::TYPE_HTML, 'size' => 65000, 'copy_post' => false],
            'is_guest' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false],
            'id_shop' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_post' => false],
            'id_shop_group' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_post' => false],
            'id_default_group' => ['type' => self::TYPE_INT, 'copy_post' => false],
            'id_lang' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_post' => false],
            'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false],
            'date_upd' => ['type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false],
            'reset_password_token' => ['type' => self::TYPE_STRING, 'validate' => 'isSha1', 'size' => 40, 'copy_post' => false],
            'reset_password_validity' => ['type' => self::TYPE_DATE, 'validate' => 'isDateOrNull', 'copy_post' => false],
        ],
    ];
}

Sin embargo, cuando lo intento deshabilitar/desinstalar, se ve así:

<?php
class Customer extends CustomerCore
{
        'table' => 'customer',
        'primary' => 'id_customer',
        'fields' => [
            'secure_key' => ['type' => self::TYPE_STRING, 'validate' => 'isMd5', 'copy_post' => false],
            'lastname' => ['type' => self::TYPE_STRING, 'validate' => 'isCustomerName', 'required' => true, 'size' => 255],
            'firstname' => ['type' => self::TYPE_STRING, 'validate' => 'isCustomerName', 'required' => true, 'size' => 255],
            'email' => ['type' => self::TYPE_STRING, 'validate' => 'isEmail', 'required' => true, 'size' => 255],
            'passwd' => ['type' => self::TYPE_STRING, 'validate' => 'isPasswd', 'required' => true, 'size' => 255],
            'last_passwd_gen' => ['type' => self::TYPE_STRING, 'copy_post' => false],
            'id_gender' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId'],
            'birthday' => ['type' => self::TYPE_DATE, 'validate' => 'isBirthDate'],
            'newsletter' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'],
            'newsletter_date_add' => ['type' => self::TYPE_DATE, 'copy_post' => false],
            'ip_registration_newsletter' => ['type' => self::TYPE_STRING, 'copy_post' => false],
            'optin' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'],
            'website' => ['type' => self::TYPE_STRING, 'validate' => 'isUrl'],
            'company' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName'],
            'siret' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName'],
            'ape' => ['type' => self::TYPE_STRING, 'validate' => 'isApe'],
            'outstanding_allow_amount' => ['type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'copy_post' => false],
            'show_public_prices' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false],
            'id_risk' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'copy_post' => false],
            'max_payment_days' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'copy_post' => false],
            'active' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false],
            'deleted' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false],
            'note' => ['type' => self::TYPE_HTML, 'size' => 65000, 'copy_post' => false],
            'is_guest' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false],
            'id_shop' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_post' => false],
            'id_shop_group' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_post' => false],
            'id_default_group' => ['type' => self::TYPE_INT, 'copy_post' => false],
            'id_lang' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_post' => false],
            'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false],
            'date_upd' => ['type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false],
            'reset_password_token' => ['type' => self::TYPE_STRING, 'validate' => 'isSha1', 'size' => 40, 'copy_post' => false],
            'reset_password_validity' => ['type' => self::TYPE_DATE, 'validate' => 'isDateOrNull', 'copy_post' => false],
        ],
    ];
}

Por supuesto, al ocurrir esto, da un error al intentar volver a activar el módulo. He buscado un poco por internet y he visto que alguien ya ha preguntado esto en su GitHub oficial, donde le han dicho que este método ya está obsoleto.

¿Cómo debería hacerlo para que funcionase correctamente?

¡Muchas gracias por todo!

Link to comment
Share on other sites

1 hour ago, joseantgv said:

Prueba a hacer el override en el construct.

He probado a hacerlo como me has comentado y de momento funciona bastante bien, de hecho es bastante más limpio, por lo que lo haré así a partir de ahora.

<?php
class Customer extends CustomerCore
{
    public function __construct($id = null, $id_lang = null)
    {
        self::$definition['fields']['lastname'] = array('type' => self::TYPE_STRING, 'validate' => 'isAnything', 'required' => true, 'size' => 255);
        self::$definition['fields']['firstname'] = array('type' => self::TYPE_STRING, 'validate' => 'isAnything', 'required' => true, 'size' => 255);
        parent::__construct($id, $id_lang);
    }
}

¡Muchas gracias por la ayuda!

  • Like 1
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...