api changes:
- GET /preorder/open - get all open preorders - added extref to preorder requests and responses, can be used to identify a specific preorder
This commit is contained in:
@@ -19,6 +19,7 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
protected function init() {
|
||||
$db = $this->db(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
$this->addRoute("/preorder/open", "getOpenPreorders", "GET");
|
||||
$this->addRoute("/preorder", "submitPreorder", "POST");
|
||||
$this->addRoute("/preorder/:code", "getPreorder", "GET");
|
||||
$this->addRoute("/preorder/:code", "cancelPreorder", "DELETE");
|
||||
@@ -79,20 +80,62 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
//var_dump($campaign, $this->allowed_origins);exit;
|
||||
}
|
||||
|
||||
protected function getOpenPreorders() {
|
||||
$ts = $this->get['ts'];
|
||||
|
||||
$update_ts = 0;
|
||||
|
||||
if($ts) {
|
||||
if(is_numeric($ts)) {
|
||||
$update_ts = $ts;
|
||||
} else {
|
||||
$update_date = new DateTime($ts);
|
||||
if($update_date) {
|
||||
$update_ts = $update_date->format('U');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// nicht auf cluster einschränken, sondern auf partner_id
|
||||
/*
|
||||
$preorder_search = [];
|
||||
if(count($this->filter_salescluster_ids)) {
|
||||
$preorder_search['netzgebiet_id'] = $this->filter_salescluster_ids;
|
||||
}*/
|
||||
|
||||
$preorder_search = [];
|
||||
$preorder_search['partner_id'] = $this->me->address_id;
|
||||
$preorder_search['add-where'] = "AND tt_preorder.`edit` > $update_ts";
|
||||
|
||||
$return = [];
|
||||
|
||||
foreach(PreorderModel::search($preorder_search) as $preorder) {
|
||||
$return[] = $preorder->getApiArray();
|
||||
}
|
||||
|
||||
return mfResponse::Ok(["preorders" => $return]);
|
||||
|
||||
}
|
||||
|
||||
protected function getPreorder($code) {
|
||||
$code = trim(strtoupper($code));
|
||||
$code = trim($code);
|
||||
if(!$code) {
|
||||
return mfResponse::NotFound(["message" => "Preorder not found"]);
|
||||
}
|
||||
|
||||
$preorder = PreorderModel::getFirst(['ucode' => $code]);
|
||||
$preorder = PreorderModel::getFirst(['ucode' => strtoupper($code), 'partner_id' => $this->me->address_id]);
|
||||
if(!$preorder) {
|
||||
// try oan id
|
||||
$preorder = PreorderModel::getFirst(['oaid' => $code]);
|
||||
if(!$preorder) {
|
||||
return mfResponse::NotFound(["message" => "Preorder not found"]);
|
||||
}
|
||||
$preorder = PreorderModel::getFirst(['oaid' => strtolower($code), 'partner_id' => $this->me->address_id]);
|
||||
}
|
||||
if(!$preorder) {
|
||||
// try as extref
|
||||
$preorder = PreorderModel::getFirst(['extref' => $code, 'partner_id' => $this->me->address_id]);
|
||||
}
|
||||
if(!$preorder) {
|
||||
return mfResponse::NotFound(["message" => "Preorder not found"]);
|
||||
}
|
||||
|
||||
|
||||
if($preorder->partner_id != $this->me->address_id) {
|
||||
return mfResponse::NotFound(["message" => "Preorder not found"]);
|
||||
@@ -103,12 +146,12 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
return mfResponse::NotFound(["message" => "Preorder not found"]);
|
||||
}
|
||||
|
||||
|
||||
return mfResponse::Ok($return);
|
||||
|
||||
}
|
||||
|
||||
protected function cancelPreorder($code) {
|
||||
/*
|
||||
$code = trim(strtoupper($code));
|
||||
if(!$code) {
|
||||
return mfResponse::NotFound(["message" => "Preorder not found"]);
|
||||
@@ -121,6 +164,24 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
if(!$preorder) {
|
||||
return mfResponse::NotFound(["message" => "Preorder not found or cancelled already"]);
|
||||
}
|
||||
}*/
|
||||
|
||||
$code = trim($code);
|
||||
if(!$code) {
|
||||
return mfResponse::NotFound(["message" => "Preorder not found"]);
|
||||
}
|
||||
|
||||
$preorder = PreorderModel::getFirst(['ucode' => strtoupper($code), 'partner_id' => $this->me->address_id, 'deleted' => 0, '<status_code' => 800]);
|
||||
if(!$preorder) {
|
||||
// try oan id
|
||||
$preorder = PreorderModel::getFirst(['oaid' => strtolower($code), 'partner_id' => $this->me->address_id, 'deleted' => 0, '<status_code' => 800]);
|
||||
}
|
||||
if(!$preorder) {
|
||||
// try as extref
|
||||
$preorder = PreorderModel::getFirst(['extref' => $code, 'partner_id' => $this->me->address_id, 'deleted' => 0, '<status_code' => 800]);
|
||||
}
|
||||
if(!$preorder) {
|
||||
return mfResponse::NotFound(["message" => "Preorder not found"]);
|
||||
}
|
||||
|
||||
// check if user owns preorder
|
||||
@@ -412,8 +473,9 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
} else {
|
||||
$preorder_data['is_additional_order'] = 0;
|
||||
}
|
||||
$preorder_data['technology'] = ($this->post['technology']) ? $this->post['technology'] : null;
|
||||
$preorder_data['patchposition'] = ($this->post['patchposition']) ? $this->post['patchposition'] : null;
|
||||
$preorder_data['extref'] = (trim($this->post['extref'])) ? trim($this->post['extref']) : null;
|
||||
$preorder_data['technology'] = (trim($this->post['technology'])) ? trim($this->post['technology']) : null;
|
||||
$preorder_data['patchposition'] = (trim($this->post['patchposition'])) ? trim($this->post['patchposition']) : null;
|
||||
|
||||
/*
|
||||
* setup price
|
||||
@@ -458,7 +520,7 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
*/
|
||||
foreach(['company','uid','firstname','lastname','street','housenumber','zip','city','phone','email','block','stiege','stock','tuer', 'unit_string'] as $key) {
|
||||
if(property_exists($customer, $key)) {
|
||||
$preorder_data[$key] = ($customer->$key) ? $customer->$key : null;
|
||||
$preorder_data[$key] = (trim($customer->$key)) ? trim($customer->$key) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -611,12 +673,20 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
|
||||
$return = ["code" => $preorder->ucode];
|
||||
if($preorder->oaid) {
|
||||
$return ['oaid'] = $preorder->oaid;
|
||||
$return['oaid'] = $preorder->oaid;
|
||||
}
|
||||
if($preorder->extref) {
|
||||
$return['extref'] = $preorder->extref;
|
||||
}
|
||||
if($addon_data) {
|
||||
$return["additionalData"] = $addon_data;
|
||||
}
|
||||
|
||||
$return['created'] = date("c", $preorder->create);
|
||||
$return['created_ts'] = (int)$preorder->create;
|
||||
$return['updated'] = date("c", $preorder->edit);
|
||||
$return['updated_ts'] = (int)$preorder->edit;
|
||||
|
||||
return mfResponse::Ok($return);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ class Preorder extends mfBaseModel {
|
||||
$a = [];
|
||||
$a['code'] = strtoupper($this->ucode);
|
||||
$a['oaid'] = $this->oaid;
|
||||
$a['extref'] = $this->extref;
|
||||
$a['status'] = $this->getProperty("status")->getApiArray();
|
||||
$a['connectionType'] = $this->connection_type;
|
||||
$a['connectionCount'] = ($this->connection_count) ? (int)$this->connection_count : 1;
|
||||
@@ -119,6 +120,11 @@ class Preorder extends mfBaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
$a['created'] = date("c", $this->create);
|
||||
$a['created_ts'] = (int)$this->create;
|
||||
$a['updated'] = date("c", $this->edit);
|
||||
$a['updated_ts'] = (int)$this->edit;
|
||||
|
||||
return $a;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ class PreorderModel {
|
||||
public $adb_hausnummer_id;
|
||||
public $adb_wohneinheit_id;
|
||||
public $oaid;
|
||||
public $extref;
|
||||
public $address_district;
|
||||
public $address_info;
|
||||
public $building_id;
|
||||
@@ -413,6 +414,13 @@ class PreorderModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("extref", $filter)) {
|
||||
$extref = FronkDB::singleton()->escape($filter['extref']);
|
||||
if($extref) {
|
||||
$where .= " AND tt_preorder.extref = '$extref'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("gemeinde", $filter)) {
|
||||
$gemeinde = FronkDB::singleton()->escape($filter['gemeinde']);
|
||||
if($gemeinde) {
|
||||
|
||||
Reference in New Issue
Block a user