Added product active flag, saving filter in Product/Index

This commit is contained in:
Frank Schubert
2023-02-27 19:02:23 +01:00
parent 388e8ea164
commit 4be8e91508
7 changed files with 86 additions and 15 deletions

View File

@@ -366,7 +366,7 @@ class OrderController extends mfBaseController {
$this->layout()->setTemplate("Order/Form");
if($this->me->is("Admin")) {
//$this->layout()->set("addresses", AddressModel::search(['parents_only' => 1]));
$this->layout()->set("products", ProductModel::getAll());
$this->layout()->set("products", ProductModel::getActive());
$this->layout()->set("terminations", TerminationModel::getAll());
} else {
// get all salespartner addresses of my networks
@@ -396,6 +396,7 @@ class OrderController extends mfBaseController {
// get products assigned to my networks
$products = [];
foreach(ProductNetworkModel::search(["network_id" => $network_ids]) as $pn) {
if(!$pn->product->active) continue;
if(!array_key_exists($pn->product_id, $products))
$products[$pn->product_id] = $pn->product;
}

View File

@@ -155,6 +155,7 @@ class PreorderController extends mfBaseController {
$products = [];
foreach(ProductNetworkModel::search(["network_id" => $campaign->network_id]) as $pn) {
if(!$pn->product->active) continue;
if(!array_key_exists($pn->product_id, $products)) {
if(is_array($pn->product->attributes) && !array_key_exists("presales", $pn->product->attributes)) {
$products[$pn->product_id] = $pn->product;

View File

@@ -54,9 +54,9 @@ class Preordercampaign extends mfBaseModel {
$activation_products = [];
$reorder_products = [];
$provisions = ProductModel::search(["attributename" => "presales", "attributevalue" => "provision"]);
$activations = ProductModel::search(["attributename" => "presales", "attributevalue" => "activation"]);
$reorders = ProductModel::search(["attributename" => "presales", "attributevalue" => "reorder"]);
$provisions = ProductModel::search(["active" => 1, "attributename" => "presales", "attributevalue" => "provision"]);
$activations = ProductModel::search(["active" => 1, "attributename" => "presales", "attributevalue" => "activation"]);
$reorders = ProductModel::search(["active" => 1, "attributename" => "presales", "attributevalue" => "reorder"]);
foreach($provisions as $p) {
if(ProductNetworkModel::search(['product_id' => $p->id, "network_id" => $this->network_id])) {

View File

@@ -19,16 +19,23 @@ class ProductController extends mfBaseController {
$this->redirect("Dashboard");
}
if($this->request->resetFilter) {
unset($_SESSION[MFAPPNAME.'-Product-filter']);
}
$filter = [];
if(is_array($this->request->filter)) {
$filter = $this->request->filter;
$_SESSION[MFAPPNAME.'-Product-filter'] = $filter;
} else {
if(array_key_exists(MFAPPNAME.'-Product-filter', $_SESSION) && count($_SESSION[MFAPPNAME.'-Product-filter'])) {
$filter = $_SESSION[MFAPPNAME.'-Product-filter'];
}
}
$this->layout->set("filter", $filter);
$filter = $this->getPreparedFilter($filter);
if($filter) {
$filter = $this->getPreparedFilter($filter);
}
// pagination defaults
$pagination = [];
@@ -55,6 +62,15 @@ class ProductController extends mfBaseController {
unset($filter['name']);
}
if(array_key_exists("active", $filter)) {
if($filter['active'] != "all") {
$new_filter['active'] = $filter['active'];
}
unset($filter['active']);
} else {
$new_filter['active'] = 1;
}
foreach($filter as $name => $value) {
$new_filter[$name] = $value;
}
@@ -128,7 +144,11 @@ class ProductController extends mfBaseController {
}
$data['external_id'] = $r->external_id;
}
//var_dump($data);exit;
$data['active'] = 1;
if(!$r->active) {
$data['active'] = 0;
}
$data['price_nne'] = ($r->price_nne) ? Layout::commaToDot($r->price_nne) : 0;
$data['price_nbe'] = ($r->price_nbe) ? Layout::commaToDot($r->price_nbe) : 0;
@@ -229,7 +249,12 @@ class ProductController extends mfBaseController {
}
$this->layout()->setFlash("Produkt erfolgreich gespeichert.", "success");
$this->redirect("Product", "Edit", ['id' => $new_id]);
if($r->return == "index") {
$this->redirect("Product");
} else {
$this->redirect("Product", "Edit", ['id' => $new_id]);
}
}
protected function deleteAction() {
@@ -310,14 +335,14 @@ class ProductController extends mfBaseController {
$products = [];
if(is_numeric($search)) {
$pnumbers = ProductModel::search(["id" => $search]);
$pnumbers = ProductModel::search(["active" => 1, "id" => $search]);
if($pnumbers) {
$products = array_merge($products, $pnumbers);
}
}
$products = array_merge($products, ProductModel::search(["name%" => $search]));
$products = array_merge($products, ProductModel::search(["active" => 1, "name%" => $search]));
if(!is_array($products) && !count($products)) {
return false;

View File

@@ -75,6 +75,21 @@ class ProductModel {
}
public static function getActive() {
$items = [];
$db = FronkDB::singleton();
$res = $db->select("Product", "*", "active = 1 ORDER BY name,producttech_id");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new Product($data);
}
}
return $items;
}
public static function getFirst() {
$db = FronkDB::singleton();
@@ -162,6 +177,15 @@ class ProductModel {
}
}
if(array_key_exists("active", $filter)) {
$active = $filter['active'];
if($active) {
$where .= " AND Product.`active` = 1";
} else {
$where .= " AND Product.`active` = 0";
}
}
if(array_key_exists("productgroup_id", $filter)) {
$productgroup_id = $filter['productgroup_id'];
if(is_numeric($productgroup_id)) {