/var/www/vhosts/ihelp.ro/httpdocs/src/Model/Table
Edit: /var/www/vhosts/ihelp.ro/httpdocs/src/Model/Table/CategoriesTable.php (2599B)
setTable('categories');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->addBehavior('Tree');
$this->belongsTo('ParentCategories', [
'className' => 'Categories',
'foreignKey' => 'parent_id',
]);
$this->hasMany('Products', [
'foreignKey' => 'category_id',
]);
}
public function beforeSave(EventInterface $event, EntityInterface $entity, ArrayObject $options)
{
parent::beforeSave($event, $entity, $options);
}
/**
* Default validation rules.
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->integer('id')
->allowEmptyString('id', null, 'create');
$validator
->scalar('name')
->maxLength('name', 255)
->requirePresence('name', 'create')
->notEmptyString('name');
// $validator
// ->scalar('slug')
// ->maxLength('slug', 255)
// ->requirePresence('slug', 'create')
// ->notEmptyString('slug');
$validator
->scalar('parent')
->maxLength('parent', 255);
return $validator;
}
/**
* This function display different filters
*
* @param string|null $field_name
* @return array
*/
public function getFilters(string $field_name = null): array
{
$filters = [
'price' => [
'name' => __('Preț'),
'values' => [
'< 50' => '0-50',
'50 - 100' => '50-100',
'100 - 200' => '100-200',
'200 - 300' => '200-300',
'500 - 1000' => '500-1000',
'1000 >' => '1000-',
]
],
'picture' => [
'name' => __('Poză'),
'values' => [
__('Doar cu poza') => 1,
]
]
];
return $filters;
}
}