composer update + load more dev dependencies for code quality, checkstyle fix

This commit is contained in:
bs
2026-08-21 23:57:55 -07:00
parent c196dc2fe0
commit 8e142f56ab
104 changed files with 6341 additions and 6743 deletions
@@ -5,18 +5,10 @@ namespace CakeProducts\Model\Table;
use ArrayObject;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\Event\EventInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Behavior\TimestampBehavior;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ExternalProductCatalogsProductCatalogs Model
@@ -24,15 +16,15 @@ use Psr\SimpleCache\CacheInterface;
* @property ExternalProductCatalogsTable&BelongsTo $ExternalProductCatalogs
* @property ProductCatalogsTable&BelongsTo $ProductCatalogs
*
* @method ExternalProductCatalogsProductCatalog newEmptyEntity()
* @method ExternalProductCatalogsProductCatalog newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog newEmptyEntity()
* @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog newEntity()
* @method array<ExternalProductCatalogsProductCatalog> newEntities(array $data, array $options = [])
* @method ExternalProductCatalogsProductCatalog get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ExternalProductCatalogsProductCatalog findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ExternalProductCatalogsProductCatalog patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog get()
* @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog findOrCreate()
* @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog patchEntity()
* @method array<ExternalProductCatalogsProductCatalog> patchEntities(iterable $entities, array $data, array $options = [])
* @method ExternalProductCatalogsProductCatalog|false save(EntityInterface $entity, array $options = [])
* @method ExternalProductCatalogsProductCatalog saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog saveOrFail()
* @method iterable<ExternalProductCatalogsProductCatalog>|ResultSetInterface<ExternalProductCatalogsProductCatalog>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ExternalProductCatalogsProductCatalog>|ResultSetInterface<ExternalProductCatalogsProductCatalog> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ExternalProductCatalogsProductCatalog>|ResultSetInterface<ExternalProductCatalogsProductCatalog>|false deleteMany(iterable $entities, array $options = [])
@@ -40,86 +32,86 @@ use Psr\SimpleCache\CacheInterface;
*
* @mixin TimestampBehavior
*/
class ExternalProductCatalogsProductCatalogsTable extends Table
{
/**
class ExternalProductCatalogsProductCatalogsTable 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('external_product_catalogs_product_catalogs');
$this->setDisplayField('external_product_catalog_id');
$this->setPrimaryKey('id');
$this->setTable('external_product_catalogs_product_catalogs');
$this->setDisplayField('external_product_catalog_id');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->addBehavior('Timestamp');
$this->setEntityClass(
Configure::read('CakeProducts.ExternalProductCatalogsProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog')
);
$this->belongsTo('ExternalProductCatalogs', [
'className' => 'CakeProducts.ExternalProductCatalogs',
$this->setEntityClass(
Configure::read('CakeProducts.ExternalProductCatalogsProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog'),
);
$this->belongsTo('ExternalProductCatalogs', [
'className' => 'CakeProducts.ExternalProductCatalogs',
// 'foreignKey' => 'external_product_catalog_id',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductCatalogs', [
'className' => 'CakeProducts.ProductCatalogs',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductCatalogs', [
'className' => 'CakeProducts.ProductCatalogs',
// 'foreignKey' => 'product_catalog_id',
'joinType' => 'INNER',
]);
'joinType' => 'INNER',
]);
$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
->uuid('external_product_catalog_id')
->notEmptyString('external_product_catalog_id');
public function validationDefault(Validator $validator): Validator {
$validator
->uuid('external_product_catalog_id')
->notEmptyString('external_product_catalog_id');
$validator
->uuid('product_catalog_id')
->notEmptyString('product_catalog_id');
$validator
->uuid('product_catalog_id')
->notEmptyString('product_catalog_id');
$validator
->boolean('enabled');
$validator
->boolean('enabled');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator;
}
return $validator;
}
public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options)
{
if (!isset($data['enabled'])) {
$data['enabled'] = false;
}
}
/**
* @return void
*/
public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options) {
if (!isset($data['enabled'])) {
$data['enabled'] = false;
}
}
/**
/**
* 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
{
public function buildRules(RulesChecker $rules): RulesChecker {
// $rules->add($rules->existsIn(['external_product_catalog_id'], 'ExternalProductCatalogs'), ['errorField' => 'external_product_catalog_id']);
// $rules->add($rules->existsIn(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => 'product_catalog_id']);
return $rules;
}
return $rules;
}
}
@@ -4,32 +4,24 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Behavior\TimestampBehavior;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ExternalProductCatalog;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ExternalProductCatalogs Model
*
* @property ProductCatalogsTable&BelongsTo $ProductCatalogs
*
* @method ExternalProductCatalog newEmptyEntity()
* @method ExternalProductCatalog newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ExternalProductCatalog newEmptyEntity()
* @method \CakeProducts\Model\Entity\ExternalProductCatalog newEntity()
* @method array<ExternalProductCatalog> newEntities(array $data, array $options = [])
* @method ExternalProductCatalog get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ExternalProductCatalog findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ExternalProductCatalog patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ExternalProductCatalog get()
* @method \CakeProducts\Model\Entity\ExternalProductCatalog findOrCreate()
* @method \CakeProducts\Model\Entity\ExternalProductCatalog patchEntity()
* @method array<ExternalProductCatalog> patchEntities(iterable $entities, array $data, array $options = [])
* @method ExternalProductCatalog|false save(EntityInterface $entity, array $options = [])
* @method ExternalProductCatalog saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ExternalProductCatalog saveOrFail()
* @method iterable<ExternalProductCatalog>|ResultSetInterface<ExternalProductCatalog>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ExternalProductCatalog>|ResultSetInterface<ExternalProductCatalog> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ExternalProductCatalog>|ResultSetInterface<ExternalProductCatalog>|false deleteMany(iterable $entities, array $options = [])
@@ -37,81 +29,79 @@ use Psr\SimpleCache\CacheInterface;
*
* @mixin TimestampBehavior
*/
class ExternalProductCatalogsTable extends Table
{
/**
class ExternalProductCatalogsTable 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('external_product_catalogs');
$this->setDisplayField('base_url');
$this->setPrimaryKey('id');
$this->setTable('external_product_catalogs');
$this->setDisplayField('base_url');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->addBehavior('Timestamp');
$this->setEntityClass(
Configure::read('CakeProducts.ExternalProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalog')
);
$this->setEntityClass(
Configure::read('CakeProducts.ExternalProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalog'),
);
$this->belongsToMany('ProductCatalogs', [
'through' => 'ExternalProductCatalogsProductCatalogs',
'className' => 'CakeProducts.ProductCatalogs',
]);
$this->belongsToMany('ProductCatalogs', [
'through' => 'ExternalProductCatalogsProductCatalogs',
'className' => 'CakeProducts.ProductCatalogs',
]);
$this->hasMany('ExternalProductCatalogsProductCatalogs', [
'foreignKey' => 'external_product_catalog_id',
'className' => 'CakeProducts.ExternalProductCatalogsProductCatalogs',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ExternalProductCatalogsProductCatalogs', [
'foreignKey' => 'external_product_catalog_id',
'className' => 'CakeProducts.ExternalProductCatalogsProductCatalogs',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$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('base_url')
->maxLength('base_url', 255)
->requirePresence('base_url', 'create')
->notEmptyString('base_url');
public function validationDefault(Validator $validator): Validator {
$validator
->scalar('base_url')
->maxLength('base_url', 255)
->requirePresence('base_url', 'create')
->notEmptyString('base_url');
// ->url('base_url');
$validator
->scalar('api_url')
->maxLength('api_url', 255)
->requirePresence('api_url', 'create')
->notEmptyString('api_url');
$validator
->scalar('api_url')
->maxLength('api_url', 255)
->requirePresence('api_url', 'create')
->notEmptyString('api_url');
// ->url('api_url');
$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
{
return $rules;
}
public function buildRules(RulesChecker $rules): RulesChecker {
return $rules;
}
}
+54 -56
View File
@@ -29,88 +29,86 @@ use Cake\Validation\Validator;
* @method iterable<\App\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\ProductAttribute>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<\App\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\ProductAttribute> deleteManyOrFail(iterable $entities, array $options = [])
*/
class ProductAttributesTable extends Table
{
/**
class ProductAttributesTable 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('product_attributes');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->setTable('product_attributes');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductAttributes.entity', 'CakeProducts\Model\Entity\ProductAttribute')
);
$this->setEntityClass(
Configure::read('CakeProducts.ProductAttributes.entity', 'CakeProducts\Model\Entity\ProductAttribute'),
);
$this->belongsTo('Products', [
'foreignKey' => 'product_id',
'className' => 'CakeProducts.Products',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductCategoryAttributes', [
'foreignKey' => 'product_category_attribute_id',
'className' => 'CakeProducts.ProductCategoryAttributes',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductCategoryAttributeOptions', [
'foreignKey' => 'product_category_attribute_option_id',
'className' => 'CakeProducts.ProductCategoryAttributeOptions',
]);
$this->belongsTo('Products', [
'foreignKey' => 'product_id',
'className' => 'CakeProducts.Products',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductCategoryAttributes', [
'foreignKey' => 'product_category_attribute_id',
'className' => 'CakeProducts.ProductCategoryAttributes',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductCategoryAttributeOptions', [
'foreignKey' => 'product_category_attribute_option_id',
'className' => 'CakeProducts.ProductCategoryAttributeOptions',
]);
}
}
/**
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->uuid('product_id')
->notEmptyString('product_id');
public function validationDefault(Validator $validator): Validator {
$validator
->uuid('product_id')
->notEmptyString('product_id');
$validator
->uuid('product_category_attribute_id')
->notEmptyString('product_category_attribute_id');
$validator
->uuid('product_category_attribute_id')
->notEmptyString('product_category_attribute_id');
$validator
->scalar('attribute_value')
->maxLength('attribute_value', 255)
->allowEmptyString('attribute_value');
$validator
->scalar('attribute_value')
->maxLength('attribute_value', 255)
->allowEmptyString('attribute_value');
$validator
->uuid('product_category_attribute_option_id')
->allowEmptyString('product_category_attribute_option_id');
$validator
->uuid('product_category_attribute_option_id')
->allowEmptyString('product_category_attribute_option_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 \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
$rules->add($rules->existsIn(['product_category_attribute_option_id'], 'ProductCategoryAttributeOptions'), ['errorField' => 'product_category_attribute_option_id']);
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
$rules->add($rules->existsIn(['product_category_attribute_option_id'], 'ProductCategoryAttributeOptions'), ['errorField' => 'product_category_attribute_option_id']);
return $rules;
}
return $rules;
}
}
+57 -65
View File
@@ -4,106 +4,98 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductCatalog;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductCatalogs Model
*
* @method ProductCatalog newEmptyEntity()
* @method ProductCatalog newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCatalog newEmptyEntity()
* @method \CakeProducts\Model\Entity\ProductCatalog newEntity()
* @method array<ProductCatalog> newEntities(array $data, array $options = [])
* @method ProductCatalog get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductCatalog findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductCatalog patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCatalog get()
* @method \CakeProducts\Model\Entity\ProductCatalog findOrCreate()
* @method \CakeProducts\Model\Entity\ProductCatalog patchEntity()
* @method array<ProductCatalog> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCatalog|false save(EntityInterface $entity, array $options = [])
* @method ProductCatalog saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCatalog saveOrFail()
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductCatalog>|ResultSetInterface<ProductCatalog> deleteManyOrFail(iterable $entities, array $options = [])
*/
class ProductCatalogsTable extends Table
{
/**
class ProductCatalogsTable 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('product_catalogs');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->setTable('product_catalogs');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductCatalogs.entity', 'CakeProducts\Model\Entity\ProductCatalog')
);
$this->hasMany('ProductCategories', [
'className' => 'CakeProducts.ProductCategories',
]);
$this->belongsToMany('ExternalProductCatalogs', [
'through' => 'ExternalProductCatalogsProductCatalogs',
'className' => 'CakeProducts.ExternalProductCatalogs',
]);
$this->setEntityClass(
Configure::read('CakeProducts.ProductCatalogs.entity', 'CakeProducts\Model\Entity\ProductCatalog'),
);
$this->hasMany('ProductCategories', [
'className' => 'CakeProducts.ProductCategories',
]);
$this->belongsToMany('ExternalProductCatalogs', [
'through' => 'ExternalProductCatalogsProductCatalogs',
'className' => 'CakeProducts.ExternalProductCatalogs',
]);
$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')
->add('name', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);
public function validationDefault(Validator $validator): Validator {
$validator
->scalar('name')
->maxLength('name', 255)
->requirePresence('name', 'create')
->notEmptyString('name')
->add('name', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);
$validator
->scalar('catalog_description')
->maxLength('catalog_description', 255)
->allowEmptyString('catalog_description');
$validator
->scalar('catalog_description')
->maxLength('catalog_description', 255)
->allowEmptyString('catalog_description');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
$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(['name']), ['errorField' => 'name']);
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->isUnique(['name']), ['errorField' => 'name']);
return $rules;
}
return $rules;
}
}
+133 -145
View File
@@ -6,18 +6,10 @@ 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\Association\HasMany;
use Cake\ORM\Behavior\TreeBehavior;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductCategory;
use CakeProducts\Model\Enum\ProductProductTypeId;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductCategories Model
@@ -26,14 +18,14 @@ use Psr\SimpleCache\CacheInterface;
* @property ProductCategoriesTable&BelongsTo $ParentProductCategories
* @property ProductCategoriesTable&HasMany $ChildProductCategories
*
* @method ProductCategory newEmptyEntity()
* @method ProductCategory newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategory newEmptyEntity()
* @method \CakeProducts\Model\Entity\ProductCategory newEntity()
* @method array<ProductCategory> newEntities(array $data, array $options = [])
* @method ProductCategory get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductCategory findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductCategory patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategory get()
* @method \CakeProducts\Model\Entity\ProductCategory findOrCreate()
* @method \CakeProducts\Model\Entity\ProductCategory patchEntity()
* @method array<ProductCategory> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCategory saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategory saveOrFail()
* @method iterable<ProductCategory>|ResultSetInterface<ProductCategory>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCategory>|ResultSetInterface<ProductCategory> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductCategory>|ResultSetInterface<ProductCategory>|false deleteMany(iterable $entities, array $options = [])
@@ -41,175 +33,171 @@ use Psr\SimpleCache\CacheInterface;
*
* @mixin TreeBehavior
*/
class ProductCategoriesTable extends Table
{
/**
class ProductCategoriesTable extends Table {
/**
* Current scope for Tree behavior - per catalog
*
* @var string
*/
protected $treeCatalogId;
protected $treeCatalogId;
/**
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
$this->treeCatalogId = 1;
public function initialize(array $config): void {
parent::initialize($config);
$this->treeCatalogId = 1;
$this->setTable('product_categories');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategories.entity', 'CakeProducts\Model\Entity\ProductCategory')
);
$this->addBehavior('Tree', [
'cascadeCallbacks' => true,
]);
$this->setTable('product_categories');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategories.entity', 'CakeProducts\Model\Entity\ProductCategory'),
);
$this->addBehavior('Tree', [
'cascadeCallbacks' => true,
]);
$this->belongsTo('ProductCatalogs', [
'foreignKey' => 'product_catalog_id',
'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCatalogs',
]);
$this->belongsTo('ParentProductCategories', [
'className' => 'CakeProducts.ProductCategories',
'foreignKey' => 'parent_id',
]);
$this->hasMany('ChildProductCategories', [
'className' => 'CakeProducts.ProductCategories',
'foreignKey' => 'parent_id',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductCategoryAttributes', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategoryAttributes',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductCategoryVariants', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategoryVariants',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('Products', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.Products',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductPhotos', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasOne('PrimaryProductPhotos', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'conditions' => ['PrimaryProductPhotos.primary_category_photo' => true],
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
]);
$this->belongsTo('ProductCatalogs', [
'foreignKey' => 'product_catalog_id',
'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCatalogs',
]);
$this->belongsTo('ParentProductCategories', [
'className' => 'CakeProducts.ProductCategories',
'foreignKey' => 'parent_id',
]);
$this->hasMany('ChildProductCategories', [
'className' => 'CakeProducts.ProductCategories',
'foreignKey' => 'parent_id',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductCategoryAttributes', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategoryAttributes',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductCategoryVariants', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategoryVariants',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('Products', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.Products',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductPhotos', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasOne('PrimaryProductPhotos', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'conditions' => ['PrimaryProductPhotos.primary_category_photo' => true],
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
]);
$this->getSchema()->setColumnType('default_product_type_id', EnumType::from(ProductProductTypeId::class));
$this->getSchema()->setColumnType('default_product_type_id', EnumType::from(ProductProductTypeId::class));
$this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
$this->addBehavior('Muffin/Trash.Trash');
}
$this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
$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
->uuid('product_catalog_id')
->notEmptyString('product_catalog_id');
public function validationDefault(Validator $validator): Validator {
$validator
->uuid('product_catalog_id')
->notEmptyString('product_catalog_id');
$validator
->scalar('name')
->maxLength('name', 255)
->requirePresence('name', 'create')
->notEmptyString('name');
$validator
->scalar('name')
->maxLength('name', 255)
->requirePresence('name', 'create')
->notEmptyString('name');
$validator
->scalar('category_description')
->allowEmptyString('category_description');
$validator
->scalar('category_description')
->allowEmptyString('category_description');
$validator
->integer('parent_id')
->allowEmptyString('parent_id');
$validator
->integer('parent_id')
->allowEmptyString('parent_id');
$validator
->boolean('enabled')
->notEmptyString('enabled');
$validator
->boolean('enabled')
->notEmptyString('enabled');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
$validator
->integer('default_product_type_id')
->allowEmptyString('default_product_type_id');
$validator
->integer('default_product_type_id')
->allowEmptyString('default_product_type_id');
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_catalog_id', 'name']), ['errorField' => 'product_catalog_id']);
$rules->add($rules->existsIn(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => 'product_catalog_id']);
$rules->add($rules->existsIn(['parent_id'], 'ParentProductCategories'), ['errorField' => 'parent_id']);
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->isUnique(['product_catalog_id', 'name']), ['errorField' => 'product_catalog_id']);
$rules->add($rules->existsIn(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => 'product_catalog_id']);
$rules->add($rules->existsIn(['parent_id'], 'ParentProductCategories'), ['errorField' => 'parent_id']);
return $rules;
}
return $rules;
}
/**
* @param int $catalogId
/**
* @param string $catalogId
*
* @return void
*/
public function setConfigureCatalogId(string $catalogId)
{
$this->treeCatalogId = $catalogId;
$this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
}
public function setConfigureCatalogId(string $catalogId) {
$this->treeCatalogId = $catalogId;
$this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
}
/**
* @param EntityInterface $entity
/**
* @param \Cake\Datasource\EntityInterface $entity
* @param array $options
*
* @return EntityInterface|false
* @return \Cake\Datasource\EntityInterface|false
*/
public function save(EntityInterface $entity, array $options = []): EntityInterface|false
{
$this->behaviors()->get('Tree')->setConfig([
'scope' => [
'product_catalog_id' => $entity->product_catalog_id,
],
]);
public function save(EntityInterface $entity, array $options = []): EntityInterface|false {
$this->behaviors()->get('Tree')->setConfig([
'scope' => [
'product_catalog_id' => $entity->product_catalog_id,
],
]);
return parent::save($entity, $options);
}
return parent::save($entity, $options);
}
}
@@ -4,112 +4,103 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
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\ProductCategoryAttributeOption;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductCategoryAttributeOptions Model
*
* @property ProductCategoryAttributesTable&BelongsTo $ProductCategoryAttributes
*
* @method ProductCategoryAttributeOption newEmptyEntity()
* @method ProductCategoryAttributeOption newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption newEmptyEntity()
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption newEntity()
* @method array<ProductCategoryAttributeOption> newEntities(array $data, array $options = [])
* @method ProductCategoryAttributeOption get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductCategoryAttributeOption findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductCategoryAttributeOption patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption get()
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption findOrCreate()
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption patchEntity()
* @method array<ProductCategoryAttributeOption> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCategoryAttributeOption|false save(EntityInterface $entity, array $options = [])
* @method ProductCategoryAttributeOption saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption saveOrFail()
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttributeOption>|ResultSetInterface<ProductCategoryAttributeOption> deleteManyOrFail(iterable $entities, array $options = [])
*/
class ProductCategoryAttributeOptionsTable extends Table
{
/**
class ProductCategoryAttributeOptionsTable 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('product_category_attribute_options');
$this->setDisplayField('attribute_value');
$this->setPrimaryKey('id');
$this->setTable('product_category_attribute_options');
$this->setDisplayField('attribute_value');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryAttributeOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryAttributeOption')
);
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryAttributeOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryAttributeOption'),
);
$this->belongsTo('ProductCategoryAttributes', [
'foreignKey' => 'product_category_attribute_id',
'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCategoryAttributes',
]);
$this->belongsTo('ProductCategoryAttributes', [
'foreignKey' => 'product_category_attribute_id',
'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCategoryAttributes',
]);
$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
->uuid('product_category_attribute_id')
->notEmptyString('product_category_attribute_id');
public function validationDefault(Validator $validator): Validator {
$validator
->uuid('product_category_attribute_id')
->notEmptyString('product_category_attribute_id');
$validator
->scalar('attribute_value')
->maxLength('attribute_value', 255)
->requirePresence('attribute_value', 'create')
->notEmptyString('attribute_value');
$validator
->scalar('attribute_value')
->maxLength('attribute_value', 255)
->requirePresence('attribute_value', 'create')
->notEmptyString('attribute_value');
$validator
->scalar('attribute_label')
->maxLength('attribute_label', 255)
->requirePresence('attribute_label', 'create')
->notEmptyString('attribute_label');
$validator
->scalar('attribute_label')
->maxLength('attribute_label', 255)
->requirePresence('attribute_label', 'create')
->notEmptyString('attribute_label');
$validator
->boolean('enabled')
->notEmptyString('enabled');
$validator
->boolean('enabled')
->notEmptyString('enabled');
$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->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
$rules->add($rules->isUnique(['attribute_value', 'product_category_attribute_id']));
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
$rules->add($rules->isUnique(['attribute_value', 'product_category_attribute_id']));
return $rules;
}
return $rules;
}
}
@@ -5,146 +5,141 @@ 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\ProductCategoryAttribute;
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductCategoryAttributes Model
*
* @property ProductCategoriesTable&BelongsTo $ProductCategories
*
* @method ProductCategoryAttribute newEmptyEntity()
* @method ProductCategoryAttribute newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute newEmptyEntity()
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute newEntity()
* @method array<ProductCategoryAttribute> newEntities(array $data, array $options = [])
* @method ProductCategoryAttribute get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductCategoryAttribute findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductCategoryAttribute patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute get()
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute findOrCreate()
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute patchEntity()
* @method array<ProductCategoryAttribute> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCategoryAttribute|false save(EntityInterface $entity, array $options = [])
* @method ProductCategoryAttribute saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryAttribute saveOrFail()
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryAttribute>|ResultSetInterface<ProductCategoryAttribute> deleteManyOrFail(iterable $entities, array $options = [])
*/
class ProductCategoryAttributesTable extends Table
{
/**
class ProductCategoryAttributesTable 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('product_category_attributes');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->setTable('product_category_attributes');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryAttributes.entity', 'CakeProducts\Model\Entity\ProductCategoryAttribute')
);
$this->belongsTo('ProductCategories', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategories',
]);
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryAttributes.entity', 'CakeProducts\Model\Entity\ProductCategoryAttribute'),
);
$this->belongsTo('ProductCategories', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategories',
]);
$this->hasMany('ProductCategoryAttributeOptions', [
'foreignKey' => 'product_category_attribute_id',
'className' => 'CakeProducts.ProductCategoryAttributeOptions',
'saveStrategy' => 'replace',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->getSchema()->setColumnType('attribute_type_id', EnumType::from(ProductCategoryAttributeTypeId::class));
$this->hasMany('ProductCategoryAttributeOptions', [
'foreignKey' => 'product_category_attribute_id',
'className' => 'CakeProducts.ProductCategoryAttributeOptions',
'saveStrategy' => 'replace',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->getSchema()->setColumnType('attribute_type_id', EnumType::from(ProductCategoryAttributeTypeId::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')
->allowEmptyString('product_category_id');
$validator
->uuid('product_category_id')
->allowEmptyString('product_category_id');
$validator
->integer('attribute_type_id')
->requirePresence('attribute_type_id', 'create')
->notEmptyString('attribute_type_id');
$validator
->integer('attribute_type_id')
->requirePresence('attribute_type_id', 'create')
->notEmptyString('attribute_type_id');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
$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(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'name']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'name']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
return $rules;
}
return $rules;
}
/**
* @param SelectQuery $query
/**
* @param \Cake\ORM\Query\SelectQuery $query
* @param string $internalCategoryId
*
* @return array|\Cake\ORM\Query|SelectQuery
* @return \Cake\ORM\Query|\Cake\ORM\Query\SelectQuery|array
*/
public function findAllCategoryAttributesForCategoryId(SelectQuery $query, string $internalCategoryId)
{
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
public function findAllCategoryAttributesForCategoryId(SelectQuery $query, string $internalCategoryId) {
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
$this->ProductCategories->behaviors()->get('Tree')->setConfig([
'scope' => [
'product_catalog_id' => $category->product_catalog_id ?? 1,
],
]);
$this->ProductCategories->behaviors()->get('Tree')->setConfig([
'scope' => [
'product_catalog_id' => $category->product_catalog_id ?? 1,
],
]);
return $this->ProductCategories
->find('path', for: $category->id)
->contain(['ProductCategoryAttributes', 'ProductCategoryAttributes.ProductCategoryAttributeOptions']);
}
/**
* @param string $internalCategoryId
* @return array|array[]|\Cake\Datasource\EntityInterface[]
*/
public function getAllCategoryAttributesForCategoryId(string $internalCategoryId) {
return $this->find('allCategoryAttributesForCategoryId', $internalCategoryId)->toArray();
}
return $this->ProductCategories
->find('path', for: $category->id)
->contain(['ProductCategoryAttributes', 'ProductCategoryAttributes.ProductCategoryAttributeOptions']);
}
public function getAllCategoryAttributesForCategoryId(string $internalCategoryId)
{
return $this->find('allCategoryAttributesForCategoryId', $internalCategoryId)->toArray();
}
}
@@ -4,33 +4,24 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use CakeProducts\Model\Entity\ProductCategoryVariantOption;
use CakeProducts\Model\Table\ProductCategoryVariantsTable;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Behavior\TimestampBehavior;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductCategoryVariantOptions Model
*
* @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants
*
* @method ProductCategoryVariantOption newEmptyEntity()
* @method ProductCategoryVariantOption newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption newEmptyEntity()
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption newEntity()
* @method array<ProductCategoryVariantOption> newEntities(array $data, array $options = [])
* @method ProductCategoryVariantOption get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductCategoryVariantOption findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductCategoryVariantOption patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption get()
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption findOrCreate()
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption patchEntity()
* @method array<ProductCategoryVariantOption> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCategoryVariantOption|false save(EntityInterface $entity, array $options = [])
* @method ProductCategoryVariantOption saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryVariantOption saveOrFail()
* @method iterable<ProductCategoryVariantOption>|ResultSetInterface<ProductCategoryVariantOption>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryVariantOption>|ResultSetInterface<ProductCategoryVariantOption> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductCategoryVariantOption>|ResultSetInterface<ProductCategoryVariantOption>|false deleteMany(iterable $entities, array $options = [])
@@ -38,75 +29,73 @@ use Psr\SimpleCache\CacheInterface;
*
* @mixin TimestampBehavior
*/
class ProductCategoryVariantOptionsTable extends Table
{
/**
class ProductCategoryVariantOptionsTable 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('product_category_variant_options');
$this->setDisplayField('variant_value');
$this->setPrimaryKey('id');
$this->setTable('product_category_variant_options');
$this->setDisplayField('variant_value');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryVariantOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryVariantOption')
);
$this->addBehavior('Timestamp');
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryVariantOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryVariantOption'),
);
$this->addBehavior('Timestamp');
$this->belongsTo('ProductCategoryVariants', [
'foreignKey' => 'product_category_variant_id',
'joinType' => 'INNER',
]);
}
$this->belongsTo('ProductCategoryVariants', [
'foreignKey' => 'product_category_variant_id',
'joinType' => 'INNER',
]);
}
/**
/**
* 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
->uuid('product_category_variant_id')
->notEmptyString('product_category_variant_id');
public function validationDefault(Validator $validator): Validator {
$validator
->uuid('product_category_variant_id')
->notEmptyString('product_category_variant_id');
$validator
->scalar('variant_value')
->maxLength('variant_value', 255)
->requirePresence('variant_value', 'create')
->notEmptyString('variant_value');
$validator
->scalar('variant_value')
->maxLength('variant_value', 255)
->requirePresence('variant_value', 'create')
->notEmptyString('variant_value');
$validator
->scalar('variant_label')
->maxLength('variant_label', 255)
->allowEmptyString('variant_label');
$validator
->scalar('variant_label')
->maxLength('variant_label', 255)
->allowEmptyString('variant_label');
$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->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']);
$rules->add($rules->isUnique(['variant_value', 'product_category_variant_id']));
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']);
$rules->add($rules->isUnique(['variant_value', 'product_category_variant_id']));
return $rules;
}
return $rules;
}
}
+93 -104
View File
@@ -4,17 +4,10 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Query;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductCategoryVariant;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductCategoryVariants Model
@@ -22,143 +15,139 @@ use Psr\SimpleCache\CacheInterface;
* @property ProductCategoriesTable&BelongsTo $ProductCategories
* @property ProductsTable&BelongsTo $Products
*
* @method ProductCategoryVariant newEmptyEntity()
* @method ProductCategoryVariant newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryVariant newEmptyEntity()
* @method \CakeProducts\Model\Entity\ProductCategoryVariant newEntity()
* @method array<ProductCategoryVariant> newEntities(array $data, array $options = [])
* @method ProductCategoryVariant get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductCategoryVariant findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductCategoryVariant patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryVariant get()
* @method \CakeProducts\Model\Entity\ProductCategoryVariant findOrCreate()
* @method \CakeProducts\Model\Entity\ProductCategoryVariant patchEntity()
* @method array<ProductCategoryVariant> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCategoryVariant|false save(EntityInterface $entity, array $options = [])
* @method ProductCategoryVariant saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ProductCategoryVariant saveOrFail()
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant> deleteManyOrFail(iterable $entities, array $options = [])
*/
class ProductCategoryVariantsTable extends Table
{
/**
class ProductCategoryVariantsTable 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('product_category_variants');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->setTable('product_category_variants');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryVariants.entity', 'CakeProducts\Model\Entity\ProductCategoryVariant')
);
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategoryVariants.entity', 'CakeProducts\Model\Entity\ProductCategoryVariant'),
);
$this->belongsTo('ProductCategories', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategories',
]);
$this->belongsTo('Products', [
'foreignKey' => 'product_id',
'className' => 'CakeProducts.Products',
]);
$this->hasMany('ProductCategoryVariantOptions', [
'foreignKey' => 'product_category_variant_id',
'className' => 'CakeProducts.ProductCategoryVariantOptions',
'dependent' => true,
'cascadeCallbacks' => true,
'saveStrategy' => 'replace',
]);
$this->belongsTo('ProductCategories', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategories',
]);
$this->belongsTo('Products', [
'foreignKey' => 'product_id',
'className' => 'CakeProducts.Products',
]);
$this->hasMany('ProductCategoryVariantOptions', [
'foreignKey' => 'product_category_variant_id',
'className' => 'CakeProducts.ProductCategoryVariantOptions',
'dependent' => true,
'cascadeCallbacks' => true,
'saveStrategy' => 'replace',
]);
$this->hasMany('ProductVariants', [
'foreignKey' => 'product_category_variant_id',
'className' => 'CakeProducts.ProductVariants',
'dependent' => true,
'cascadeCallbacks' => true,
]);
}
$this->hasMany('ProductVariants', [
'foreignKey' => 'product_category_variant_id',
'className' => 'CakeProducts.ProductVariants',
'dependent' => true,
'cascadeCallbacks' => true,
]);
}
/**
/**
* 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')
->allowEmptyString('product_category_id');
$validator
->uuid('product_category_id')
->allowEmptyString('product_category_id');
$validator
->uuid('product_id')
->allowEmptyString('product_id');
$validator
->uuid('product_id')
->allowEmptyString('product_id');
$validator
->boolean('is_system_variant')
->allowEmptyString('is_system_variant');
$validator
->boolean('is_system_variant')
->allowEmptyString('is_system_variant');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
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(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_category_id']);
$rules->add($rules->isUnique(['name', 'product_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_id']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_category_id']);
$rules->add($rules->isUnique(['name', 'product_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_id']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
return $rules;
}
return $rules;
}
/**
* @param SelectQuery $query
/**
* @param \Cake\ORM\Query\SelectQuery $query
* @param string $internalCategoryId
*
* @return array|Query|SelectQuery
* @return Query|\Cake\ORM\Query\SelectQuery|array
*/
public function findAllCategoryVariantsForCategoryId(SelectQuery $query, string $internalCategoryId)
{
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
public function findAllCategoryVariantsForCategoryId(SelectQuery $query, string $internalCategoryId) {
$category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail();
$this->ProductCategories->behaviors()->get('Tree')->setConfig([
'scope' => [
'product_catalog_id' => $category->product_catalog_id ?? 1,
],
]);
$this->ProductCategories->behaviors()->get('Tree')->setConfig([
'scope' => [
'product_catalog_id' => $category->product_catalog_id ?? 1,
],
]);
return $this->ProductCategories
->find('path', for: $category->id)
->contain(['ProductCategoryVariants']);
}
return $this->ProductCategories
->find('path', for: $category->id)
->contain(['ProductCategoryVariants']);
}
/**
/**
* @param string $internalCategoryId
* @return array
*/
public function getAllCategoryVariantsForCategoryId(string $internalCategoryId)
{
return $this->find('allCategoryVariantsForCategoryId', $internalCategoryId)->toArray();
}
public function getAllCategoryVariantsForCategoryId(string $internalCategoryId) {
return $this->find('allCategoryVariantsForCategoryId', $internalCategoryId)->toArray();
}
}
+106 -115
View File
@@ -4,16 +4,9 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Behavior\TimestampBehavior;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductPhoto;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductPhotos Model
@@ -21,15 +14,15 @@ use Psr\SimpleCache\CacheInterface;
* @property ProductsTable&BelongsTo $Products
* @property ProductSkusTable&BelongsTo $ProductSkus
*
* @method ProductPhoto newEmptyEntity()
* @method ProductPhoto newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductPhoto newEmptyEntity()
* @method \CakeProducts\Model\Entity\ProductPhoto newEntity()
* @method array<ProductPhoto> newEntities(array $data, array $options = [])
* @method ProductPhoto get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductPhoto findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductPhoto patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductPhoto get()
* @method \CakeProducts\Model\Entity\ProductPhoto findOrCreate()
* @method \CakeProducts\Model\Entity\ProductPhoto patchEntity()
* @method array<ProductPhoto> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductPhoto|false save(EntityInterface $entity, array $options = [])
* @method ProductPhoto saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ProductPhoto saveOrFail()
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto>|false deleteMany(iterable $entities, array $options = [])
@@ -37,136 +30,134 @@ use Psr\SimpleCache\CacheInterface;
*
* @mixin TimestampBehavior
*/
class ProductPhotosTable extends Table
{
/**
class ProductPhotosTable 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('product_photos');
$this->setDisplayField('photo_filename');
$this->setPrimaryKey('id');
$this->setTable('product_photos');
$this->setDisplayField('photo_filename');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductPhotos.entity', 'CakeProducts\Model\Entity\ProductPhoto')
);
$this->setEntityClass(
Configure::read('CakeProducts.ProductPhotos.entity', 'CakeProducts\Model\Entity\ProductPhoto'),
);
$this->addBehavior('Timestamp');
$this->addBehavior('Timestamp');
$this->addBehavior('Tools.Toggle', [
'field' => 'primary_category_photo',
'scopeFields' => ['product_category_id'],
'scope' => [
'deleted IS' => null,
],
]);
$this->addBehavior('CakeProducts.SecondToggle', [
'field' => 'primary_photo',
'scopeFields' => ['product_id'],
'scope' => [
'deleted IS' => null,
'product_id IS NOT' => null,
],
]);
$this->addBehavior('CakeProducts.ThirdToggle', [
'field' => 'primary_sku_photo',
'scopeFields' => ['product_sku_id'],
'scope' => [
'deleted IS' => null,
'product_sku_id IS NOT' => null,
],
]);
$this->belongsTo('Products', [
'foreignKey' => 'product_id',
'joinType' => 'LEFT',
'className' => 'CakeProducts.Products',
]);
$this->addBehavior('Tools.Toggle', [
'field' => 'primary_category_photo',
'scopeFields' => ['product_category_id'],
'scope' => [
'deleted IS' => null,
],
]);
$this->addBehavior('CakeProducts.SecondToggle', [
'field' => 'primary_photo',
'scopeFields' => ['product_id'],
'scope' => [
'deleted IS' => null,
'product_id IS NOT' => null,
],
]);
$this->addBehavior('CakeProducts.ThirdToggle', [
'field' => 'primary_sku_photo',
'scopeFields' => ['product_sku_id'],
'scope' => [
'deleted IS' => null,
'product_sku_id IS NOT' => null,
],
]);
$this->belongsTo('Products', [
'foreignKey' => 'product_id',
'joinType' => 'LEFT',
'className' => 'CakeProducts.Products',
]);
$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->belongsTo('ProductSkus', [
'foreignKey' => 'product_sku_id',
'joinType' => 'LEFT',
'className' => 'CakeProducts.ProductSkus',
]);
}
$this->belongsTo('ProductSkus', [
'foreignKey' => 'product_sku_id',
'joinType' => 'LEFT',
'className' => 'CakeProducts.ProductSkus',
]);
}
/**
/**
* 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
->uuid('product_id')
->allowEmptyString('product_id');
public function validationDefault(Validator $validator): Validator {
$validator
->uuid('product_id')
->allowEmptyString('product_id');
$validator
->uuid('product_sku_id')
->allowEmptyString('product_sku_id');
$validator
->uuid('product_sku_id')
->allowEmptyString('product_sku_id');
$validator
->uuid('product_category_id')
->requirePresence('product_category_id', 'create')
->notEmptyString('product_category_id');
$validator
->uuid('product_category_id')
->requirePresence('product_category_id', 'create')
->notEmptyString('product_category_id');
$validator
->scalar('photo_dir')
->maxLength('photo_dir', 255)
->requirePresence('photo_dir', 'create')
->notEmptyString('photo_dir');
$validator
->scalar('photo_dir')
->maxLength('photo_dir', 255)
->requirePresence('photo_dir', 'create')
->notEmptyString('photo_dir');
$validator
->scalar('photo_filename')
->maxLength('photo_filename', 255)
->requirePresence('photo_filename', 'create')
->notEmptyString('photo_filename');
$validator
->scalar('photo_filename')
->maxLength('photo_filename', 255)
->requirePresence('photo_filename', 'create')
->notEmptyString('photo_filename');
$validator
->boolean('primary_photo')
->notEmptyString('primary_photo');
$validator
->boolean('primary_photo')
->notEmptyString('primary_photo');
$validator
->integer('photo_position')
->notEmptyString('photo_position');
$validator
->integer('photo_position')
->notEmptyString('photo_position');
$validator
->boolean('enabled')
->notEmptyString('enabled');
$validator
->boolean('enabled')
->notEmptyString('enabled');
$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->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
return $rules;
}
return $rules;
}
}
@@ -3,16 +3,9 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table;
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\ProductSkuVariantValue;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductSkuVariantValues Model
@@ -21,92 +14,90 @@ use Psr\SimpleCache\CacheInterface;
* @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants
* @property ProductCategoryVariantOptionsTable&BelongsTo $ProductCategoryVariantOptions
*
* @method ProductSkuVariantValue newEmptyEntity()
* @method ProductSkuVariantValue newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue newEmptyEntity()
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue newEntity()
* @method array<ProductSkuVariantValue> newEntities(array $data, array $options = [])
* @method ProductSkuVariantValue get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductSkuVariantValue findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductSkuVariantValue patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue get()
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue findOrCreate()
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue patchEntity()
* @method array<ProductSkuVariantValue> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductSkuVariantValue|false save(EntityInterface $entity, array $options = [])
* @method ProductSkuVariantValue saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ProductSkuVariantValue saveOrFail()
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductSkuVariantValue>|ResultSetInterface<ProductSkuVariantValue> deleteManyOrFail(iterable $entities, array $options = [])
*/
class ProductSkuVariantValuesTable extends Table
{
/**
class ProductSkuVariantValuesTable 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('product_sku_variant_values');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->setTable('product_sku_variant_values');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->belongsTo('ProductSkus', [
'className' => 'CakeProducts.ProductSkus',
'foreignKey' => 'product_sku_id',
'propertyName' => 'product_sku',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductVariants', [
'className' => 'CakeProducts.ProductVariants',
'foreignKey' => 'product_variant_id',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductCategoryVariantOptions', [
'className' => 'CakeProducts.ProductCategoryVariantOptions',
'foreignKey' => 'product_category_variant_option_id',
'joinType' => 'INNER',
]);
}
$this->belongsTo('ProductSkus', [
'className' => 'CakeProducts.ProductSkus',
'foreignKey' => 'product_sku_id',
'propertyName' => 'product_sku',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductVariants', [
'className' => 'CakeProducts.ProductVariants',
'foreignKey' => 'product_variant_id',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductCategoryVariantOptions', [
'className' => 'CakeProducts.ProductCategoryVariantOptions',
'foreignKey' => 'product_category_variant_option_id',
'joinType' => 'INNER',
]);
}
/**
/**
* 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
->uuid('product_sku_id')
->notEmptyString('product_sku_id');
public function validationDefault(Validator $validator): Validator {
$validator
->uuid('product_sku_id')
->notEmptyString('product_sku_id');
$validator
->uuid('product_variant_id')
->notEmptyString('product_variant_id');
$validator
->uuid('product_variant_id')
->notEmptyString('product_variant_id');
$validator
->uuid('product_category_variant_option_id')
->notEmptyString('product_category_variant_option_id');
$validator
->uuid('product_category_variant_option_id')
->notEmptyString('product_category_variant_option_id');
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->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
// @TODO why not working?? causing tests to fail / associated variant values not saving on product-skus/add
$rules->add($rules->existsIn(['product_variant_id'], 'ProductVariants'), ['errorField' => 'product_variant_id']);
$rules->add($rules->existsIn(['product_category_variant_option_id'], 'ProductCategoryVariantOptions'), ['errorField' => 'product_category_variant_option_id']);
// @TODO why not working?? causing tests to fail / associated variant values not saving on product-skus/add
$rules->add($rules->existsIn(['product_variant_id'], 'ProductVariants'), ['errorField' => 'product_variant_id']);
$rules->add($rules->existsIn(['product_category_variant_option_id'], 'ProductCategoryVariantOptions'), ['errorField' => 'product_category_variant_option_id']);
return $rules;
}
return $rules;
}
}
+86 -97
View File
@@ -4,33 +4,24 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use Cake\ORM\Query\SelectQuery;
use CakeProducts\Model\Table\ProductsTable;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Behavior\TimestampBehavior;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductSku;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductSkus Model
*
* @property ProductsTable&BelongsTo $Products
*
* @method ProductSku newEmptyEntity()
* @method ProductSku newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductSku newEmptyEntity()
* @method \CakeProducts\Model\Entity\ProductSku newEntity()
* @method array<ProductSku> newEntities(array $data, array $options = [])
* @method ProductSku get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductSku findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductSku patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductSku get()
* @method \CakeProducts\Model\Entity\ProductSku findOrCreate()
* @method \CakeProducts\Model\Entity\ProductSku patchEntity()
* @method array<ProductSku> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductSku|false save(EntityInterface $entity, array $options = [])
* @method ProductSku saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ProductSku saveOrFail()
* @method iterable<ProductSku>|ResultSetInterface<ProductSku>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductSku>|ResultSetInterface<ProductSku> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductSku>|ResultSetInterface<ProductSku>|false deleteMany(iterable $entities, array $options = [])
@@ -38,114 +29,112 @@ use Psr\SimpleCache\CacheInterface;
*
* @mixin TimestampBehavior
*/
class ProductSkusTable extends Table
{
/**
class ProductSkusTable 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('product_skus');
$this->setDisplayField('sku');
$this->setPrimaryKey('id');
$this->setTable('product_skus');
$this->setDisplayField('sku');
$this->setPrimaryKey('id');
$this->setEntityClass(
Configure::read('CakeProducts.ProductSkus.entity', 'CakeProducts\Model\Entity\ProductSku')
);
$this->setEntityClass(
Configure::read('CakeProducts.ProductSkus.entity', 'CakeProducts\Model\Entity\ProductSku'),
);
$this->addBehavior('Timestamp');
$this->addBehavior('Tools.Toggle', [
'field' => 'default_sku',
'scopeFields' => ['product_id'],
'scope' => [
'deleted IS' => null,
],
]);
$this->addBehavior('Timestamp');
$this->addBehavior('Tools.Toggle', [
'field' => 'default_sku',
'scopeFields' => ['product_id'],
'scope' => [
'deleted IS' => null,
],
]);
$this->belongsTo('Products', [
'className' => 'CakeProducts.Products',
'foreignKey' => 'product_id',
'joinType' => 'INNER',
]);
$this->belongsTo('Products', [
'className' => 'CakeProducts.Products',
'foreignKey' => 'product_id',
'joinType' => 'INNER',
]);
$this->hasMany('ProductSkuVariantValues', [
'foreignKey' => 'product_sku_id',
'className' => 'CakeProducts.ProductSkuVariantValues',
'saveStrategy' => 'replace',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductSkuVariantValues', [
'foreignKey' => 'product_sku_id',
'className' => 'CakeProducts.ProductSkuVariantValues',
'saveStrategy' => 'replace',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductPhotos', [
'foreignKey' => 'product_sku_id',
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductPhotos', [
'foreignKey' => 'product_sku_id',
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasOne('PrimaryProductPhotos', [
'foreignKey' => 'product_sku_id',
'conditions' => ['PrimaryProductPhotos.primary_photo' => true],
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
]);
}
$this->hasOne('PrimaryProductPhotos', [
'foreignKey' => 'product_sku_id',
'conditions' => ['PrimaryProductPhotos.primary_photo' => true],
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
]);
}
/**
/**
* 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
->uuid('product_id')
->notEmptyString('product_id');
public function validationDefault(Validator $validator): Validator {
$validator
->uuid('product_id')
->notEmptyString('product_id');
$validator
->scalar('sku')
->maxLength('sku', 255)
->requirePresence('sku', 'create')
->notEmptyString('sku');
$validator
->scalar('sku')
->maxLength('sku', 255)
->requirePresence('sku', 'create')
->notEmptyString('sku');
$validator
->scalar('barcode')
->maxLength('barcode', 255)
->allowEmptyString('barcode');
$validator
->scalar('barcode')
->maxLength('barcode', 255)
->allowEmptyString('barcode');
$validator
->decimal('price')
->allowEmptyString('price');
$validator
->decimal('price')
->allowEmptyString('price');
$validator
->decimal('cost')
->allowEmptyString('cost');
$validator
->decimal('cost')
->allowEmptyString('cost');
$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->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$rules->add($rules->isUnique(['sku'], 'SKU must be unique'), ['errorField' => 'sku']);
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$rules->add($rules->isUnique(['sku'], 'SKU must be unique'), ['errorField' => 'sku']);
return $rules;
}
return $rules;
}
}
+60 -71
View File
@@ -3,18 +3,9 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table;
use CakeProducts\Model\Entity\ProductVariant;
use CakeProducts\Model\Table\ProductCategoryVariantsTable;
use CakeProducts\Model\Table\ProductsTable;
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 Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductVariants Model
@@ -22,96 +13,94 @@ use Psr\SimpleCache\CacheInterface;
* @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants
* @property ProductsTable&BelongsTo $Products
*
* @method ProductVariant newEmptyEntity()
* @method ProductVariant newEntity(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductVariant newEmptyEntity()
* @method \CakeProducts\Model\Entity\ProductVariant newEntity()
* @method array<ProductVariant> newEntities(array $data, array $options = [])
* @method ProductVariant get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductVariant findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductVariant patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductVariant get()
* @method \CakeProducts\Model\Entity\ProductVariant findOrCreate()
* @method \CakeProducts\Model\Entity\ProductVariant patchEntity()
* @method array<ProductVariant> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductVariant|false save(EntityInterface $entity, array $options = [])
* @method ProductVariant saveOrFail(EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ProductVariant saveOrFail()
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductVariant>|ResultSetInterface<ProductVariant> deleteManyOrFail(iterable $entities, array $options = [])
*/
class ProductVariantsTable extends Table
{
/**
class ProductVariantsTable 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('product_variants');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->setTable('product_variants');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->belongsTo('ProductCategoryVariants', [
'className' => 'CakeProducts.ProductCategoryVariants',
'foreignKey' => 'product_category_variant_id',
]);
$this->belongsTo('Products', [
'className' => 'CakeProducts.Products',
'foreignKey' => 'product_id',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductCategoryVariants', [
'className' => 'CakeProducts.ProductCategoryVariants',
'foreignKey' => 'product_category_variant_id',
]);
$this->belongsTo('Products', [
'className' => 'CakeProducts.Products',
'foreignKey' => 'product_id',
'joinType' => 'INNER',
]);
$this->hasMany('ProductSkuVariantValues', [
'className' => 'CakeProducts.ProductSkuVariantValues',
'foreignKey' => 'product_variant_id',
'dependent' => true,
'cascadeCallbacks' => true,
]);
}
$this->hasMany('ProductSkuVariantValues', [
'className' => 'CakeProducts.ProductSkuVariantValues',
'foreignKey' => 'product_variant_id',
'dependent' => true,
'cascadeCallbacks' => true,
]);
}
/**
/**
* 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_variant_id')
->allowEmptyString('product_category_variant_id');
$validator
->uuid('product_category_variant_id')
->allowEmptyString('product_category_variant_id');
$validator
->uuid('product_id')
->notEmptyString('product_id');
$validator
->uuid('product_id')
->notEmptyString('product_id');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
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->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']);
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
public function buildRules(RulesChecker $rules): RulesChecker {
$rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']);
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
return $rules;
}
return $rules;
}
}
+92 -101
View File
@@ -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;
}
}