/var/www/vhosts/ihelp.ro/httpdocs/src/Model/Table
Edit: /var/www/vhosts/ihelp.ro/httpdocs/src/Model/Table/CartsTable.php (2120B)
setTable('carts');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsTo('Users', [
'foreignKey' => 'user_id',
]);
$this->belongsTo('PaymentMethods', [
'foreignKey' => 'payment_method_id',
]);
$this->belongsTo('UserAddresses', [
'foreignKey' => 'user_address_id',
]);
$this->hasMany('CartProducts', [
'foreignKey' => 'cart_id',
])->setDependent(true);
}
/**
* beforeSave. DON`T REMOVE
*/
function beforeSave(EventInterface $event, EntityInterface $entity, ArrayObject $options)
{
}
/**
* Default validation rules.
*/
public function validationDefault(Validator $validator): Validator
{
// $validator
// ->integer('id')
// ->allowEmptyString('id', null, 'create');
return $validator;
}
public function validationCheckout(Validator $validator): Validator
{
$validator
->integer('user_address_id')
->requirePresence('user_address_id')
->notEmptyString('user_address_id');
$validator
->integer('payment_method_id')
->requirePresence('payment_method_id')
->notEmptyString('payment_method_id');
return $validator;
}
/**
* Returns a rules checker object that will be used for validating
*/
// public function buildRules(RulesChecker $rules): RulesChecker
// {
// $rules->add($rules->existsIn(['user_id'], 'Users'), ['errorField' => 'user_id']);
// return $rules;
// }
}