add soft delete via muffin/trash to all product related tables

This commit is contained in:
2025-04-08 01:30:40 -07:00
parent 013bec1b54
commit cf7c67763c
33 changed files with 188 additions and 11 deletions

View File

@@ -71,6 +71,8 @@ class ExternalProductCatalogsProductCatalogsTable extends Table
// 'foreignKey' => 'product_catalog_id',
'joinType' => 'INNER',
]);
$this->addBehavior('Muffin/Trash.Trash');
}
/**
@@ -92,6 +94,10 @@ class ExternalProductCatalogsProductCatalogsTable extends Table
$validator
->boolean('enabled');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator;
}

View File

@@ -67,7 +67,11 @@ class ExternalProductCatalogsTable extends Table
$this->hasMany('ExternalProductCatalogsProductCatalogs', [
'foreignKey' => 'external_product_catalog_id',
'className' => 'CakeProducts.ExternalProductCatalogsProductCatalogs',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->addBehavior('Muffin/Trash.Trash');
}
/**

View File

@@ -63,6 +63,7 @@ class ProductAttributesTable extends Table
'foreignKey' => 'product_category_attribute_option_id',
'className' => 'CakeProducts.ProductCategoryAttributeOptions',
]);
}
/**
@@ -90,6 +91,10 @@ class ProductAttributesTable extends Table
->uuid('product_category_attribute_option_id')
->allowEmptyString('product_category_attribute_option_id');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator;
}

View File

@@ -57,6 +57,8 @@ class ProductCatalogsTable extends Table
'through' => 'ExternalProductCatalogsProductCatalogs',
'className' => 'CakeProducts.ExternalProductCatalogs',
]);
$this->addBehavior('Muffin/Trash.Trash');
}
/**
@@ -84,6 +86,10 @@ class ProductCatalogsTable extends Table
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator;
}

View File

@@ -65,7 +65,9 @@ class ProductCategoriesTable extends Table
$this->setEntityClass(
Configure::read('CakeProducts.ProductCategories.entity', 'CakeProducts\Model\Entity\ProductCategory')
);
$this->addBehavior('Tree');
$this->addBehavior('Tree', [
'cascadeCallbacks' => true,
]);
$this->belongsTo('ProductCatalogs', [
'foreignKey' => 'product_catalog_id',
@@ -79,13 +81,18 @@ class ProductCategoriesTable extends Table
$this->hasMany('ChildProductCategories', [
'className' => 'CakeProducts.ProductCategories',
'foreignKey' => 'parent_id',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->hasMany('ProductCategoryAttributes', [
'foreignKey' => 'product_category_id',
'bindingKey' => 'internal_id',
'className' => 'CakeProducts.ProductCategoryAttributes',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]);
$this->addBehavior('Muffin/Trash.Trash');
}
/**
@@ -118,6 +125,10 @@ class ProductCategoriesTable extends Table
->boolean('enabled')
->notEmptyString('enabled');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator;
}

View File

@@ -54,6 +54,8 @@ class ProductCategoryAttributeOptionsTable extends Table
'joinType' => 'INNER',
'className' => 'CakeProducts.ProductCategoryAttributes',
]);
$this->addBehavior('Muffin/Trash.Trash');
}
/**
@@ -84,6 +86,10 @@ class ProductCategoryAttributeOptionsTable extends Table
->boolean('enabled')
->notEmptyString('enabled');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator;
}

View File

@@ -61,8 +61,12 @@ class ProductCategoryAttributesTable extends Table
'foreignKey' => 'product_category_attribute_id',
'className' => 'CakeProducts.ProductCategoryAttributeOptions',
'saveStrategy' => 'replace',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->getSchema()->setColumnType('attribute_type_id', EnumType::from(ProductCategoryAttributeTypeId::class));
$this->addBehavior('Muffin/Trash.Trash');
}
/**
@@ -93,6 +97,10 @@ class ProductCategoryAttributesTable extends Table
->requirePresence('enabled', 'create')
->notEmptyString('enabled');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator;
}

View File

@@ -60,9 +60,12 @@ class ProductsTable extends Table
$this->hasMany('ProductAttributes', [
'className' => 'CakeProducts.ProductAttributes',
'dependent' => true,
'cascadeCallbacks' => true,
]);
$this->getSchema()->setColumnType('product_type_id', EnumType::from(ProductProductTypeId::class));
$this->addBehavior('Muffin/Trash.Trash');
}
/**
@@ -88,6 +91,10 @@ class ProductsTable extends Table
->requirePresence('product_type_id', 'create')
->notEmptyString('product_type_id');
$validator
->dateTime('deleted')
->allowEmptyDateTime('deleted');
return $validator;
}