Added checks in Product::deleteAction()
This commit is contained in:
@@ -312,8 +312,39 @@ class ProductController extends mfBaseController {
|
||||
$this->redirect("Product");
|
||||
}
|
||||
|
||||
// check if Product is unused
|
||||
// check if product is in use
|
||||
if(OrderProductModel::count(["product_id" => $product->id])) {
|
||||
$this->layout()->setFlash("Produkt kann nicht gelöscht werden, da es in Verwendung ist!", "error");
|
||||
$this->redirect("Product");
|
||||
}
|
||||
|
||||
if(ContractModel::count(["product_id" => $product->id])) {
|
||||
$this->layout()->setFlash("Produkt kann nicht gelöscht werden, da es in Verwendung ist!", "error");
|
||||
$this->redirect("Product");
|
||||
}
|
||||
|
||||
if(ContractqueueModel::count(["product_id" => $product->id])) {
|
||||
$this->layout()->setFlash("Produkt kann nicht gelöscht werden, da es in Verwendung ist!", "error");
|
||||
$this->redirect("Product");
|
||||
}
|
||||
|
||||
if(PreorderModel::count(["product_id" => $product->id]) || PreorderModel::count(["setup_product_id" => $product->id])) {
|
||||
$this->layout()->setFlash("Produkt kann nicht gelöscht werden, da es in Verwendung ist!", "error");
|
||||
$this->redirect("Product");
|
||||
}
|
||||
|
||||
// delete attributes
|
||||
foreach($product->attributes as $attrib) {
|
||||
$attrib->delete();
|
||||
}
|
||||
// delete networks
|
||||
foreach(ProductNetworkModel::search(['product_id' => $product->id]) as $pn) {
|
||||
$pn->delete();
|
||||
}
|
||||
|
||||
// delete product
|
||||
$product->delete();
|
||||
$this->layout()->setFlash("Produkt erfolgreich gelöscht", "success");
|
||||
$this->redirect("Product");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user