remove variant type id (enum) from variants table, use internal id for category field on variants form

This commit is contained in:
2025-06-30 21:25:47 -07:00
parent 5fb215c7fd
commit c9d34f7115
8 changed files with 10 additions and 52 deletions

View File

@@ -74,7 +74,7 @@ class ProductCategoryVariantsController extends AppController
}
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
}
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list')->all();
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
$products = $productCategoryVariantsTable->Products->find('list')->all();
$this->set(compact('productCategoryVariant', 'productCategories', 'products'));
}
@@ -99,8 +99,8 @@ class ProductCategoryVariantsController extends AppController
}
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
}
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list', limit: 200)->all();
$products = $productCategoryVariantsTable->Products->find('list', limit: 200)->all();
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
$products = $productCategoryVariantsTable->Products->find('list', limit: 200)->where(['product_category_id' => $productCategoryVariant->product_category_id])->all();
$this->set(compact('productCategoryVariant', 'productCategories', 'products'));
}

View File

@@ -3,6 +3,7 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity;
use Cake\Datasource\EntityInterface;
use Cake\ORM\Entity;
/**
@@ -12,11 +13,10 @@ use Cake\ORM\Entity;
* @property string $name
* @property string|null $product_category_id
* @property string|null $product_id
* @property int $variant_type_id
* @property bool $enabled
*
* @property \App\Model\Entity\ProductCategory $product_category
* @property \App\Model\Entity\Product $product
* @property ProductCategory|EntityInterface $product_category
* @property Product|EntityInterface $product
*/
class ProductCategoryVariant extends Entity
{
@@ -33,9 +33,9 @@ class ProductCategoryVariant extends Entity
'name' => true,
'product_category_id' => true,
'product_id' => true,
'variant_type_id' => true,
'enabled' => true,
'product_category' => true,
'product' => true,
// entities
'product_category' => false,
'product' => false,
];
}

View File

@@ -1,21 +0,0 @@
<?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',
};
}
}

View File

@@ -3,13 +3,10 @@ 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
@@ -56,8 +53,6 @@ class ProductCategoryVariantsTable extends Table
'foreignKey' => 'product_id',
'className' => 'CakeProducts.Products',
]);
$this->getSchema()->setColumnType('variant_type_id', EnumType::from(ProductCategoryVariantTypeId::class));
}
/**
@@ -82,11 +77,6 @@ class ProductCategoryVariantsTable extends Table
->uuid('product_id')
->allowEmptyString('product_id');
$validator
->integer('variant_type_id')
->requirePresence('variant_type_id', 'create')
->notEmptyString('variant_type_id');
$validator
->boolean('enabled')
->requirePresence('enabled', 'create')