diff --git a/Layout/default/Product/Index.php b/Layout/default/Product/Index.php
index 13d778b79..25a0e0dbd 100644
--- a/Layout/default/Product/Index.php
+++ b/Layout/default/Product/Index.php
@@ -158,7 +158,7 @@
=$product->ivt_id?> |
$product->id])?>">
-
+ $product->id])?>">
$product->id])?>" class="text-danger" onclick="if(!confirm('Berechtigungen wirklich löschen?')) return false;" title="Produkt Löschen">
|
diff --git a/application/Product/Product.php b/application/Product/Product.php
index a37ec2c83..9d7e0580d 100644
--- a/application/Product/Product.php
+++ b/application/Product/Product.php
@@ -80,4 +80,27 @@ class Product extends mfBaseModel {
return $this->$name;
}
+
+
+ public function __clone() {
+ $me = new User;
+ $me->loadMe();
+
+ $old_id = $this->id;
+ $this->id = null;
+
+ $this->name .= " - Kopie";
+
+ // cleanup data
+ $this->create_by = $me->id;
+ $this->edit_by = $me->id;
+
+ $this->create = null;
+ $this->edit = null;
+ $this->saved = 0;
+ $this->mode = "new";
+ $this->_old_data = new StdClass();
+
+ $this->log->debug("Cloned Product $old_id");
+ }
}
\ No newline at end of file
diff --git a/application/Product/ProductController.php b/application/Product/ProductController.php
index e92adc7ea..731d17f62 100644
--- a/application/Product/ProductController.php
+++ b/application/Product/ProductController.php
@@ -108,6 +108,46 @@ class ProductController extends mfBaseController {
return $this->addAction();
}
+ protected function copyAction() {
+ if(!$this->me->is(["Admin"])) {
+ $this->redirect("Dashboard");
+ }
+
+ $id = $this->request->id;
+ if(!is_numeric($id) || $id < 1) {
+ $this->layout()->setFlash("Produkt nicht gefunden", "error");
+ $this->redirect("Product");
+ }
+
+ $product = new Product($id);
+ if(!$product->id) {
+ $this->layout()->setFlash("Produkt nicht gefunden", "error");
+ $this->redirect("Product");
+ }
+
+ $copy = clone($product);
+ if(!$copy->save()) {
+ $this->layout()->setFlash("Kopie konnte nicht gespeichert werden", "error");
+ $this->redirect("Product");
+ }
+
+ foreach($product->attributes as $attrib) {
+ $new_attrib = clone($attrib);
+ $new_attrib->product_id = $copy->id;
+ $new_attrib->save();
+ }
+
+ foreach(ProductNetworkModel::search(['product_id' => $product->id]) as $pn) {
+ $new_pn = clone($pn);
+ $new_pn->product_id = $copy->id;
+ $new_pn->save();
+ }
+
+ $this->layout()->setFlash("Kopie erfolgreich erstellt.", "success");
+ $this->redirect("Product", "edit", ["id" => $copy->id]);
+
+ }
+
protected function saveAction() {
if(!$this->me->is(["Admin"])) {
$this->redirect("Dashboard");
diff --git a/application/ProductAttribute/ProductAttribute.php b/application/ProductAttribute/ProductAttribute.php
index f9ce6a4a0..df62e1dcb 100644
--- a/application/ProductAttribute/ProductAttribute.php
+++ b/application/ProductAttribute/ProductAttribute.php
@@ -30,4 +30,28 @@ class ProductAttribute extends mfBaseModel {
return $this->$name;
}
+
+ public function __clone() {
+ $me = new User;
+ $me->loadMe();
+ //var_dump($this);exit;
+ $old_id = $this->id;
+ $this->id = null;
+
+ // cleanup data
+ unset($this->data->name);
+ unset($this->data->type);
+ unset($this->data->displayname);
+ unset($this->data->description);
+ $this->create_by = $me->id;
+ $this->edit_by = $me->id;
+
+ $this->create = null;
+ $this->edit = null;
+ $this->saved = 0;
+ $this->mode = "new";
+ $this->_old_data = new StdClass();
+
+ $this->log->debug("Cloned ProductAttribute $old_id");
+ }
}
\ No newline at end of file
diff --git a/application/ProductNetwork/ProductNetwork.php b/application/ProductNetwork/ProductNetwork.php
index ddb7194ba..f372f01e0 100644
--- a/application/ProductNetwork/ProductNetwork.php
+++ b/application/ProductNetwork/ProductNetwork.php
@@ -24,5 +24,25 @@ class ProductNetwork extends mfBaseModel {
return $this->$name;
}
+
+ public function __clone() {
+ $me = new User;
+ $me->loadMe();
+
+ $old_id = $this->id;
+ $this->id = null;
+
+ // cleanup data
+ $this->create_by = $me->id;
+ $this->edit_by = $me->id;
+
+ $this->create = null;
+ $this->edit = null;
+ $this->saved = 0;
+ $this->mode = "new";
+ $this->_old_data = new StdClass();
+
+ $this->log->debug("Cloned ProductNetwork $old_id");
+ }
}
\ No newline at end of file