add soft delete via muffin/trash to all product related tables
This commit is contained in:
@@ -141,6 +141,11 @@ class ProductCategoriesController extends AppController
|
||||
$productCategoriesTable = $this->getTable();
|
||||
|
||||
$productCategory = $productCategoriesTable->get($id);
|
||||
// $productCategoriesTable->behaviors()->get('Tree')->setConfig([
|
||||
// 'scope' => [
|
||||
// 'product_catalog_id' => $productCategory->product_catalog_id,
|
||||
// ],
|
||||
// ]);
|
||||
if ($productCategoriesTable->delete($productCategory)) {
|
||||
$this->Flash->success(__('The product category has been deleted.'));
|
||||
} else {
|
||||
|
||||
@@ -14,6 +14,7 @@ use Cake\ORM\Entity;
|
||||
* @property string $product_catalog_id
|
||||
* @property DateTime $created
|
||||
* @property bool $enabled
|
||||
* @property DateTime|null $deleted
|
||||
*
|
||||
* @property ExternalProductCatalog $external_product_catalog
|
||||
* @property ProductCatalog $product_catalog
|
||||
@@ -34,6 +35,8 @@ class ExternalProductCatalogsProductCatalog extends Entity
|
||||
'product_catalog_id' => true,
|
||||
'created' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
// entities
|
||||
'external_product_catalog' => true,
|
||||
'product_catalog' => true,
|
||||
];
|
||||
|
||||
@@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -12,6 +13,7 @@ use Cake\ORM\Entity;
|
||||
* @property string $name
|
||||
* @property string $product_category_id
|
||||
* @property \CakeProducts\Model\Enum\ProductProductTypeId $product_type_id
|
||||
* @property DateTime|null $deleted
|
||||
*
|
||||
* @property \CakeProducts\Model\Entity\ProductCategory $product_category
|
||||
* @property \CakeProducts\Model\Entity\ProductAttribute[] $product_attributes
|
||||
@@ -31,7 +33,9 @@ class Product extends Entity
|
||||
'name' => true,
|
||||
'product_category_id' => true,
|
||||
'product_type_id' => true,
|
||||
'product_category' => true,
|
||||
'deleted' => true,
|
||||
// entities
|
||||
'product_category' => false,
|
||||
'product_attributes' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -13,6 +14,7 @@ use Cake\ORM\Entity;
|
||||
* @property string $product_category_attribute_id
|
||||
* @property string|null $attribute_value
|
||||
* @property string|null $product_category_attribute_option_id
|
||||
* @property DateTime|null $deleted
|
||||
*
|
||||
* @property Product $product
|
||||
* @property ProductCategoryAttribute $product_category_attribute
|
||||
@@ -34,6 +36,8 @@ class ProductAttribute extends Entity
|
||||
'product_category_attribute_id' => true,
|
||||
'attribute_value' => true,
|
||||
'product_category_attribute_option_id' => true,
|
||||
'deleted' => true,
|
||||
// entities
|
||||
'product' => false,
|
||||
'product_category_attribute' => false,
|
||||
'product_category_attribute_option' => false,
|
||||
|
||||
@@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -12,6 +13,7 @@ use Cake\ORM\Entity;
|
||||
* @property string $name
|
||||
* @property string|null $catalog_description
|
||||
* @property bool $enabled
|
||||
* @property DateTime|null $deleted
|
||||
*
|
||||
* @property ProductCategory[] $product_categories
|
||||
* @property ExternalProductCatalog[] $external_product_catalogs
|
||||
@@ -31,6 +33,8 @@ class ProductCatalog extends Entity
|
||||
'name' => true,
|
||||
'catalog_description' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
// entities
|
||||
'product_categories' => true,
|
||||
'external_product_catalogs' => true,
|
||||
];
|
||||
|
||||
@@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -17,6 +18,7 @@ use Cake\ORM\Entity;
|
||||
* @property int $lft
|
||||
* @property int $rght
|
||||
* @property bool $enabled
|
||||
* @property DateTime|null $deleted
|
||||
*
|
||||
* @property \CakeProducts\Model\Entity\ProductCatalog $product_catalog
|
||||
* @property \CakeProducts\Model\Entity\ParentProductCategory $parent_product_category
|
||||
@@ -42,6 +44,8 @@ class ProductCategory extends Entity
|
||||
'lft' => true,
|
||||
'rght' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
// entities
|
||||
'product_catalog' => true,
|
||||
'parent_product_category' => true,
|
||||
'child_product_categories' => true,
|
||||
|
||||
@@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -13,6 +14,7 @@ use Cake\ORM\Entity;
|
||||
* @property string|null $product_category_id
|
||||
* @property int $attribute_type_id
|
||||
* @property bool $enabled
|
||||
* @property DateTime|null $deleted
|
||||
*
|
||||
* @property ProductCategory $product_category
|
||||
* @property ProductCategoryAttributeOption[] $product_category_attribute_options
|
||||
@@ -33,6 +35,8 @@ class ProductCategoryAttribute extends Entity
|
||||
'product_category_id' => true,
|
||||
'attribute_type_id' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
// entities
|
||||
'product_category' => true,
|
||||
'product_category_attribute_options' => true,
|
||||
];
|
||||
|
||||
@@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -13,6 +14,7 @@ use Cake\ORM\Entity;
|
||||
* @property string $attribute_value
|
||||
* @property string $attribute_label
|
||||
* @property bool $enabled
|
||||
* @property DateTime|null $deleted
|
||||
*
|
||||
* @property ProductCategoryAttribute $product_category_attribute
|
||||
*/
|
||||
@@ -32,6 +34,8 @@ class ProductCategoryAttributeOption extends Entity
|
||||
'attribute_value' => true,
|
||||
'attribute_label' => true,
|
||||
'enabled' => true,
|
||||
'deleted' => true,
|
||||
// entities
|
||||
'product_category_attribute' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user