Added Preorder attributes and checkboxes in list

This commit is contained in:
Frank Schubert
2023-03-08 14:49:47 +01:00
parent 835d9b1b58
commit 9d02064aa2
5 changed files with 142 additions and 5 deletions
@@ -126,6 +126,9 @@ class PreorderController extends mfBaseController {
}
}
if(array_key_exists("attributes", $filter) && count($filter['attributes'])) {
}
if(is_array($filter) && count($filter)) {
foreach($filter as $name => $value) {
@@ -586,4 +589,60 @@ class PreorderController extends mfBaseController {
}
protected function apiAction() {
if(!$this->me->is(["Admin","netowner","salespartner"])) {
$this->redirect("Dashboard");
}
$do = $this->request->do;
$data = [];
switch($do) {
case "saveAttribute":
$return = $this->saveAttributeApi();
break;
default:
$return = false;
}
if(!is_array($return) || !count($return)) {
$data = ["status" => "error"];
$this->returnJson($data);
}
$data['status'] = "OK";
$data['result'] = $return;
$this->returnJson($data);
}
private function saveAttributeApi() {
$preorder_id = $this->request->id;
if(!is_numeric($preorder_id) || $preorder_id < 1) {
return false;
}
$preorder = new Preorder($preorder_id);
if(!$preorder->id) {
return false;
}
$attribute = $this->request->attribute;
if(!$attribute) {
return false;
}
$value = $this->request->value;
$attribs = $preorder->attribute;
if(!$attribs) {
$attribs = [];
}
$attribs[$attribute] = $value ? 1 : 0;
$preorder->attributes = json_encode($attribs);
if($preorder->save()) {
return ["id" => $preorder_id, "attribute" => $attribute];
} else {
$this->returnJson(["status" => "error", "result" => ["id" => $preorder_id, "attribute" => $attribute]]);
}
}
}