category photos should be working

This commit is contained in:
bs
2025-10-12 01:04:36 -07:00
parent 66db31c7ad
commit 30aad1dea4
11 changed files with 105 additions and 9 deletions
@@ -100,6 +100,27 @@ class ProductCategoriesTable extends Table
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('Products', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.Products',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductPhotos', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasOne('PrimaryProductPhotos', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'conditions' => ['PrimaryProductPhotos.primary_category_photo' => true],
'className' => 'CakeProducts.ProductPhotos',
'dependent' => true,
]);
$this->getSchema()->setColumnType('default_product_type_id', EnumType::from(ProductProductTypeId::class));
+14 -2
View File
@@ -61,10 +61,17 @@ class ProductPhotosTable extends Table
$this->belongsTo('Products', [
'foreignKey' => 'product_id',
'joinType' => 'INNER',
'joinType' => 'LEFT',
'className' => 'CakeProducts.Products',
]);
$this->belongsTo('ProductCategories', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'joinType' => 'LEFT',
'className' => 'CakeProducts.ProductCategories',
]);
$this->belongsTo('ProductSkus', [
'foreignKey' => 'product_sku_id',
'joinType' => 'LEFT',
@@ -82,12 +89,16 @@ class ProductPhotosTable extends Table
{
$validator
->uuid('product_id')
->notEmptyString('product_id');
->allowEmptyString('product_id');
$validator
->uuid('product_sku_id')
->allowEmptyString('product_sku_id');
$validator
->uuid('product_category_id')
->allowEmptyString('product_category_id');
$validator
->scalar('photo_dir')
->maxLength('photo_dir', 255)
@@ -130,6 +141,7 @@ class ProductPhotosTable extends Table
{
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
return $rules;
}