composer update + load more dev dependencies for code quality, checkstyle fix
This commit is contained in:
@@ -5,154 +5,145 @@ namespace CakeProducts\Model\Table;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Database\Type\EnumType;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\Product;
|
||||
use CakeProducts\Model\Enum\ProductProductTypeId;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* Products Model
|
||||
*
|
||||
* @property ProductCategoriesTable&BelongsTo $ProductCategories
|
||||
*
|
||||
* @method Product newEmptyEntity()
|
||||
* @method Product newEntity(array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\Product newEmptyEntity()
|
||||
* @method \CakeProducts\Model\Entity\Product newEntity()
|
||||
* @method array<Product> newEntities(array $data, array $options = [])
|
||||
* @method Product get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method Product findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method Product patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\Product get()
|
||||
* @method \CakeProducts\Model\Entity\Product findOrCreate()
|
||||
* @method \CakeProducts\Model\Entity\Product patchEntity()
|
||||
* @method array<Product> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method Product|false save(EntityInterface $entity, array $options = [])
|
||||
* @method Product saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method \CakeProducts\Model\Entity\Product saveOrFail()
|
||||
* @method iterable<Product>|ResultSetInterface<Product>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<Product>|ResultSetInterface<Product> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<Product>|ResultSetInterface<Product>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<Product>|ResultSetInterface<Product> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
*/
|
||||
class ProductsTable extends Table
|
||||
{
|
||||
/**
|
||||
class ProductsTable extends Table {
|
||||
|
||||
/**
|
||||
* Initialize method
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('products');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
$this->setTable('products');
|
||||
$this->setDisplayField('name');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.Products.entity', 'CakeProducts\Model\Entity\Product')
|
||||
);
|
||||
$this->setEntityClass(
|
||||
Configure::read('CakeProducts.Products.entity', 'CakeProducts\Model\Entity\Product'),
|
||||
);
|
||||
|
||||
$this->belongsTo('ProductCategories', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'joinType' => 'INNER',
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
$this->belongsTo('ProductCategories', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'joinType' => 'INNER',
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductAttributes', [
|
||||
'className' => 'CakeProducts.ProductAttributes',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductAttributes', [
|
||||
'className' => 'CakeProducts.ProductAttributes',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductVariants', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.ProductVariants',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductVariants', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.ProductVariants',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductSkus', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.ProductSkus',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductSkus', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.ProductSkus',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductPhotos', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
$this->hasMany('ProductPhotos', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
|
||||
$this->hasOne('PrimaryProductPhotos', [
|
||||
'foreignKey' => 'product_id',
|
||||
'conditions' => ['PrimaryProductPhotos.primary_photo' => true],
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
]);
|
||||
$this->hasOne('PrimaryProductPhotos', [
|
||||
'foreignKey' => 'product_id',
|
||||
'conditions' => ['PrimaryProductPhotos.primary_photo' => true],
|
||||
'className' => 'CakeProducts.ProductPhotos',
|
||||
'dependent' => true,
|
||||
]);
|
||||
|
||||
$this->hasOne('DefaultProductSkus', [
|
||||
'foreignKey' => 'product_id',
|
||||
'conditions' => ['DefaultProductSkus.default_sku' => true],
|
||||
'className' => 'CakeProducts.ProductSkus',
|
||||
'propertyName' => 'default_product_sku',
|
||||
'dependent' => true,
|
||||
]);
|
||||
$this->hasOne('DefaultProductSkus', [
|
||||
'foreignKey' => 'product_id',
|
||||
'conditions' => ['DefaultProductSkus.default_sku' => true],
|
||||
'className' => 'CakeProducts.ProductSkus',
|
||||
'propertyName' => 'default_product_sku',
|
||||
'dependent' => true,
|
||||
]);
|
||||
|
||||
$this->getSchema()->setColumnType('product_type_id', EnumType::from(ProductProductTypeId::class));
|
||||
$this->getSchema()->setColumnType('product_type_id', EnumType::from(ProductProductTypeId::class));
|
||||
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
$this->addBehavior('Muffin/Trash.Trash');
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->scalar('name')
|
||||
->maxLength('name', 255)
|
||||
->requirePresence('name', 'create')
|
||||
->notEmptyString('name');
|
||||
|
||||
$validator
|
||||
->uuid('product_category_id')
|
||||
->notEmptyString('product_category_id');
|
||||
$validator
|
||||
->uuid('product_category_id')
|
||||
->notEmptyString('product_category_id');
|
||||
|
||||
$validator
|
||||
->integer('product_type_id')
|
||||
->requirePresence('product_type_id', 'create')
|
||||
->notEmptyString('product_type_id');
|
||||
$validator
|
||||
->integer('product_type_id')
|
||||
->requirePresence('product_type_id', 'create')
|
||||
->notEmptyString('product_type_id');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->isUnique(['product_category_id', 'name']), ['errorField' => 'product_category_id']);
|
||||
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->isUnique(['product_category_id', 'name']), ['errorField' => 'product_category_id']);
|
||||
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
|
||||
// $rules->add($rules->validCount('product_attributes', 0, '<=', 'You must not have any tags'));
|
||||
|
||||
return $rules;
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user