start of variant values
This commit is contained in:
39
src/Model/Entity/ProductSkuVariantValue.php
Normal file
39
src/Model/Entity/ProductSkuVariantValue.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
* ProductSkuVariantValue Entity
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $product_sku_id
|
||||
* @property string $product_category_variant_id
|
||||
* @property string $product_category_variant_option_id
|
||||
*
|
||||
* @property ProductSku $product_sku
|
||||
* @property ProductCategoryVariant $product_category_variant
|
||||
* @property ProductCategoryVariantOption $product_category_variant_option
|
||||
*/
|
||||
class ProductSkuVariantValue 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_sku_id' => true,
|
||||
'product_category_variant_id' => true,
|
||||
'product_category_variant_option_id' => true,
|
||||
'product_skus' => true,
|
||||
'product_category_variant' => true,
|
||||
'product_category_variant_option' => true,
|
||||
];
|
||||
}
|
||||
109
src/Model/Table/ProductSkuVariantValuesTable.php
Normal file
109
src/Model/Table/ProductSkuVariantValuesTable.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?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\ProductSkuVariantValue;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductSkuVariantValues Model
|
||||
*
|
||||
* @property ProductSkusTable&BelongsTo $ProductSkus
|
||||
* @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants
|
||||
* @property ProductCategoryVariantOptionsTable&BelongsTo $ProductCategoryVariantOptions
|
||||
*
|
||||
* @method ProductSkuVariantValue newEmptyEntity()
|
||||
* @method ProductSkuVariantValue newEntity(array $data, array $options = [])
|
||||
* @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 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 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
|
||||
{
|
||||
/**
|
||||
* 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_sku_variant_values');
|
||||
$this->setDisplayField('id');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->belongsTo('ProductSkus', [
|
||||
'className' => 'CakeProducts.ProductSkus',
|
||||
'foreignKey' => 'product_sku_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
$this->belongsTo('ProductCategoryVariants', [
|
||||
'className' => 'CakeProducts.ProductCategoryVariants',
|
||||
'foreignKey' => 'product_category_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
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->uuid('product_sku_id')
|
||||
->notEmptyString('product_sku_id');
|
||||
|
||||
$validator
|
||||
->uuid('product_category_variant_id')
|
||||
->notEmptyString('product_category_variant_id');
|
||||
|
||||
$validator
|
||||
->uuid('product_category_variant_option_id')
|
||||
->notEmptyString('product_category_variant_option_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->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
|
||||
$rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']);
|
||||
$rules->add($rules->existsIn(['product_category_variant_option_id'], 'ProductCategoryVariantOptions'), ['errorField' => 'product_category_variant_option_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user