remove variant type id (enum) from variants table, use internal id for category field on variants form
CI / testsuite (mysql, 8.1, ) (push) Failing after 0s Details
CI / testsuite (mysql, 8.4, ) (push) Failing after 0s Details
CI / testsuite (pgsql, 8.1, ) (push) Failing after 0s Details
CI / testsuite (pgsql, 8.4, ) (push) Failing after 0s Details
CI / testsuite (sqlite, 8.1, ) (push) Failing after 0s Details
CI / testsuite (sqlite, 8.1, prefer-lowest) (push) Failing after 0s Details
CI / testsuite (sqlite, 8.4, ) (push) Failing after 0s Details
CI / Coding Standard & Static Analysis (push) Failing after 0s Details

This commit is contained in:
Brandon Shipley 2025-06-30 21:25:47 -07:00
parent 5fb215c7fd
commit c9d34f7115
Signed by: bmfs
GPG Key ID: 14E38571D8BB0DE4
8 changed files with 10 additions and 52 deletions

View File

@ -32,11 +32,6 @@ class CreateProductCategoryVariants extends AbstractMigration
'default' => null, 'default' => null,
'null' => true, 'null' => true,
]); ]);
$table->addColumn('variant_type_id', 'integer', [
'default' => null,
'limit' => 11,
'null' => false,
]);
$table->addColumn('enabled', 'boolean', [ $table->addColumn('enabled', 'boolean', [
'default' => null, 'default' => null,
'null' => false, 'null' => false,

View File

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

View File

@ -3,6 +3,7 @@ declare(strict_types=1);
namespace CakeProducts\Model\Entity; namespace CakeProducts\Model\Entity;
use Cake\Datasource\EntityInterface;
use Cake\ORM\Entity; use Cake\ORM\Entity;
/** /**
@ -12,11 +13,10 @@ use Cake\ORM\Entity;
* @property string $name * @property string $name
* @property string|null $product_category_id * @property string|null $product_category_id
* @property string|null $product_id * @property string|null $product_id
* @property int $variant_type_id
* @property bool $enabled * @property bool $enabled
* *
* @property \App\Model\Entity\ProductCategory $product_category * @property ProductCategory|EntityInterface $product_category
* @property \App\Model\Entity\Product $product * @property Product|EntityInterface $product
*/ */
class ProductCategoryVariant extends Entity class ProductCategoryVariant extends Entity
{ {
@ -33,9 +33,9 @@ class ProductCategoryVariant extends Entity
'name' => true, 'name' => true,
'product_category_id' => true, 'product_category_id' => true,
'product_id' => true, 'product_id' => true,
'variant_type_id' => true,
'enabled' => true, 'enabled' => true,
'product_category' => true, // entities
'product' => true, '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; namespace CakeProducts\Model\Table;
use Cake\Database\Type\EnumType;
use Cake\ORM\Query\SelectQuery; use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker; use Cake\ORM\RulesChecker;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
use CakeProducts\Model\Enum\ProductCategoryVariantTypeId;
/** /**
* ProductCategoryVariants Model * ProductCategoryVariants Model
@ -56,8 +53,6 @@ class ProductCategoryVariantsTable extends Table
'foreignKey' => 'product_id', 'foreignKey' => 'product_id',
'className' => 'CakeProducts.Products', 'className' => 'CakeProducts.Products',
]); ]);
$this->getSchema()->setColumnType('variant_type_id', EnumType::from(ProductCategoryVariantTypeId::class));
} }
/** /**
@ -82,11 +77,6 @@ class ProductCategoryVariantsTable extends Table
->uuid('product_id') ->uuid('product_id')
->allowEmptyString('product_id'); ->allowEmptyString('product_id');
$validator
->integer('variant_type_id')
->requirePresence('variant_type_id', 'create')
->notEmptyString('variant_type_id');
$validator $validator
->boolean('enabled') ->boolean('enabled')
->requirePresence('enabled', 'create') ->requirePresence('enabled', 'create')

View File

@ -6,6 +6,5 @@
echo $this->Form->control('name'); echo $this->Form->control('name');
echo $this->Form->control('product_category_id', ['options' => $productCategories, 'empty' => true]); echo $this->Form->control('product_category_id', ['options' => $productCategories, 'empty' => true]);
echo $this->Form->control('product_id', ['options' => $products, 'empty' => true]); echo $this->Form->control('product_id', ['options' => $products, 'empty' => true]);
echo $this->Form->control('variant_type_id');
echo $this->Form->control('enabled'); echo $this->Form->control('enabled');
?> ?>

View File

@ -23,7 +23,6 @@ class ProductCategoryVariantsFixture extends TestFixture
'name' => 'Color', 'name' => 'Color',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'product_id' => null, 'product_id' => null,
'variant_type_id' => 1,
'enabled' => 1, 'enabled' => 1,
], ],
[ [
@ -31,9 +30,9 @@ class ProductCategoryVariantsFixture extends TestFixture
'name' => 'Color', 'name' => 'Color',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'variant_type_id' => 1,
'enabled' => 1, 'enabled' => 1,
], ],
]; ];
parent::init(); parent::init();
} }

View File

@ -152,7 +152,6 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest
$data = [ $data = [
'name' => 'Size', 'name' => 'Size',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'variant_type_id' => 1,
'enabled' => true, 'enabled' => true,
]; ];
$this->post($url, $data); $this->post($url, $data);
@ -186,7 +185,6 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest
$data = [ $data = [
'name' => '', 'name' => '',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'variant_type_id' => 1,
'enabled' => true, 'enabled' => true,
]; ];
$this->post($url, $data); $this->post($url, $data);
@ -246,7 +244,6 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest
// test new data here // test new data here
'name' => 'updated name', 'name' => 'updated name',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'variant_type_id' => 1,
'enabled' => true, 'enabled' => true,
]; ];
$this->put($url, $data); $this->put($url, $data);
@ -282,7 +279,6 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest
$data = [ $data = [
'name' => '', 'name' => '',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'variant_type_id' => 1,
'enabled' => true, 'enabled' => true,
]; ];
$this->put($url, $data); $this->put($url, $data);