Products can now be cloned
This commit is contained in:
@@ -158,7 +158,7 @@
|
|||||||
<td><?=$product->ivt_id?></td>
|
<td><?=$product->ivt_id?></td>
|
||||||
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
|
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
|
||||||
<a href="<?=self::getUrl("Product", "edit", ["id" => $product->id])?>"><i class="far fa-edit" title="Produkt Bearbeiten"></i></a>
|
<a href="<?=self::getUrl("Product", "edit", ["id" => $product->id])?>"><i class="far fa-edit" title="Produkt Bearbeiten"></i></a>
|
||||||
<!--a href="<?=self::getUrl("Product", "copy", ["id" => $product->id])?>"><i class="far fa-clone" title="Kopie erstellen"></i></a-->
|
<a href="<?=self::getUrl("Product", "copy", ["id" => $product->id])?>"><i class="far fa-clone" title="Kopie erstellen"></i></a>
|
||||||
<a href="<?=self::getUrl("Product", "delete", ["id" => $product->id])?>" class="text-danger" onclick="if(!confirm('Berechtigungen wirklich löschen?')) return false;" title="Produkt Löschen"><i class="fas fa-trash"></i></a>
|
<a href="<?=self::getUrl("Product", "delete", ["id" => $product->id])?>" class="text-danger" onclick="if(!confirm('Berechtigungen wirklich löschen?')) return false;" title="Produkt Löschen"><i class="fas fa-trash"></i></a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -80,4 +80,27 @@ class Product extends mfBaseModel {
|
|||||||
|
|
||||||
return $this->$name;
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -108,6 +108,46 @@ class ProductController extends mfBaseController {
|
|||||||
return $this->addAction();
|
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() {
|
protected function saveAction() {
|
||||||
if(!$this->me->is(["Admin"])) {
|
if(!$this->me->is(["Admin"])) {
|
||||||
$this->redirect("Dashboard");
|
$this->redirect("Dashboard");
|
||||||
|
|||||||
@@ -30,4 +30,28 @@ class ProductAttribute extends mfBaseModel {
|
|||||||
|
|
||||||
return $this->$name;
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -24,5 +24,25 @@ class ProductNetwork extends mfBaseModel {
|
|||||||
|
|
||||||
return $this->$name;
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user