bring into standalone plugin for distribution

This commit is contained in:
2024-11-24 18:38:29 -08:00
parent 279d46f14b
commit ded60d16bf
83 changed files with 7020 additions and 1 deletions

View File

@@ -0,0 +1,115 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Model\Table;
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 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 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 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 = [])
* @method iterable<ExternalProductCatalog>|ResultSetInterface<ExternalProductCatalog> deleteManyOrFail(iterable $entities, array $options = [])
*
* @mixin TimestampBehavior
*/
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);
$this->setTable('external_product_catalogs');
$this->setDisplayField('base_url');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsTo('ProductCatalogs', [
'foreignKey' => 'product_catalog_id',
'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCatalogs',
]);
}
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->uuid('product_catalog_id')
->notEmptyString('product_catalog_id');
$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');
// ->url('api_url');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
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
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => 'product_catalog_id']);
return $rules;
}
}

View File

@@ -0,0 +1,99 @@
<?php
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 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 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 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
{
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
$this->setTable('product_catalogs');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->hasMany('ProductCategories', [
'className' => 'CakeProducts.ProductCategories',
]);
$this->hasMany('ExternalProductCatalogs', [
'className' => 'CakeProducts.ExternalProductCatalogs',
]);
}
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return 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']);
$validator
->scalar('catalog_description')
->maxLength('catalog_description', 255)
->allowEmptyString('catalog_description');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
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
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->isUnique(['name']), ['errorField' => 'name']);
return $rules;
}
}

View File

@@ -0,0 +1,164 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Model\Table;
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 Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductCategories Model
*
* @property ProductCatalogsTable&BelongsTo $ProductCatalogs
* @property ProductCategoriesTable&BelongsTo $ParentProductCategories
* @property ProductCategoriesTable&HasMany $ChildProductCategories
*
* @method ProductCategory newEmptyEntity()
* @method ProductCategory newEntity(array $data, array $options = [])
* @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 array<ProductCategory> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductCategory saveOrFail(EntityInterface $entity, array $options = [])
* @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 = [])
* @method iterable<ProductCategory>|ResultSetInterface<ProductCategory> deleteManyOrFail(iterable $entities, array $options = [])
*
* @mixin TreeBehavior
*/
class ProductCategoriesTable extends Table
{
/**
* Current scope for Tree behavior - per catalog
*
* @var string
*/
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;
$this->setTable('product_categories');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->addBehavior('Tree');
$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',
]);
$this->hasMany('ProductCategoryAttributes', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategoryAttributes',
]);
$this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
}
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
*/
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('category_description')
->allowEmptyString('category_description');
$validator
->integer('parent_id')
->allowEmptyString('parent_id');
$validator
->boolean('enabled')
->notEmptyString('enabled');
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
*/
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;
}
/**
* @param int $catalogId
*
* @return void
*/
public function setConfigureCatalogId(string $catalogId)
{
$this->treeCatalogId = $catalogId;
$this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
}
/**
* @param EntityInterface $entity
* @param array $options
*
* @return EntityInterface|false
*/
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);
}
}

View File

@@ -0,0 +1,103 @@
<?php
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\ProductCategoryAttributeOption;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductCategoryAttributeOptions Model
*
* @property ProductCategoryAttributesTable&BelongsTo $ProductCategoryAttributes
*
* @method ProductCategoryAttributeOption newEmptyEntity()
* @method ProductCategoryAttributeOption newEntity(array $data, array $options = [])
* @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 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 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
{
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
$this->setTable('product_category_attribute_options');
$this->setDisplayField('attribute_value');
$this->setPrimaryKey('id');
$this->belongsTo('ProductCategoryAttributes', [
'foreignKey' => 'product_category_attribute_id',
'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCategoryAttributes',
]);
}
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->integer('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_label')
->maxLength('attribute_label', 255)
->requirePresence('attribute_label', 'create')
->notEmptyString('attribute_label');
$validator
->boolean('enabled')
->notEmptyString('enabled');
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
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => '0']);
return $rules;
}
}

View File

@@ -0,0 +1,113 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Model\Table;
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 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 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 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
{
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
$this->setTable('product_category_attributes');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$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',
]);
$this->getSchema()->setColumnType('attribute_type_id', EnumType::from(ProductCategoryAttributeTypeId::class));
}
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
*/
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
->integer('attribute_type_id')
->requirePresence('attribute_type_id', 'create')
->notEmptyString('attribute_type_id');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
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
*/
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;
}
}

View File

@@ -0,0 +1,105 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Model\Table;
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 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 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 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
{
/**
* Initialize method
*
* @param array<string, mixed> $config The configuration for the Table.
* @return void
*/
public function initialize(array $config): void
{
parent::initialize($config);
$this->setTable('products');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->belongsTo('ProductCategories', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCategories',
]);
$this->getSchema()->setColumnType('product_type_id', EnumType::from(ProductProductTypeId::class));
}
/**
* Default validation rules.
*
* @param Validator $validator Validator instance.
* @return Validator
*/
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
->integer('product_type_id')
->requirePresence('product_type_id', 'create')
->notEmptyString('product_type_id');
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
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->isUnique(['product_category_id', 'name']), ['errorField' => '0']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => '1']);
return $rules;
}
}