Reputation: 513
Following this answers will be the code like this:
Product::$definition['fields']['mystock'] = array('type' => ObjectModel::TYPE_INT, 'validate' => 'isUnsignedInt');
class Product extends ProductCore
{
public $mystock;
}
But it's not working.
p.s. I want to add a definition rule btw.
upd 1.
this is my working override of Supplier
class in a module:
class Supplier extends SupplierCore
{
/** @var string Email */
public $email;
/**
* @see ObjectModel::$definition
*/
public static $definition = array(
'table' => 'supplier',
'primary' => 'id_supplier',
'multilang' => true,
'fields' => array(
'name' => array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName', 'required' => true, 'size' => 64),
'active' => array('type' => self::TYPE_BOOL),
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'size' => 128),
// Lang fields
'description' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),
'meta_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 128),
'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
'meta_keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
),
);
public function __construct($id = null, $id_lang = null)
{
parent::__construct($id, $id_lang);
}
}
upd 2.
and this is wrong side:
Supplier::$definition['fields']['email'] = array('type' => ObjectModel::TYPE_STRING, 'validate' => 'isEmail', 'required' => true, 'size' => 128);
class Supplier extends SupplierCore
{
/** @var string Email */
public $email;
public function __construct($id = null, $id_lang = null)
{
parent::__construct($id, $id_lang);
}
}
So how to do this, if it's possible?
upd 3. maybe better would be add it somewhere on submitting form, before this check:
$validation = $address->validateController();
// checks address validity
if (count($validation) > 0)
{
foreach ($validation as $item)
$this->errors[] = $item;
$this->errors[] = Tools::displayError('The address is not correct. Please make sure all of the required fields are completed.');
}
But how?
Upvotes: 1
Views: 2602
Reputation: 95
I think you are placing the definition in the wrong place. Try this code in your override class for supplier:
class Supplier extends SupplierCore
{
/** @var string Email */
public $email;
public function __construct($id = null, $id_lang = null)
{
self::$definition['fields']['email'] = array('type' => ObjectModel::TYPE_STRING, 'validate' => 'isEmail', 'required' => true, 'size' => 128);
parent::__construct($id, $id_lang);
}
}
Upvotes: 2