product id back on product category variants table...dumb
This commit is contained in:
parent
2d405d542b
commit
5b38de39fc
|
@ -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();
|
||||
|
|
|
@ -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,
|
||||
];
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
],
|
||||
],
|
||||
|
|
Loading…
Reference in New Issue