bring into standalone plugin for distribution
This commit is contained in:
41
src/Model/Entity/ExternalProductCatalog.php
Normal file
41
src/Model/Entity/ExternalProductCatalog.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
* ExternalProductCatalog Entity
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $product_catalog_id
|
||||
* @property string $base_url
|
||||
* @property string $api_url
|
||||
* @property \Cake\I18n\DateTime $created
|
||||
* @property \Cake\I18n\DateTime|null $deleted
|
||||
* @property bool $enabled
|
||||
*
|
||||
* @property \CakeProducts\Model\Entity\ProductCatalog $product_catalog
|
||||
*/
|
||||
class ExternalProductCatalog extends Entity
|
||||
{
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
* be mass assigned. For security purposes, it is advised to set '*' to false
|
||||
* (or remove it), and explicitly make individual fields accessible as needed.
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'product_catalog_id' => true,
|
||||
'base_url' => true,
|
||||
'api_url' => true,
|
||||
'created' => true,
|
||||
'deleted' => true,
|
||||
'enabled' => true,
|
||||
'product_catalog' => true,
|
||||
];
|
||||
}
|
||||
35
src/Model/Entity/Product.php
Normal file
35
src/Model/Entity/Product.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
* Product Entity
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $name
|
||||
* @property string $product_category_id
|
||||
* @property \CakeProducts\Model\Enum\ProductProductTypeId $product_type_id
|
||||
*
|
||||
* @property \CakeProducts\Model\Entity\ProductCategory $product_category
|
||||
*/
|
||||
class Product extends Entity
|
||||
{
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
* be mass assigned. For security purposes, it is advised to set '*' to false
|
||||
* (or remove it), and explicitly make individual fields accessible as needed.
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'product_category_id' => true,
|
||||
'product_type_id' => true,
|
||||
'product_category' => true,
|
||||
];
|
||||
}
|
||||
37
src/Model/Entity/ProductCatalog.php
Normal file
37
src/Model/Entity/ProductCatalog.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
* ProductCatalog Entity
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $name
|
||||
* @property string|null $catalog_description
|
||||
* @property bool $enabled
|
||||
*
|
||||
* @property \CakeProducts\Model\Entity\ProductCategory[] $product_categories
|
||||
* @property \CakeProducts\Model\Entity\ExternalProductCatalog[] $external_product_catalogs
|
||||
*/
|
||||
class ProductCatalog extends Entity
|
||||
{
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
* be mass assigned. For security purposes, it is advised to set '*' to false
|
||||
* (or remove it), and explicitly make individual fields accessible as needed.
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'catalog_description' => true,
|
||||
'enabled' => true,
|
||||
'product_categories' => true,
|
||||
'external_product_catalogs' => true,
|
||||
];
|
||||
}
|
||||
49
src/Model/Entity/ProductCategory.php
Normal file
49
src/Model/Entity/ProductCategory.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
* ProductCategory Entity
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $internal_id
|
||||
* @property string $product_catalog_id
|
||||
* @property string $name
|
||||
* @property string|null $category_description
|
||||
* @property int|null $parent_id
|
||||
* @property int $lft
|
||||
* @property int $rght
|
||||
* @property bool $enabled
|
||||
*
|
||||
* @property \CakeProducts\Model\Entity\ProductCatalog $product_catalog
|
||||
* @property \CakeProducts\Model\Entity\ParentProductCategory $parent_product_category
|
||||
* @property \CakeProducts\Model\Entity\ChildProductCategory[] $child_product_categories
|
||||
*/
|
||||
class ProductCategory extends Entity
|
||||
{
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
* be mass assigned. For security purposes, it is advised to set '*' to false
|
||||
* (or remove it), and explicitly make individual fields accessible as needed.
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'product_catalog_id' => true,
|
||||
'internal_id' => true,
|
||||
'name' => true,
|
||||
'category_description' => true,
|
||||
'parent_id' => true,
|
||||
'lft' => true,
|
||||
'rght' => true,
|
||||
'enabled' => true,
|
||||
'product_catalog' => true,
|
||||
'parent_product_category' => true,
|
||||
'child_product_categories' => true,
|
||||
];
|
||||
}
|
||||
39
src/Model/Entity/ProductCategoryAttribute.php
Normal file
39
src/Model/Entity/ProductCategoryAttribute.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
* ProductCategoryAttribute Entity
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $name
|
||||
* @property string|null $product_category_id
|
||||
* @property int $attribute_type_id
|
||||
* @property bool $enabled
|
||||
*
|
||||
* @property ProductCategory $product_category
|
||||
* @property ProductCategoryAttributeOption[] $product_category_attribute_options
|
||||
*/
|
||||
class ProductCategoryAttribute extends Entity
|
||||
{
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
* be mass assigned. For security purposes, it is advised to set '*' to false
|
||||
* (or remove it), and explicitly make individual fields accessible as needed.
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'product_category_id' => true,
|
||||
'attribute_type_id' => true,
|
||||
'enabled' => true,
|
||||
'product_category' => true,
|
||||
'product_category_attribute_options' => true,
|
||||
];
|
||||
}
|
||||
37
src/Model/Entity/ProductCategoryAttributeOption.php
Normal file
37
src/Model/Entity/ProductCategoryAttributeOption.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
* ProductCategoryAttributeOption Entity
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $product_category_attribute_id
|
||||
* @property string $attribute_value
|
||||
* @property string $attribute_label
|
||||
* @property bool $enabled
|
||||
*
|
||||
* @property ProductCategoryAttribute $product_category_attribute
|
||||
*/
|
||||
class ProductCategoryAttributeOption extends Entity
|
||||
{
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
* be mass assigned. For security purposes, it is advised to set '*' to false
|
||||
* (or remove it), and explicitly make individual fields accessible as needed.
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'product_category_attribute_id' => true,
|
||||
'attribute_value' => true,
|
||||
'attribute_label' => true,
|
||||
'enabled' => true,
|
||||
'product_category_attribute' => true,
|
||||
];
|
||||
}
|
||||
23
src/Model/Enum/ProductCategoryAttributeTypeId.php
Normal file
23
src/Model/Enum/ProductCategoryAttributeTypeId.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace CakeProducts\Model\Enum;
|
||||
|
||||
use Cake\Database\Type\EnumLabelInterface;
|
||||
use Tools\Model\Enum\EnumOptionsTrait;
|
||||
|
||||
enum ProductCategoryAttributeTypeId: int implements EnumLabelInterface
|
||||
{
|
||||
use EnumOptionsTrait;
|
||||
|
||||
case Constrained = 1;
|
||||
case Text = 2;
|
||||
case Integer = 3;
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::Constrained => 'Constrained',
|
||||
self::Text => 'Text',
|
||||
self::Integer => 'Integer'
|
||||
};
|
||||
}
|
||||
}
|
||||
23
src/Model/Enum/ProductProductTypeId.php
Normal file
23
src/Model/Enum/ProductProductTypeId.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace CakeProducts\Model\Enum;
|
||||
|
||||
use Cake\Database\Type\EnumLabelInterface;
|
||||
use Tools\Model\Enum\EnumOptionsTrait;
|
||||
|
||||
enum ProductProductTypeId: int implements EnumLabelInterface
|
||||
{
|
||||
use EnumOptionsTrait;
|
||||
|
||||
case Service = 1;
|
||||
case Product = 2;
|
||||
case Consumable = 3;
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::Service => 'Service',
|
||||
self::Product => 'Product',
|
||||
self::Consumable => 'Consumable'
|
||||
};
|
||||
}
|
||||
}
|
||||
115
src/Model/Table/ExternalProductCatalogsTable.php
Normal file
115
src/Model/Table/ExternalProductCatalogsTable.php
Normal 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;
|
||||
}
|
||||
}
|
||||
99
src/Model/Table/ProductCatalogsTable.php
Normal file
99
src/Model/Table/ProductCatalogsTable.php
Normal 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;
|
||||
}
|
||||
}
|
||||
164
src/Model/Table/ProductCategoriesTable.php
Normal file
164
src/Model/Table/ProductCategoriesTable.php
Normal 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);
|
||||
}
|
||||
}
|
||||
103
src/Model/Table/ProductCategoryAttributeOptionsTable.php
Normal file
103
src/Model/Table/ProductCategoryAttributeOptionsTable.php
Normal 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;
|
||||
}
|
||||
}
|
||||
113
src/Model/Table/ProductCategoryAttributesTable.php
Normal file
113
src/Model/Table/ProductCategoryAttributesTable.php
Normal 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;
|
||||
}
|
||||
}
|
||||
105
src/Model/Table/ProductsTable.php
Normal file
105
src/Model/Table/ProductsTable.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user