product id back on product category variants table...dumb
CI / testsuite (mysql, 8.2, ) (push) Successful in 10m53s Details
CI / testsuite (mysql, 8.4, ) (push) Successful in 10m18s Details
CI / testsuite (sqlite, 8.2, prefer-lowest) (push) Failing after 6m9s Details
CI / Coding Standard & Static Analysis (push) Failing after 5m56s Details

This commit is contained in:
Brandon Shipley 2025-09-22 21:51:52 -07:00
parent 2d405d542b
commit 5b38de39fc
Signed by: bmfs
GPG Key ID: 14E38571D8BB0DE4
4 changed files with 22 additions and 3 deletions

View File

@ -28,6 +28,10 @@ class CreateProductCategoryVariants extends AbstractMigration
'default' => null,
'null' => true,
]);
$table->addColumn('product_id', 'uuid', [
'default' => null,
'null' => true,
]);
$table->addColumn('enabled', 'boolean', [
'default' => null,
'null' => false,
@ -38,12 +42,18 @@ class CreateProductCategoryVariants extends AbstractMigration
'name' => 'VARIANTS_BY_PRODUCT_CATEGORY_ID',
'unique' => false,
]);
$table->addIndex([
'product_id',
], [
'name' => 'VARIANTS_BY_PRODUCT_ID',
'unique' => false,
]);
// $table->addIndex([
// 'name',
// 'product_category_id',
// 'product_id',
// ], [
// 'name' => 'VARIANTS_BY_NAME_AND_PRODUCT_CATEGORY_ID_UNIQUE',
// 'name' => 'VARIANTS_BY_NAME_AND_PRODUCT_CATEGORY_ID_AND_PRODUCT_ID_UNIQUE',
// 'unique' => true,
// ]);
$table->create();

View File

@ -12,6 +12,7 @@ use Cake\ORM\Entity;
* @property string $id
* @property string $name
* @property string|null $product_category_id
* @property string|null $product_id
* @property bool $enabled
*
* @property ProductCategory|EntityInterface $product_category
@ -31,10 +32,12 @@ class ProductCategoryVariant extends Entity
protected array $_accessible = [
'name' => true,
'product_category_id' => true,
'product_id' => true,
'enabled' => true,
// entities
'product_category' => false,
'product' => false,
'product_category_variant_options' => true,
];
}

View File

@ -61,6 +61,10 @@ class ProductCategoryVariantsTable extends Table
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategories',
]);
$this->belongsTo('Products', [
'foreignKey' => 'product_id',
'className' => 'CakeProducts.Products',
]);
$this->hasMany('ProductCategoryVariantOptions', [
'foreignKey' => 'product_category_variant_id',
'className' => 'CakeProducts.ProductCategoryVariantOptions',
@ -109,7 +113,9 @@ class ProductCategoryVariantsTable extends Table
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_category_id']);
$rules->add($rules->isUnique(['name', 'product_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_id']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
return $rules;
}

View File

@ -180,7 +180,7 @@ class ProductSkusControllerTest extends BaseControllerTest
'cost' => 1.5,
'product_sku_variant_values' => [
0 => [
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
'product_category_variant_option_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d26',
],
],