test additions variants table
This commit is contained in:
@@ -12,7 +12,7 @@ use Cake\ORM\Entity;
|
||||
* @property string $name
|
||||
* @property string|null $product_category_id
|
||||
* @property string|null $product_id
|
||||
* @property int $attribute_type_id
|
||||
* @property int $variant_type_id
|
||||
* @property bool $enabled
|
||||
*
|
||||
* @property \App\Model\Entity\ProductCategory $product_category
|
||||
@@ -33,7 +33,7 @@ class ProductCategoryVariant extends Entity
|
||||
'name' => true,
|
||||
'product_category_id' => true,
|
||||
'product_id' => true,
|
||||
'attribute_type_id' => true,
|
||||
'variant_type_id' => true,
|
||||
'enabled' => true,
|
||||
'product_category' => true,
|
||||
'product' => true,
|
||||
|
||||
21
src/Model/Enum/ProductCategoryVariantTypeId.php
Normal file
21
src/Model/Enum/ProductCategoryVariantTypeId.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace CakeProducts\Model\Enum;
|
||||
|
||||
use Cake\Database\Type\EnumLabelInterface;
|
||||
use Tools\Model\Enum\EnumOptionsTrait;
|
||||
|
||||
enum ProductCategoryVariantTypeId: int implements EnumLabelInterface
|
||||
{
|
||||
use EnumOptionsTrait;
|
||||
|
||||
case AutoAdd = 1;
|
||||
case ManualAdd = 2;
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::AutoAdd => 'All Variant Combinations Created Automatically',
|
||||
self::ManualAdd => 'Variants Manually Managed',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Table;
|
||||
|
||||
use Cake\Database\Type\EnumType;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
|
||||
use CakeProducts\Model\Enum\ProductCategoryVariantTypeId;
|
||||
|
||||
/**
|
||||
* ProductCategoryVariants Model
|
||||
@@ -53,6 +56,8 @@ class ProductCategoryVariantsTable extends Table
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.Products',
|
||||
]);
|
||||
$this->getSchema()->setColumnType('variant_type_id', EnumType::from(ProductCategoryVariantTypeId::class));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,9 +83,9 @@ class ProductCategoryVariantsTable extends Table
|
||||
->allowEmptyString('product_id');
|
||||
|
||||
$validator
|
||||
->integer('attribute_type_id')
|
||||
->requirePresence('attribute_type_id', 'create')
|
||||
->notEmptyString('attribute_type_id');
|
||||
->integer('variant_type_id')
|
||||
->requirePresence('variant_type_id', 'create')
|
||||
->notEmptyString('variant_type_id');
|
||||
|
||||
$validator
|
||||
->boolean('enabled')
|
||||
|
||||
Reference in New Issue
Block a user