Products can now be cloned
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user