From d06f0cedc38414ba5c70e4819af04e7d57bc1317 Mon Sep 17 00:00:00 2001 From: Jeppe Bundgaard Date: Tue, 28 Oct 2025 09:58:29 +0100 Subject: [PATCH] Add new properties and routes for product and booking enhancements - Added `virtual_cart` property in `bookings_o` and enhanced its structure method. - Introduced `display_in_booking_form` and `order_priority` properties in `products_o` with updates to object structure, parsing, and routes. - Enabled handling of product attributes `display_in_booking_form` and `order_priority` in `productsRoute`. - Added `booked_invoice_id` reset logic in `collected_order_invoices_o`. - Introduced `machineButtonPressRoute` to log button press incidents and send Slack notifications. --- services/nginx/app/objects/bookings_o.php | 2 + .../objects/collected_order_invoices_o.php | 1 + services/nginx/app/objects/products_o.php | 14 ++++++ .../app/routes/machineButtonPressRoute.php | 44 +++++++++++++++++++ services/nginx/app/routes/productsRoute.php | 8 ++++ 5 files changed, 69 insertions(+) create mode 100644 services/nginx/app/routes/machineButtonPressRoute.php diff --git a/services/nginx/app/objects/bookings_o.php b/services/nginx/app/objects/bookings_o.php index 0db2be1b..49a680b2 100644 --- a/services/nginx/app/objects/bookings_o.php +++ b/services/nginx/app/objects/bookings_o.php @@ -35,6 +35,7 @@ class bookings_o extends db public object_property $wash_certificate_pdf; public object_property $status; public object_property $data; + public object_property $virtual_cart; public function structure(): void { @@ -106,6 +107,7 @@ class bookings_o extends db $this->wash_certificate_pdf = new object_property($this->table, $this->id, 'wash_certificate_pdf', 'string', true); $this->status = new object_property($this->table, $this->id, 'status', 'string', true); $this->data = new object_property($this->table, $this->id, 'data', 'string', true); + $this->virtual_cart = new object_property($this->table, $this->id, 'virtual_cart', 'int', false); } public function parseBookings(array $listObjectsWithPaginationIfSet): array diff --git a/services/nginx/app/objects/collected_order_invoices_o.php b/services/nginx/app/objects/collected_order_invoices_o.php index cb23a034..e140bae0 100644 --- a/services/nginx/app/objects/collected_order_invoices_o.php +++ b/services/nginx/app/objects/collected_order_invoices_o.php @@ -1277,6 +1277,7 @@ class collected_order_invoices_o extends db // Clear the external_id and processor fields $this->external_id->set(null); $this->processor->set(null); + $this->booked_invoice_id->set(null); // Object changed self::objectChanged(); } diff --git a/services/nginx/app/objects/products_o.php b/services/nginx/app/objects/products_o.php index fb9eb464..23ca56a3 100644 --- a/services/nginx/app/objects/products_o.php +++ b/services/nginx/app/objects/products_o.php @@ -60,6 +60,16 @@ class products_o extends db * @var object_property $is_wash */ public object_property $is_wash; + /** + * Should the item be displayed in the booking form? + * @var object_property $display_in_booking_form + */ + public object_property $display_in_booking_form; + /** + * Order priority integer (lower = higher priority) + * @var object_property $order_priority + */ + public object_property $order_priority; /** * The timestamp of when the object was created * @var object_property @@ -106,6 +116,8 @@ class products_o extends db $this->apply_category_discount = new object_property($this->table, $this->id, 'apply_category_discount', 'bool', false); $this->requires_note = new object_property($this->table, $this->id, 'requires_note', 'bool', false); $this->is_wash = new object_property($this->table, $this->id, 'is_wash', 'bool', false); + $this->display_in_booking_form = new object_property($this->table, $this->id, 'display_in_booking_form', 'bool', false); + $this->order_priority = new object_property($this->table, $this->id, 'order_priority', 'int', false); $this->created_at = new object_property($this->table, $this->id, 'created_at', 'string', false); $this->updated_at = new object_property($this->table, $this->id, 'updated_at', 'string', false); } @@ -196,6 +208,8 @@ class products_o extends db 'apply_category_discount' => (bool)$this->apply_category_discount->value(), 'requires_note' => (bool)$this->requires_note->value(), 'is_wash' => (bool)$this->is_wash->value(), + 'display_in_booking_form' => (bool)$this->display_in_booking_form->value(), + 'order_priority' => (int)$this->order_priority->value(), 'created_at' => (string)$this->created_at->value(), 'updated_at' => (string)$this->updated_at->value(), ]; diff --git a/services/nginx/app/routes/machineButtonPressRoute.php b/services/nginx/app/routes/machineButtonPressRoute.php new file mode 100644 index 00000000..b49bc9bd --- /dev/null +++ b/services/nginx/app/routes/machineButtonPressRoute.php @@ -0,0 +1,44 @@ +get_plate_scanner(); + self::requireParameters(['token']); + // Validate the token + self::requireType('token', 'string'); + self::requireMinLength('token', 1); + self::requireMaxLength('token', 100); + // TODO: Implement action + $slack = new slack(); + $slack->send_department_booking_notification((int)$plate_scanner->department_id->value(), 'Button was pressed on the machine with the plate scanner: ' . $plate_scanner->id); + // Log the incident + (new logs_o())->add('relay', $plate_scanner->department_id->value(), 1, 0, 'TRIGGER_BUTTON_PRESS', 'Button was pressed on the machine with the plate scanner: ' . $plate_scanner->id); + // Return a success message + $response->success(['message' => 'Button press recorded.', 'scanner' => $plate_scanner->name->value()], 201); + }, [ + 'add_button_press' => 'Add a button press' + ]); + } +} \ No newline at end of file diff --git a/services/nginx/app/routes/productsRoute.php b/services/nginx/app/routes/productsRoute.php index 18914ca0..ca596d8b 100644 --- a/services/nginx/app/routes/productsRoute.php +++ b/services/nginx/app/routes/productsRoute.php @@ -132,6 +132,8 @@ class productsRoute 'updated_at' => (string)$product['updated_at'], 'addons' => (new product_options_o())->getProductOptions($product['id']), 'is_wash' => (bool)$product['is_wash'], + 'display_in_booking_form' => (bool)$product['display_in_booking_form'], + 'order_priority' => (int)$product['order_priority'], ]; } @@ -342,6 +344,12 @@ class productsRoute if (self::isParametersSet(['is_wash'])) { $product->is_wash->set($response->getRequestParameter('is_wash') ? 1 : 0); } + if (self::isParametersSet(['display_in_booking_form'])) { + $product->display_in_booking_form->set($response->getRequestParameter('display_in_booking_form') ? 1 : 0); + } + if (self::isParametersSet(['order_priority'])) { + $product->order_priority->set((int)$response->getRequestParameter('order_priority') ?? ''); + } (new logs_o())->add('products', 'global', 1, $user->id, 'EDIT_PRODUCT', 'Product id: ' . $id); // Return a success message $response->success(['message' => 'Product edited successfully']);